org.mmbase.storage.util
Class TypeMapping

java.lang.Object
  extended byorg.mmbase.storage.util.TypeMapping
All Implemented Interfaces:
java.lang.Comparable

public class TypeMapping
extends java.lang.Object
implements java.lang.Comparable

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).

Version:
$Id: TypeMapping.java,v 1.3 2003/09/01 13:29:46 pierre Exp $
Author:
Pierre van Rooden

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

Field Detail

type

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


name

public java.lang.String name
The name of the MMBase type to map


minSize

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


maxSize

public int 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(int size)
Sets a fixed size for this TypeMapping. Effectively, this sets the minimimum and maximum size of the type mapping to the specified value, ensuring this TypeMapping object is equal to all TypeMappings whos minimum size is equal to or smaller than the size, and teh maximum size is equal to or greater that this size.

Parameters:
size - the size to set

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable

equals

public boolean equals(java.lang.Object o)

getType

public java.lang.String getType(int size)
Returns the mappings type.


toString

public java.lang.String toString()


MMBase build 1.7.1.20041002