Class DefaultKeyConverter

java.lang.Object
com.tangosol.coherence.rest.DefaultKeyConverter
All Implemented Interfaces:
KeyConverter

public class DefaultKeyConverter extends Object implements KeyConverter
Default implementation of KeyConverter for a given key class.

This KeyConverter implementation uses the following rules to perform key conversion:

  • toString:
    1. if the key class is java.util.Date, format the argument as yyyy-MM-dd;
    2. if the key class is UUID or UID, return a hexadecimal representation of the argument without the leading Ox;
    3. otherwise, call the toString method on the argument
  • fromString:
    1. if the key class is java.util.Date, the given string needs to be formatted as yyyy-MM-dd;
    2. otherwise, look for a constructor or a static fromString, valueOf or parse method (in that order) on the key class
Author:
as 2011.06.08
  • Field Details

    • m_clzKey

      protected final Class m_clzKey
      Key class.
    • m_ctorFromString

      protected final Constructor m_ctorFromString
      Constructor to use for conversion from string.
    • m_methFromString

      protected final Method m_methFromString
      Static method to use for conversion from string.
    • METHODS

      protected static final String[] METHODS
      Method names that should be tried in order when looking for a method that can be used for conversion from string.
    • DATE_FORMAT

      protected static final DateFormat DATE_FORMAT
      DateFormat instance that will be used to convert Date keys.
  • Constructor Details

    • DefaultKeyConverter

      public DefaultKeyConverter(Class clzKey)
      Construct a DefaultKeyConverter instance.
      Parameters:
      clzKey - key class
  • Method Details

    • fromString

      public Object fromString(String sKey)
      Convert a string representation of a key into its object form.
      Specified by:
      fromString in interface KeyConverter
      Parameters:
      sKey - key as a string
      Returns:
      key in its object form
    • toString

      public String toString(Object oKey)
      Convert an object representation of a key into its string form.
      Specified by:
      toString in interface KeyConverter
      Parameters:
      oKey - key in its original object form
      Returns:
      string representation of a key
    • findConstructor

      protected Constructor findConstructor()
      Find a key class constructor that accepts a single String argument.
      Returns:
      constructor if it exists, null otherwise
    • findMethod

      protected Method findMethod(String sMethodName)
      Find a static method with a specified name that accepts a single String argument.
      Parameters:
      sMethodName - the name of the method
      Returns:
      method if it exists, null otherwise