Class WordData

  • All Implemented Interfaces:
    java.lang.Cloneable

    public final class WordData
    extends java.lang.Object
    implements java.lang.Cloneable
    Stem and tag data associated with a given word. Instances of this class are reused and mutable (values returned from getStem(), getWord() and other related methods change on subsequent calls to DictionaryLookup class that returned a given instance of WordData. If you need a copy of the stem or tag data for a given word, you have to create a custom buffer yourself and copy the associated data, perform clone() or create strings (they are immutable) using getStem() and then CharSequence.toString(). For reasons above it makes no sense to use instances of this class in associative containers or lists. In fact, both equals(Object) and hashCode() are overridden and throw exceptions to prevent accidental damage.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String COLLECTIONS_ERROR_MESSAGE
      Error information if somebody puts us in a Java collection.
      private java.nio.charset.CharsetDecoder decoder
      Character encoding in internal buffers.
      (package private) java.nio.ByteBuffer stemBuffer
      Byte buffer holding stem data.
      private java.nio.CharBuffer stemCharSequence
      Character sequence after converting stemBuffer using decoder.
      (package private) java.nio.ByteBuffer tagBuffer
      Byte buffer holding tag data.
      private java.nio.CharBuffer tagCharSequence
      Character sequence after converting tagBuffer using decoder.
      (package private) java.nio.ByteBuffer wordBuffer
      Byte buffer holding the inflected word form data.
      private java.lang.CharSequence wordCharSequence
      Inflected word form data.
    • Constructor Summary

      Constructors 
      Constructor Description
      WordData​(java.lang.String stem, java.lang.String tag, java.lang.String encoding)
      A constructor for tests only.
      WordData​(java.nio.charset.CharsetDecoder decoder)
      Package scope constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      WordData clone()
      Declare a covariant of Object.clone() that returns a deep copy of this object.
      private java.lang.CharSequence cloneCharSequence​(java.lang.CharSequence chs)
      Clone char sequences only if not immutable.
      boolean equals​(java.lang.Object obj)  
      java.lang.CharSequence getStem()  
      java.nio.ByteBuffer getStemBytes​(java.nio.ByteBuffer target)
      Copy the stem's binary data (no charset decoding) to a custom byte buffer.
      java.lang.CharSequence getTag()  
      java.nio.ByteBuffer getTagBytes​(java.nio.ByteBuffer target)
      Copy the tag's binary data (no charset decoding) to a custom byte buffer.
      java.lang.CharSequence getWord()  
      java.nio.ByteBuffer getWordBytes​(java.nio.ByteBuffer target)
      Copy the inflected word's binary data (no charset decoding) to a custom byte buffer.
      int hashCode()  
      java.lang.String toString()  
      (package private) void update​(java.nio.ByteBuffer wordBuffer, java.lang.CharSequence word)  
      • Methods inherited from class java.lang.Object

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

      • COLLECTIONS_ERROR_MESSAGE

        private static final java.lang.String COLLECTIONS_ERROR_MESSAGE
        Error information if somebody puts us in a Java collection.
        See Also:
        Constant Field Values
      • decoder

        private final java.nio.charset.CharsetDecoder decoder
        Character encoding in internal buffers.
      • wordCharSequence

        private java.lang.CharSequence wordCharSequence
        Inflected word form data.
      • stemCharSequence

        private java.nio.CharBuffer stemCharSequence
        Character sequence after converting stemBuffer using decoder.
      • tagCharSequence

        private java.nio.CharBuffer tagCharSequence
        Character sequence after converting tagBuffer using decoder.
      • wordBuffer

        java.nio.ByteBuffer wordBuffer
        Byte buffer holding the inflected word form data.
      • stemBuffer

        java.nio.ByteBuffer stemBuffer
        Byte buffer holding stem data.
      • tagBuffer

        java.nio.ByteBuffer tagBuffer
        Byte buffer holding tag data.
    • Constructor Detail

      • WordData

        WordData​(java.nio.charset.CharsetDecoder decoder)
        Package scope constructor.
      • WordData

        WordData​(java.lang.String stem,
                 java.lang.String tag,
                 java.lang.String encoding)
        A constructor for tests only.
    • Method Detail

      • getStemBytes

        public java.nio.ByteBuffer getStemBytes​(java.nio.ByteBuffer target)
        Copy the stem's binary data (no charset decoding) to a custom byte buffer. The buffer is cleared prior to copying and flipped for reading upon returning from this method. If the buffer is null or not large enough to hold the result, a new buffer is allocated.
        Parameters:
        target - Target byte buffer to copy the stem buffer to or null if a new buffer should be allocated.
        Returns:
        Returns target or the new reallocated buffer.
      • getTagBytes

        public java.nio.ByteBuffer getTagBytes​(java.nio.ByteBuffer target)
        Copy the tag's binary data (no charset decoding) to a custom byte buffer. The buffer is cleared prior to copying and flipped for reading upon returning from this method. If the buffer is null or not large enough to hold the result, a new buffer is allocated.
        Parameters:
        target - Target byte buffer to copy the tag buffer to or null if a new buffer should be allocated.
        Returns:
        Returns target or the new reallocated buffer.
      • getWordBytes

        public java.nio.ByteBuffer getWordBytes​(java.nio.ByteBuffer target)
        Copy the inflected word's binary data (no charset decoding) to a custom byte buffer. The buffer is cleared prior to copying and flipped for reading upon returning from this method. If the buffer is null or not large enough to hold the result, a new buffer is allocated.
        Parameters:
        target - Target byte buffer to copy the word buffer to or null if a new buffer should be allocated.
        Returns:
        Returns target or the new reallocated buffer.
      • getTag

        public java.lang.CharSequence getTag()
        Returns:
        Return tag data decoded to a character sequence or null if no associated tag data exists.
      • getStem

        public java.lang.CharSequence getStem()
        Returns:
        Return stem data decoded to a character sequence or null if no associated stem data exists.
      • 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
      • clone

        public WordData clone()
        Declare a covariant of Object.clone() that returns a deep copy of this object. The content of all internal buffers is copied.
        Overrides:
        clone in class java.lang.Object
      • cloneCharSequence

        private java.lang.CharSequence cloneCharSequence​(java.lang.CharSequence chs)
        Clone char sequences only if not immutable.
      • update

        void update​(java.nio.ByteBuffer wordBuffer,
                    java.lang.CharSequence word)