org.mmbase.storage.util
Class TypeMapping

Package class diagram package TypeMapping
java.lang.Object
  extended by org.mmbase.storage.util.TypeMapping
All Implemented Interfaces:
Comparable<TypeMapping>

public class TypeMapping
extends Object
implements Comparable<TypeMapping>

The TypeMapping class helps translating MMBase types to storage-specific type descriptions. Examples of type mappings are mappings that convert to database field types. I.e., a STRING with size 0-255 could be configured to translate to 'varchar({0})', '{0}, in this case,. being the size of the actual field.
TypeMapping is a comparable class, which allows it to be used in a sorted map, set or list. However, Typemapping needs fuzzy matching so it is easy to locate the appropriate type-mapping for a field. As such, it's natural ordering is NOT consistent with equals. A typemapping may be considered 'equal' while still having a different ordering position in the class. This allows for an easy search on a sorted list of TypeMappings: By using 'IndexOf' you can quickly find a TypeMapping in a list, even if the min or max sizes for the type do not completely match. You typically use this if you searxh for a TypeMapping whose size you set with 'getSize()', rather than setting a specific range (using the minSize/maxSize properties).

Since:
MMBase-1.7
Version:
$Id: TypeMapping.java 34900 2009-05-01 16:29:42Z michiel $
Author:
Pierre van Rooden

Field Summary
 long maxSize
          The maximum size of the MMBase type to map.
 long minSize
          The minimum size of the MMBase type to map.
 String name
          The name of the MMBase type to map
 String type
          The expression this type should translate to.
 
Constructor Summary
TypeMapping()
           
 
Method Summary
 int compareTo(TypeMapping o)
           
 boolean equals(Object o)
           
 String getType(Object... messageFormatArguments)
          Returns the mappings type.
 int hashCode()
           
 void setFixedSize(long size)
          Sets a fixed size for this TypeMapping.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

type

public String type
The expression this type should translate to. You can access this property directly, but you can use getType(Object...) to obtain an expanded expression.


name

public String name
The name of the MMBase type to map


minSize

public long minSize
The minimum size of the MMBase type to map. A value of -1 indicates no mimimum.


maxSize

public long maxSize
The maximum size of the MMBase type to map. A value of -1 indicates no maximum.

Constructor Detail

TypeMapping

public TypeMapping()
Method Detail

setFixedSize

public void setFixedSize(long size)
Sets a fixed size for this TypeMapping. Effectively, this sets the minimum and maximum size of the type mapping to the specified value, ensuring this TypeMapping object is equal to all TypeMappings which minimum size is equal to or smaller than the size, and the maximum size is equal to or greater that this size.

Parameters:
size - the size to set

compareTo

public int compareTo(TypeMapping o)
Specified by:
compareTo in interface Comparable<TypeMapping>

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

getType

public String getType(Object... messageFormatArguments)
Returns the mappings type.

Parameters:
messageFormatArguments - Argument to use as arugment for the used MessageFormat.format(String, Object...).
Returns:
mappings type

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()


MMBase2 Core 2.0-SNAPSHOT - 2013-03-30T06:36