Class Dictionary

  • All Implemented Interfaces:
    java.lang.Iterable<StringList>

    public class Dictionary
    extends java.lang.Object
    implements java.lang.Iterable<StringList>
    This class is a dictionary.
    • Constructor Summary

      Constructors 
      Constructor Description
      Dictionary()
      Initializes an empty Dictionary.
      Dictionary​(boolean caseSensitive)  
      Dictionary​(java.io.InputStream in)
      Initializes the Dictionary from an existing dictionary resource.
      Dictionary​(java.io.InputStream in, boolean caseSensitive)
      Deprecated.
      This constructor is deprecated.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Set<java.lang.String> asStringSet()
      Gets this dictionary as a Set<String>.
      boolean contains​(StringList tokens)
      Checks if this dictionary has the given entry.
      boolean equals​(java.lang.Object obj)  
      int getMaxTokenCount()  
      int getMinTokenCount()  
      int hashCode()  
      java.util.Iterator<StringList> iterator()
      Retrieves an Iterator over all tokens.
      static Dictionary parseOneEntryPerLine​(java.io.Reader in)
      Reads a dictionary which has one entry per line.
      void put​(StringList tokens)
      Adds the tokens to the dictionary as one new entry.
      void remove​(StringList tokens)
      Removes the given tokens form the current instance.
      void serialize​(java.io.OutputStream out)
      Writes the current instance to the given OutputStream.
      int size()
      Retrieves the number of tokens in the current instance.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • Dictionary

        public Dictionary()
        Initializes an empty Dictionary.
      • Dictionary

        public Dictionary​(boolean caseSensitive)
      • Dictionary

        public Dictionary​(java.io.InputStream in,
                          boolean caseSensitive)
                   throws java.io.IOException,
                          InvalidFormatException
        Deprecated.
        This constructor is deprecated. Passing the case sensitivity flag has no effect. Use Dictionary(InputStream) instead and set the case sensitivity during the dictionary creation.
        Loads a Dictionary from a XML file.
        Parameters:
        in - the dictionary in its XML format
        caseSensitive - has no effect
        Throws:
        java.io.IOException
        InvalidFormatException
    • Method Detail

      • put

        public void put​(StringList tokens)
        Adds the tokens to the dictionary as one new entry.
        Parameters:
        tokens - the new entry
      • getMinTokenCount

        public int getMinTokenCount()
        Returns:
        minimum token count in the dictionary
      • getMaxTokenCount

        public int getMaxTokenCount()
        Returns:
        maximum token count in the dictionary
      • contains

        public boolean contains​(StringList tokens)
        Checks if this dictionary has the given entry.
        Parameters:
        tokens -
        Returns:
        true if it contains the entry otherwise false
      • remove

        public void remove​(StringList tokens)
        Removes the given tokens form the current instance.
        Parameters:
        tokens -
      • iterator

        public java.util.Iterator<StringList> iterator()
        Retrieves an Iterator over all tokens.
        Specified by:
        iterator in interface java.lang.Iterable<StringList>
        Returns:
        token-Iterator
      • size

        public int size()
        Retrieves the number of tokens in the current instance.
        Returns:
        number of tokens
      • serialize

        public void serialize​(java.io.OutputStream out)
                       throws java.io.IOException
        Writes the current instance to the given OutputStream.
        Parameters:
        out -
        Throws:
        java.io.IOException
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • parseOneEntryPerLine

        public static Dictionary parseOneEntryPerLine​(java.io.Reader in)
                                               throws java.io.IOException
        Reads a dictionary which has one entry per line. The tokens inside an entry are whitespace delimited.
        Parameters:
        in -
        Returns:
        the parsed dictionary
        Throws:
        java.io.IOException
      • asStringSet

        public java.util.Set<java.lang.String> asStringSet()
        Gets this dictionary as a Set<String>. Only iterator(), size() and contains(Object) methods are implemented. If this dictionary entries are multi tokens only the first token of the entry will be part of the Set.
        Returns:
        a Set containing the entries of this dictionary