Package com.tangosol.coherence.rest
Class DefaultKeyConverter
- java.lang.Object
-
- com.tangosol.coherence.rest.DefaultKeyConverter
-
- All Implemented Interfaces:
KeyConverter
public class DefaultKeyConverter extends Object implements KeyConverter
Default implementation ofKeyConverterfor a given key class.This
KeyConverterimplementation uses the following rules to perform key conversion:- toString:
- fromString:
- if the key class is java.util.Date, the given string needs to be formatted as yyyy-MM-dd;
- 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 Summary
Fields Modifier and Type Field Description protected static DateFormatDATE_FORMATDateFormat instance that will be used to convert Date keys.protected Classm_clzKeyKey class.protected Constructorm_ctorFromStringConstructor to use for conversion from string.protected Methodm_methFromStringStatic method to use for conversion from string.protected static String[]METHODSMethod names that should be tried in order when looking for a method that can be used for conversion from string.
-
Constructor Summary
Constructors Constructor Description DefaultKeyConverter(Class clzKey)Construct a DefaultKeyConverter instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ConstructorfindConstructor()Find a key class constructor that accepts a single String argument.protected MethodfindMethod(String sMethodName)Find a static method with a specified name that accepts a single String argument.ObjectfromString(String sKey)Convert a string representation of a key into its object form.StringtoString(Object oKey)Convert an object representation of a key into its string form.
-
-
-
Field Detail
-
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 Detail
-
DefaultKeyConverter
public DefaultKeyConverter(Class clzKey)
Construct a DefaultKeyConverter instance.- Parameters:
clzKey- key class
-
-
Method Detail
-
fromString
public Object fromString(String sKey)
Convert a string representation of a key into its object form.- Specified by:
fromStringin interfaceKeyConverter- 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:
toStringin interfaceKeyConverter- 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
-
-