org.mmbase.datatypes
Class ComparableDataType<E extends Serializable & Comparable<E>>

java.lang.Object
  extended by org.mmbase.core.AbstractDescriptor
      extended by org.mmbase.datatypes.BasicDataType<E>
          extended by org.mmbase.datatypes.ComparableDataType<E>
All Implemented Interfaces:
Serializable, Cloneable, Comparable<DataType<E>>, Descriptor, DataType<E>, PublicCloneable<AbstractDescriptor>
Direct Known Subclasses:
DateTimeDataType, NumberDataType, StringDataType

public abstract class ComparableDataType<E extends Serializable & Comparable<E>>
extends BasicDataType<E>

Comparable datatypes have values which are Comparable, so can be ordered, and therefore can have a minimum and a maximum value.

Since:
MMBase-1.8
Version:
$Id: ComparableDataType.java 41983 2010-04-20 15:27:34Z michiel $
Author:
Michiel Meeuwissen
See Also:
Serialized Form

Nested Class Summary
protected  class ComparableDataType.MaxRestriction
           
protected  class ComparableDataType.MinRestriction
           
 
Nested classes/interfaces inherited from class org.mmbase.datatypes.BasicDataType
BasicDataType.AbstractRestriction<D extends Serializable>, BasicDataType.DataTypeComparator<D>, BasicDataType.EnumerationRestriction, BasicDataType.RequiredRestriction, BasicDataType.RestrictedEnumerationIterator, BasicDataType.StaticAbstractRestriction<D extends Serializable>, BasicDataType.TypeRestriction, BasicDataType.UniqueRestriction
 
Nested classes/interfaces inherited from interface org.mmbase.datatypes.DataType
DataType.Restriction<D extends Serializable>
 
Field Summary
protected  ComparableDataType.MaxRestriction maxRestriction
           
protected  ComparableDataType.MinRestriction minRestriction
           
 
Fields inherited from class org.mmbase.datatypes.BasicDataType
DATATYPE_BUNDLE, defaultValue, enumerationRestriction, origin, requiredRestriction, typeRestriction, uniqueRestriction
 
Fields inherited from class org.mmbase.core.AbstractDescriptor
description, guiName, key
 
Fields inherited from interface org.mmbase.datatypes.DataType
ENFORCE_ABSOLUTE, ENFORCE_ALWAYS, ENFORCE_NEVER, ENFORCE_ONCHANGE, ENFORCE_ONCREATE, ENFORCE_ONVALIDATE, PROCESS_GET, PROCESS_SET, VALID, XMLNS
 
Constructor Summary
protected ComparableDataType(String name, Class<E> classType)
           
 
Method Summary
 ComparableDataType<E> clone(String name)
          Returns a cloned instance of this datatype, inheriting all validation rules.
protected  void cloneRestrictions(BasicDataType<E> origin)
          If a datatype is cloned, the restrictions of it (normally implemented as inner classes), must be reinstantiated.
protected  int compare(E comp1, E comp2)
           
abstract  E first()
          Returns a natural 'first' value.
 Comparator<E> getComparator()
           
 E getDefaultValue(Locale locale, Cloud cloud, Field field)
          Returns the (locale dependent) default value of this data type,
 int getEnforceStrength()
          The maximum enforce strength of all restrictions on this datatype.
 DataType.Restriction<E> getMaxRestriction()
           
 DataType.Restriction<E> getMinRestriction()
           
protected  void inheritRestrictions(BasicDataType<E> origin)
          If a datatype inherits from another datatype all its restrictions inherit too.
 boolean isMaxInclusive()
          Returns whether the maximum value for this data type is inclusive or not.
 boolean isMinInclusive()
          Returns whether the minimum value for this data type is inclusive or not.
 void setMax(E value, boolean inclusive)
          Sets the maximum Date value for this data type.
 void setMin(E value, boolean inclusive)
          Sets the minimum Date value for this data type.
protected  StringBuilder toStringBuilder()
           
 void toXml(Element parent)
          Fills this datatype in another XML (for example in the xml of DataType.getOrigin(), to make one XML, fully describing the DataType).
protected  Collection<LocalizedString> validateCastValue(Collection<LocalizedString> errors, Object castValue, Object value, Node node, Field field)
           
 
Methods inherited from class org.mmbase.datatypes.BasicDataType
addErrorDescription, addRestriction, addRestriction, addStyleClass, cast, cast, castAndValidate, castForSearch, castOrException, castToPresent, castToValidate, checkType, clone, compareTo, edit, equals, finish, finish, getBaseType, getBaseTypeIdentifier, getCloud, getCloud, getCommitProcessor, getDefaultProcessor, getDefaultValue, getDeleteProcessor, getElement, getElement, getEnforceString, getEnumerationFactory, getEnumerationRestriction, getEnumerationValue, getEnumerationValues, getHandler, getHandlers, getOrigin, getProcessor, getProcessor, getProcessorWithoutDefault, getRequiredRestriction, getRestrictions, getStyleClasses, getTypeAsClass, getUniqueRestriction, hashCode, inherit, inheritProperties, isCorrectType, isFinished, isRequired, isUnique, preCast, preCast, preCast, rewrite, setCommitProcessor, setDefaultProcessor, setDefaultValue, setDeleteProcessor, setProcessor, setProcessor, setRequired, setUnique, setXml, toString, toXml, validate, validate, validateCastValueOrNull, validateRequired, xmlValue
 
