Package adams.core.base
Class BaseObject
- java.lang.Object
-
- adams.core.base.BaseObject
-
- All Implemented Interfaces:
CloneHandler<BaseObject>
,Serializable
,Comparable
- Direct Known Subclasses:
AbstractBaseString
,BaseBoolean
,BaseByte
,BaseCharacter
,BaseColor
,BaseDate
,BaseDateTime
,BaseDateTimeMsec
,BaseDouble
,BaseFloat
,BaseInteger
,BaseLong
,BaseShort
,BaseTime
,BaseTimeMsec
,BaseURI
,BaseURL
public abstract class BaseObject extends Object implements Comparable, CloneHandler<BaseObject>, Serializable
Super class for wrappers around classes like String, Integer, etc.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Comparable
m_Internal
the internal object.protected static Map<Class,Properties>
m_Properties
the properties with the templates.static String
SUFFIX_DISPLAY
static String
SUFFIX_VALUE
-
Constructor Summary
Constructors Constructor Description BaseObject(String s)
Initializes the object with the string to parse.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
compareTo(Object o)
Compares this object with the specified object for order.boolean
equals(Object o)
Compares itself against the other base object.BaseObject
getClone()
Returns a clone of itself.Comparable
getInternal()
Returns the internal object.static <T extends BaseObject>
Map<String,T>getTemplates(Class<T> cls)
Returns the predefined templates.
Properties file in same location as class, e.g.:
adams.core.base.BaseObject -> adams/core/base/BaseObject.props
Format of props file:abstract String
getTipText()
Returns a tool tip for the GUI editor (ignored if null is returned).String
getUnicode()
Returns the underlying object as string with escaped unicode sequences.abstract String
getValue()
Returns the current string value.boolean
hasFavoritesSupport()
Whether this object should have favorites support.int
hashCode()
Hashcode so can be used as hashtable key.protected void
initialize()
Initializes the internal object.abstract boolean
isValid(String value)
Checks whether the string value is a valid presentation for this class.boolean
isValidUnicode(String value)
Checks whether the string value (with escaped unicode sequences) is a valid presentation for this class.static BaseObject
newInstance(Class cls, String s)
Creates a new instance of the specified BaseObject-derived class and sets the specified value.void
setUnicode(String value)
Sets the string value with escaped unicode sequences.abstract void
setValue(String value)
Sets the string value.static BaseObject[]
toObjectArray(String[] array, Class cls)
Turns the String array into a BaseObject array.static BaseObject[]
toObjectArray(List<String> array, Class cls)
Turns the String array into a BaseObject array.String
toString()
Returns the underlying object as string.static String[]
toStringArray(BaseObject[] array)
Turns the BaseObject array into a string array.static List<String>
toStringList(BaseObject[] array)
Turns the BaseObject array into a string list.
-
-
-
Field Detail
-
SUFFIX_DISPLAY
public static final String SUFFIX_DISPLAY
- See Also:
- Constant Field Values
-
SUFFIX_VALUE
public static final String SUFFIX_VALUE
- See Also:
- Constant Field Values
-
m_Properties
protected static Map<Class,Properties> m_Properties
the properties with the templates.
-
m_Internal
protected Comparable m_Internal
the internal object.
-
-
Constructor Detail
-
BaseObject
public BaseObject(String s)
Initializes the object with the string to parse.- Parameters:
s
- the string to parse
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the internal object.
Default implementation does nothing.
-
getClone
public BaseObject getClone()
Returns a clone of itself.- Specified by:
getClone
in interfaceCloneHandler<BaseObject>
- Returns:
- the clone or null in case of an error
-
compareTo
public int compareTo(Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.- Specified by:
compareTo
in interfaceComparable
- Parameters:
o
- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
- Throws:
ClassCastException
- if the specified object's type prevents it from being compared to this object.
-
equals
public boolean equals(Object o)
Compares itself against the other base object.- Overrides:
equals
in classObject
- Parameters:
o
- the object to compare against- Returns:
- true if the internal string is the same
- See Also:
compareTo(Object)
-
hashCode
public int hashCode()
Hashcode so can be used as hashtable key. Returns the hashcode of the internal string.
-
getInternal
public Comparable getInternal()
Returns the internal object.- Returns:
- the internal object
-
isValid
public abstract boolean isValid(String value)
Checks whether the string value is a valid presentation for this class.- Parameters:
value
- the string value to check- Returns:
- true if valid
-
isValidUnicode
public boolean isValidUnicode(String value)
Checks whether the string value (with escaped unicode sequences) is a valid presentation for this class.- Parameters:
value
- the string value to check- Returns:
- true if valid
-
setValue
public abstract void setValue(String value)
Sets the string value.- Parameters:
value
- the string value
-
getValue
public abstract String getValue()
Returns the current string value.- Returns:
- the string value
-
setUnicode
public void setUnicode(String value)
Sets the string value with escaped unicode sequences.- Parameters:
value
- the string value
-
getUnicode
public String getUnicode()
Returns the underlying object as string with escaped unicode sequences.- Returns:
- the underlying object
- See Also:
getValue()
,Utils.escapeUnicode(String)
-
getTipText
public abstract String getTipText()
Returns a tool tip for the GUI editor (ignored if null is returned).- Returns:
- the tool tip
-
toString
public String toString()
Returns the underlying object as string.- Overrides:
toString
in classObject
- Returns:
- the underlying object
- See Also:
getValue()
-
hasFavoritesSupport
public boolean hasFavoritesSupport()
Whether this object should have favorites support.
Default is false.- Returns:
- true if to support favorites
-
newInstance
public static BaseObject newInstance(Class cls, String s)
Creates a new instance of the specified BaseObject-derived class and sets the specified value.- Parameters:
cls
- the class to instantiates
- the value to set- Returns:
- the instantiated object, null if class cannot be instantiated or value is invalid
-
toStringArray
public static String[] toStringArray(BaseObject[] array)
Turns the BaseObject array into a string array.- Parameters:
array
- the array to convert- Returns:
- the generated string array
-
toStringList
public static List<String> toStringList(BaseObject[] array)
Turns the BaseObject array into a string list.- Parameters:
array
- the array to convert- Returns:
- the generated string list
-
toObjectArray
public static BaseObject[] toObjectArray(String[] array, Class cls)
Turns the String array into a BaseObject array.- Parameters:
array
- the array to convertcls
- the BaseObject derived class to use- Returns:
- the generated object array
-
toObjectArray
public static BaseObject[] toObjectArray(List<String> array, Class cls)
Turns the String array into a BaseObject array.- Parameters:
array
- the array to convertcls
- the BaseObject derived class to use- Returns:
- the generated object array
-
getTemplates
public static <T extends BaseObject> Map<String,T> getTemplates(Class<T> cls)
Returns the predefined templates.
Properties file in same location as class, e.g.:
adams.core.base.BaseObject -> adams/core/base/BaseObject.props
Format of props file:ID.display=text to display in GUI ID.value=value to set
- Returns:
- the templates
-
-