Class OrderToken


  • public class OrderToken
    extends java.lang.Object
    A class representing a token of an Eressea order.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int TT_CLOSING_QUOTE
      A token that is a quote which matches an opening quote
      static int TT_COMMENT
      A comment (starting with ; or //)
      static int TT_EOC
      End-of-order token type
      static int TT_EXCLAM
      A token making the order persistent
      static int TT_ID
      An ID of a unit, building etc.
      static int TT_KEYWORD
      Well known keyword token type
      static int TT_NUMBER
      A number specifying some amount in contrast to an ID
      static int TT_OPENING_QUOTE
      A token that is a quote which starts a string
      static int TT_PERSIST
      A token making the order persistent
      static int TT_STRING
      A quoted or non-quoted string
      static int TT_UNDEF
      Undefined token type
      int ttype
      the type of the token
    • Constructor Summary

      Constructors 
      Constructor Description
      OrderToken​(int type)
      Creates a new OrderToken object with empty string and specified type
      OrderToken​(java.lang.String text)
      Creates a new OrderToken object representing the specified string, but with invalid start and end positions and undefined type.
      OrderToken​(java.lang.String text, int start, int end)
      Creates a new OrderToken object representing the specified string and the specified start and end positions.
      OrderToken​(java.lang.String text, int start, int end, int ttype, boolean followedBySpace)
      Creates a new OrderToken object representing the specified string with specific start and end positions and type.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean equals​(OrderToken token)
      boolean equalsAll​(OrderToken token)
      Deep equals.
      boolean equalsCompletedToken​(java.lang.String strKeyword)
      As equalsToken(String), but also accepts prefixes if followedBySpace is false.
      boolean equalsLocalToken​(java.lang.String strKeyword)
      Deprecated.
      use proper unit locale
      boolean equalsToken​(java.lang.String strKeyword)
      Compares the token and the specified keyword with respect to abbreviations as used by the eressea game server.
      boolean equivalentText​(OrderToken token)  
      boolean followedBySpace()
      Should return true if the token is followed by a whitespace character
      int getEnd()
      Returns the position of the first character after the token text in the order (i.e., getEnd()-getStart() is the length of the token).
      int getStart()
      Returns the position of the first character of the token text in the order.
      java.lang.String getStrippedText​(char[] delimiters)
      Same as getText() but removes enclosing quotes.
      java.lang.String getText()
      Returns the text.
      int hashCode()  
      void setStart​(int start)
      Deprecated.
      better make this immutable...
      java.lang.String toString()
      Returns a string representation of this order token.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • TT_KEYWORD

        public static final int TT_KEYWORD
        Well known keyword token type
        See Also:
        Constant Field Values
      • TT_STRING

        public static final int TT_STRING
        A quoted or non-quoted string
        See Also:
        Constant Field Values
      • TT_NUMBER

        public static final int TT_NUMBER
        A number specifying some amount in contrast to an ID
        See Also:
        Constant Field Values
      • TT_COMMENT

        public static final int TT_COMMENT
        A comment (starting with ; or //)
        See Also:
        Constant Field Values
      • TT_PERSIST

        public static final int TT_PERSIST
        A token making the order persistent
        See Also:
        Constant Field Values
      • TT_OPENING_QUOTE

        public static final int TT_OPENING_QUOTE
        A token that is a quote which starts a string
        See Also:
        Constant Field Values
      • TT_CLOSING_QUOTE

        public static final int TT_CLOSING_QUOTE
        A token that is a quote which matches an opening quote
        See Also:
        Constant Field Values
      • TT_EXCLAM

        public static final int TT_EXCLAM
        A token making the order persistent
        See Also:
        Constant Field Values
      • ttype

        public int ttype
        the type of the token
    • Constructor Detail

      • OrderToken

        public OrderToken​(java.lang.String text)
        Creates a new OrderToken object representing the specified string, but with invalid start and end positions and undefined type.
        Parameters:
        text - the text this order token represents.
      • OrderToken

        public OrderToken​(java.lang.String text,
                          int start,
                          int end)
        Creates a new OrderToken object representing the specified string and the specified start and end positions.
        Parameters:
        text - the text this order token represents.
        start - the start position of the token in the underlying stream.
        end - the end position of the token in the underlying stream.
      • OrderToken

        public OrderToken​(int type)
        Creates a new OrderToken object with empty string and specified type
      • OrderToken

        public OrderToken​(java.lang.String text,
                          int start,
                          int end,
                          int ttype,
                          boolean followedBySpace)
        Creates a new OrderToken object representing the specified string with specific start and end positions and type.
        Parameters:
        text - the text this order token represents.
        start - the start position of the token in the underlying stream.
        end - the end position of the token in the underlying stream.
        ttype - the type of the token, the value must equal one the TT_XXX constants.
        followedBySpace - defines whether the token was followed by either '\r' '\n' '\t' or ' '
    • Method Detail

      • followedBySpace

        public boolean followedBySpace()
        Should return true if the token is followed by a whitespace character
      • getText

        public java.lang.String getText()
        Returns the text.
      • getStrippedText

        public java.lang.String getStrippedText​(char[] delimiters)
        Same as getText() but removes enclosing quotes.
      • getStart

        public int getStart()
        Returns the position of the first character of the token text in the order.
      • setStart

        @Deprecated
        public void setStart​(int start)
        Deprecated.
        better make this immutable...
        Sets the position of the start of the token text in the order.
      • getEnd

        public int getEnd()
        Returns the position of the first character after the token text in the order (i.e., getEnd()-getStart() is the length of the token).
      • toString

        public java.lang.String toString()
        Returns a string representation of this order token.
        Overrides:
        toString in class java.lang.Object
      • equalsLocalToken

        @Deprecated
        public boolean equalsLocalToken​(java.lang.String strKeyword)
        Deprecated.
        use proper unit locale
        Compares the token and the translation of the specified keyword with respect to abbreviations as used by the eressea game server.
      • equalsCompletedToken

        public boolean equalsCompletedToken​(java.lang.String strKeyword)
        As equalsToken(String), but also accepts prefixes if followedBySpace is false.
        Returns:
        true if strKeyword is equal (disregarding case and umlauts) to this token
      • equalsToken

        public boolean equalsToken​(java.lang.String strKeyword)
        Compares the token and the specified keyword with respect to abbreviations as used by the eressea game server. Prefixes are accepted if followedBySpace() is true.
        Returns:
        true if strKeyword is equal (disregarding case and umlauts) to this token or if followedBySpace is true and strKeyWord starts with this token.
      • equals

        @Deprecated
        public boolean equals​(OrderToken token)
        Returns true if this is a prefix of token or vice versa. Attention This method does not override Object.equals(Object)!
      • equivalentText

        public boolean equivalentText​(OrderToken token)
        Returns:
        equalsToken(token.text) || token.equalsToken(text)
      • equalsAll

        public boolean equalsAll​(OrderToken token)
        Deep equals.
        Returns:
        true if the token has identical text, start, end, type and followedBySpace.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object