com.h3c.util

## Class SymbolTokenizer

- java.lang.Object
- - com.h3c.util.SymbolTokenizer

- All Implemented Interfaces:
    Iterator<String>

      public class SymbolTokenizer
      extends Object
      implements Iterator<String>

  Utility for tokenizing a string along symbol boundaries. The symbols themselves are returned as part of the token sequence and only white-space is eliminated.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SymbolTokenizer(String[] symbols, String[] preDelimiters, String[] postDelimiters)` Create a new symbol tokenizer using the specified symbols and any valid delimiters.
    `SymbolTokenizer(String string, String[] symbols, String[] preDelimiters, String[] postDelimiters)` Create a new symbol tokenizer using the specified symbols and any valid delimiters and ready to tokenize the given string.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `hasNext()` Determines whether there are more tokens, symbols or otherwise, remaining to be parsed in the string.
    `String` | `next()` Get the next token, symbol or otherwise.
    `int` | `position()` Get the current parse position.
    `void` | `remove()`
    `void` | `reset()` Resets the tokenizer to the parse from the beginning of the current string.
    `void` | `setString(String string)` Apply a new string to be parsed by this tokenizer and reset the tokenizer.
    `String` | `string()` Get the string being parsed.
    `boolean` | `wasSymbol()` Indicates whether the last token returned via next() was a special symbol or not.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SymbolTokenizer

          public SymbolTokenizer(String[] symbols,
                         String[] preDelimiters,
                         String[] postDelimiters)

      Create a new symbol tokenizer using the specified symbols and any valid delimiters.
      Parameters:
        `symbols` - array of recognized symbol strings
        `preDelimiters` - string of characters that may precede each respective symbol; elements may be null if symbol has no special constraint
        `postDelimiters` - string of characters that may follow each respective symbol; elements may be null if symbol has no special constraint

    - #### SymbolTokenizer

          public SymbolTokenizer(String string,
                         String[] symbols,
                         String[] preDelimiters,
                         String[] postDelimiters)

      Create a new symbol tokenizer using the specified symbols and any valid delimiters and ready to tokenize the given string.
      Parameters:
        `string` - string to be parsed
        `symbols` - array of recognized symbol strings
        `preDelimiters` - string of characters that may precede each respective symbol; elements may be null if symbol has no special constraint
        `postDelimiters` - string of characters that may follow each respective symbol; elements may be null if symbol has no special constraint

  - ### Method Detail

    - #### string

          public String string()

      Get the string being parsed.
      Returns:
        string being parsed by this tokenizer

    - #### setString

          public void setString(String string)

      Apply a new string to be parsed by this tokenizer and reset the tokenizer.
      Parameters:
        `string` - string to be parsed

    - #### position

          public int position()

      Get the current parse position.
      Returns:
        position within the string where the tokenizer will start parsing next

    - #### reset

          public void reset()

      Resets the tokenizer to the parse from the beginning of the current string.

    - #### hasNext

          public boolean hasNext()

      Determines whether there are more tokens, symbols or otherwise, remaining to be parsed in the string.
      Specified by:
        `hasNext` in interface `Iterator<String>`
      Returns:
        true if there are more tokens, false otherwise

    - #### next

          public String next()

      Get the next token, symbol or otherwise.
      Specified by:
        `next` in interface `Iterator<String>`
      Returns:
        next token; null if already at the end of the string

    - #### wasSymbol

          public boolean wasSymbol()

      Indicates whether the last token returned via next() was a special symbol or not.
      Returns:
        true if the token was a symbol; false otherwise

    - #### remove

          public void remove()

      Specified by:
        `remove` in interface `Iterator<String>`

Copyright © 2014. All Rights Reserved.