org.argouml.util
Class CustomSeparator

java.lang.Object
  extended byorg.argouml.util.CustomSeparator
Direct Known Subclasses:
ExprSeparatorWithStrings, QuotedStringSeparator

public class CustomSeparator
extends java.lang.Object

Base class for custom separators.

It can be instantiated directly, and then works like a separator in the delimiter string. For that purpose you should use the delimiter string in MyTokenizer, unless your token is wider than 32 characters.

You can also subclass this class to provide for more intricate recogition of the tokens. It is known that this class has been subclassed to recognize quoted strings, and balanced parentheses.

You should have this mental image of the tokenizing process:

  • Reset is called.
  • For each character, c, in the sequence being tokenized:
  • hasFreePart is checked to see if something follows. If true:
  • tokenLength is checked to see how far back in the sequence the token begun. If there are characters before that but after the last token, then they are made a token and this token is saved and returned next.

    Since:
    0.11.2
    See Also:
    MyTokenizer

    Field Summary
    private  char[] match
               
    private  char[] pattern
               
     
    Constructor Summary
    protected CustomSeparator()
              This constructor is only availible to subclasses of this class.
      CustomSeparator(char start)
              This constructor creates a new custom separator that matches the character start.
      CustomSeparator(java.lang.String start)
              This constructor creates a new custom separator that matches the string start.
     
    Method Summary
     boolean addChar(char c)
              Called to allow you to decide if you want to capure control of the matching process.
     boolean endChar(char c)
              Called to check if more characters are expected in the free part of the token.
     boolean hasFreePart()
              Called to check if more characters are expected to follow after addChar has returned true.
     void reset()
              Called to reset the separator before staring to look for a new token.
     int tokenLength()
              Returns the length of the matched token.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    pattern

    private char[] pattern

    match

    private char[] match
    Constructor Detail

    CustomSeparator

    protected CustomSeparator()
    This constructor is only availible to subclasses of this class. If you use it you should also override addChar to recognize when your separator should that control. If you don't, then you may block all other separators.


    CustomSeparator

    public CustomSeparator(char start)
    This constructor creates a new custom separator that matches the character start. Unless you override addChar, the default behaviour is to return false in addChar until start is encountered and then hasFreePart returns false.

    Parameters:
    start - The start character.

    CustomSeparator

    public CustomSeparator(java.lang.String start)
    This constructor creates a new custom separator that matches the string start. Unless you override addChar, the default behaviour is to return false in addChar until start is encountered and then hasFreePart returns false.

    Parameters:
    start - The start String.
    Method Detail

    reset

    public void reset()
    Called to reset the separator before staring to look for a new token.


    tokenLength

    public int tokenLength()
    Returns the length of the matched token. It is not required to be meaningful unless addChar has returned true and hasFreePart returned false or endChar returned true.

    Returns:
    The length of the matched token.

    addChar

    public boolean addChar(char c)
    Called to allow you to decide if you want to capure control of the matching process. If you return true, then hasFreePart will be checked to see if you expect more things to follow.

    The default behaviour is to return false until the character or String given as parameter to the constructor has been matched.

    Parameters:
    c - The next character in the sequence being tokenized.
    Returns:
    true to gain control of the matching, false to continue matching.

    hasFreePart

    public boolean hasFreePart()
    Called to check if more characters are expected to follow after addChar has returned true. If true, then any following characters will be fed to endChar until endChar returns true.

    The default behaviour is to return false.

    Returns:
    true to continue feeding characters to endChar or false.

    endChar

    public boolean endChar(char c)
    Called to check if more characters are expected in the free part of the token.

    Parameters:
    c - The next character in the sequence being tokenized.
    Returns:
    true to indicate that the token is complete, or false to continue feeding characters through endChar.


    ArgoUML © 1996-2004 (20040316)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook