com.h3c.util.codec

## Class StringSetCodec

- java.lang.Object
- - com.h3c.util.codec.StringSetCodec

- All Implemented Interfaces:
    Encodable, StringCodec
  Direct Known Subclasses:
    EntropicStringSetCodec

      public class StringSetCodec
      extends Object
      implements StringCodec, Encodable

  This class takes a set of strings and provides an implementation of `StringCodec` that encodes each given string to a shorter, but unique alternate. Note that once the codec is instantiated it is immutable. For a codec that allows you to add mappings after construction, use `EntropicStringSetCodec` instead.
  See Also:
    `CodecFactory`

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `decode(String enc)` Decodes an encoded value.
    `String` | `encode(String str)` Encodes an original string.
    `boolean` | `equals(Object o)`
    `int` | `hashCode()`
    `int` | `size()` Returns the number of mappings in the codec.
    `String` | `toDebugString()` Provides a multi-line string representation of the codec useful for debugging purposes.
    `String` | `toEncodedString()` Returns an encodement of this implementation.
    `String` | `toString()`
    `static StringSetCodec` | `valueOf(String blueprint)` Recreates an instance of StringSetCodec from the supplied blueprint.

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### encode

          public String encode(String str)

      Encodes an original string.
      Specified by:
        `encode` in interface `StringCodec`
      Parameters:
        `str` - the original string
      Returns:
        the encoded value
      Throws:
        `NullPointerException` - if the parameter is null
        `IllegalArgumentException` - if the original string is not a member of the initializing set

    - #### decode

          public String decode(String enc)

      Decodes an encoded value.
      Specified by:
        `decode` in interface `StringCodec`
      Parameters:
        `enc` - the encoded value
      Returns:
        the original string
      Throws:
        `NullPointerException` - if the parameter is null
        `IllegalArgumentException` - if the encoded value is not a member of the encodings for the initializing set

    - #### size

          public int size()

      Description copied from interface: `StringCodec`
      Returns the number of mappings in the codec.
      Specified by:
        `size` in interface `StringCodec`
      Returns:
        the number of mappings.

    - #### toEncodedString

          public String toEncodedString()

      Returns an encodement of this implementation. Essentially, this is a blueprint that can be stored, and later used to reconstruct this specific implementation of the codec.
      Specified by:
        `toEncodedString` in interface `Encodable`
      Returns:
        the blueprint of this codec instance

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### toDebugString

          public String toDebugString()

      Provides a multi-line string representation of the codec useful for debugging purposes. It shows all the mappings.
      Returns:
        a multi-line string representation

    - #### valueOf

          public static StringSetCodec valueOf(String blueprint)

      Recreates an instance of StringSetCodec from the supplied blueprint. Essentially, the blueprint is a Memento that was previously generated via `toEncodedString()`.
      Parameters:
        `blueprint` - the blueprint
      Returns:
        the corresponding StringSetCodec implementation
      Throws:
        `NullPointerException` - if blueprint is null
        `IllegalArgumentException` - if blueprint if badly formed

Copyright © 2014. All Rights Reserved.