Methods inherited from class org.mmbase.core.AbstractDescriptor
getDefaultLocale, getDescription, getDescription, getGUIName, getGUIName, getLocalizedDescription, getLocalizedGUIName, getName, setDescription, setDescription, setGUIName, setGUIName, setLocalizedDescription, setLocalizedGUIName
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mmbase.bridge.Descriptor
getDescription, getDescription, getGUIName, getGUIName, getLocalizedDescription, getLocalizedGUIName, getName, setDescription, setDescription, setGUIName, setGUIName
 

Field Detail

minRestriction

protected ComparableDataType.MinRestriction minRestriction

maxRestriction

protected ComparableDataType.MaxRestriction maxRestriction
Constructor Detail

ComparableDataType

protected ComparableDataType(String name,
                             Class<E> classType)
Method Detail

inheritRestrictions

protected void inheritRestrictions(BasicDataType<E> origin)
Description copied from class: BasicDataType
If a datatype inherits from another datatype all its restrictions inherit too.

Overrides:
inheritRestrictions in class BasicDataType<E extends Serializable & Comparable<E>>

cloneRestrictions

protected void cloneRestrictions(BasicDataType<E> origin)
Description copied from class: BasicDataType
If a datatype is cloned, the restrictions of it (normally implemented as inner classes), must be reinstantiated.

Overrides:
cloneRestrictions in class BasicDataType<E extends Serializable & Comparable<E>>

getMinRestriction

public DataType.Restriction<E> getMinRestriction()

isMinInclusive

public boolean isMinInclusive()
Returns whether the minimum value for this data type is inclusive or not.

Returns:
true if the minimum value if inclusive, false if it is not, or if there is no minimum.

getMaxRestriction

public DataType.Restriction<E> getMaxRestriction()

isMaxInclusive

public boolean isMaxInclusive()
Returns whether the maximum value for this data type is inclusive or not.

Returns:
true if the maximum value if inclusive, false if it is not, or if there is no minimum.

getDefaultValue

public E getDefaultValue(Locale locale,
                         Cloud cloud,
                         Field field)
Description copied from class: BasicDataType
Returns the (locale dependent) default value of this data type,

Specified by:
getDefaultValue in interface DataType<E extends Serializable & Comparable<E>>
Overrides:
getDefaultValue in class BasicDataType<E extends Serializable & Comparable<E>>

toXml

public void toXml(Element parent)
Description copied from interface: DataType
Fills this datatype in another XML (for example in the xml of DataType.getOrigin(), to make one XML, fully describing the DataType). The implementation of this method is unfinished!

Specified by:
toXml in interface DataType<E extends Serializable & Comparable<E>>
Overrides:
toXml in class BasicDataType<E extends Serializable & Comparable<E>>
Parameters:
parent - a 'datatype' element.

setMin

public void setMin(E value,
                   boolean inclusive)
Sets the minimum Date value for this data type.

Parameters:
value - the minimum as an Comparable (and Serializable), or null if there is no minimum.
inclusive - whether the minimum value is inclusive or not
Throws:
Class<T> - Identifier: java.lang.UnsupportedOperationException if this data type is read-only (i.e. defined by MMBase)

setMax

public void setMax(E value,
                   boolean inclusive)
Sets the maximum Date value for this data type.

Parameters:
value - the maximum as an Comparable (and Serializable), or null if there is no maximum.
inclusive - whether the maximum value is inclusive or not
Throws:
Class<T> - Identifier: java.lang.UnsupportedOperationException if this data type is read-only (i.e. defined by MMBase)

getEnforceStrength

public int getEnforceStrength()
Description copied from interface: DataType
The maximum enforce strength of all restrictions on this datatype. See DataType.ENFORCE_ALWAYS, DataType.ENFORCE_ONCHANGE, DataType.ENFORCE_NEVER.

Specified by:
getEnforceStrength in interface DataType<E extends Serializable & Comparable<E>>
Overrides:
getEnforceStrength in class BasicDataType<E extends Serializable & Comparable<E>>
Returns:
maximum enforce strength

validateCastValue

protected Collection<LocalizedString> validateCastValue(Collection<LocalizedString> errors,
                                                        Object castValue,
                                                        Object value,
                                                        Node node,
                                                        Field field)
Overrides:
validateCastValue in class BasicDataType<E extends Serializable & Comparable<E>>

clone

public ComparableDataType<E> clone(String name)
Description copied from class: BasicDataType
Returns a cloned instance of this datatype, inheriting all validation rules. Similar to calling clone(), but changes the data type name if one is provided. Besides super.clone, it calls BasicDataType.inheritProperties(BasicDataType) and BasicDataType.cloneRestrictions(BasicDataType). A clone is not finished. See BasicDataType.isFinished().

Specified by:
clone in interface DataType<E extends Serializable & Comparable<E>>
Overrides:
clone in class BasicDataType<E extends Serializable & Comparable<E>>
Parameters:
name - the new name of the copied datatype (can be null, in which case the name is not changed).
Returns:
cloned DataType

toStringBuilder

protected StringBuilder toStringBuilder()
Overrides:
toStringBuilder in class BasicDataType<E extends Serializable & Comparable<E>>

compare

protected int compare(E comp1,
                      E comp2)
Since:
MMBase-1.9.2

getComparator

public Comparator<E> getComparator()
Overrides:
getComparator in class BasicDataType<E extends Serializable & Comparable<E>>
Since:
MMBase-1.9.2

first

public abstract E first()
Returns a natural 'first' value. This may return some kind of 0

Since:
MMBase-2.0


MMBase 2.0-SNAPSHOT - null