|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjava.text.Format
com.davisor.data.Type
com.davisor.data.LocaleType
com.davisor.data.FormatType
com.davisor.data.TupleType
TupleType defines a tuple of types where each element has it's own type. Element types may be any types, even other tuples which then recursively contain more elements with their own types.
Tuple types address their member types in four different ways:
Integer indexes refer directly to the array a tuple uses to store
it's members. The indexes give the tuple members a well-defined
order, and the tuple a well-defined size. Relevant
methods for this access mode are getSize() and
getType(int).
The second reference method uses type identifier strings associated
with each tuple member. Member identifiers allow convenient random
access to tuple members. Relevant methods for this access mode are
getID(int), getIndex(java.lang.String), and getType(int).
The third method uses data names to identify types. Unlike member
identification strings, data names need not be mutually
unique. Instead, data names may be used to group and give
"meanings" to members. For example, one or more members types
could have the name "temperature", which would allow identification
of all members that carry temperature data information. The types
that represent temperature may vary between various integer and
floating point types. Furthermore, the identification strings tell
each temperature member apart. Relevant methods for this access
mode are getTypeIndex(java.lang.String) and getTypeIndexes(java.lang.String).
The fourth and most elaborate method to access types is by type
compatibility. Type compatibility is measured by a floating point
value between 0.0 and 1.0, where zero means that data of the first
type cannot be converted to the given another type, and one means
that the types are identical. Values between express a varying
degree of type compatibility. Relevant methods for this access mode
are getTypeIndex(java.lang.String) and getTypeIndexes(java.lang.String).
Tuples support tuple mapping between tuple types. Tuple mapping
converts tuples with one set and order of members to tuples with
another set and order of members. This is useful for example with
tuple streams that bring in data from various sources to be
consumed in different data sinks. Tuple mapping is carried out
with integer tables as described in the getTypeIndexMap(com.davisor.data.TupleType)
method documentation.
Tuples support standard Java utility messages formats, and custom tuple formats. These formats support a number of powerfull tuple content parsing and formatting operations. Furthermore, a tuple type may be associated with an additional values map that tuple formats may use to satisfy advanced value resolvation tasks.
getTypeIndexMap(com.davisor.data.TupleType),
rearrange(com.davisor.data.TupleData, int[]),
setAdditionalValues(java.util.Map),
setFormat(java.lang.String),
TupleData,
TupleFormat,
TuplePatternType,
Serialized Form| Nested Class Summary |
| Nested classes inherited from class java.text.Format |
java.text.Format.Field |
| Field Summary | |
protected java.util.Map |
M_additionalValues
Additional values map. |
protected java.util.Map |
M_keys
Tuple type unique identifiers. |
static java.lang.String |
TYPENAME
Type name ("TUPLE"). |
| Fields inherited from class com.davisor.data.FormatType |
M_pattern, M_sample |
| Fields inherited from class com.davisor.data.LocaleType |
DEFAULT_LOCALE, M_locale |
| Fields inherited from class com.davisor.data.Type |
METADATA_GROUP, METADATA_NAME, METADATA_PARENT, METADATA_SUBCHANNELS |
| Constructor Summary | |
|
TupleType(java.sql.ResultSet rs,
java.util.Map dataNames)
Creates a tuple of types from a result set by extracting meta data from the given result set by and creating a new tuple type from the information it contains. |
|
TupleType(java.sql.ResultSetMetaData rsmd,
java.util.Map dataNames)
Creates a tuple of types from the result set meta data. |
|
TupleType(java.sql.ResultSetMetaData rsmd,
java.lang.String[] dataNames)
Creates a tuple of types from the result set meta data. |
|
TupleType(java.sql.ResultSet rs,
java.lang.String[] dataNames)
Creates a tuple of types from a result set by extracting meta data from the given result set and by creating a new tuple type from the information it contains. |
|
TupleType(java.lang.String dataName,
java.lang.String id,
int size)
Creates a new tuple data type of the given number of subtypes. |
|
TupleType(java.lang.String dataName,
java.lang.String id,
java.text.MessageFormat formatter)
Creates a tuple type from an element type description string. |
|
TupleType(java.lang.String dataName,
java.lang.String id,
java.lang.String format)
Creates a tuple type from specification string. |
protected |
TupleType(java.lang.String typeName,
java.lang.String dataName,
java.lang.String id,
java.util.Map metaData,
java.util.Locale locale,
java.lang.String pattern,
java.lang.Object sample,
Type[] types,
java.util.Map keys)
Creates a new tuple type. |
|
TupleType(java.lang.String dataName,
java.lang.String id,
Type type)
Creates a new one element tuple type. |
|
TupleType(java.lang.String dataName,
java.lang.String id,
Type type1,
Type type2)
Creates a new tuple data type from two subtypes. |
|
TupleType(java.lang.String dataName,
java.lang.String id,
Type type1,
Type type2,
Type type3)
Creates a new tuple data type from three subtypes. |
|
TupleType(TupleType tt)
Deep copy constructor. |
| Method Summary | |
boolean |
containsKey(java.lang.String key)
Returns true if this type contains an element for
the specified key. |
protected java.text.Format |
createFormatter()
Creates a new TupleFormat instance from the current
pattern, locale, and additional value settings. |
com.davisor.core.Dupable |
dup()
Makes a deep copy of this object. |
boolean |
equals(java.lang.Object o)
Tests if this object is equal with another object. |
java.util.Map |
getAdditionalValues()
Gets additional values map associated with this type. |
java.lang.String |
getFormat()
Get the format specification string for this tuple type. |
java.lang.String |
getId(int index)
Deprecated. replaced with getID(int) |
java.lang.String |
getID(int index)
Gets tuple member type (unique) id by member index. |
int |
getIndex(java.lang.String memberId)
Gets tuple member type index by (unique) member identifier. |
int |
getMaxDepth()
Gets tuple type maximum recursion depth. |
int |
getSize()
Gets the number of tuple elements. |
int |
getSQLCode()
Gets the SQL type code, as defined by java.sql.Types (ARRAY). |
Type |
getType(int index)
Gets the tuple member type by index. |
Type |
getType(java.lang.String memberId)
Gets tuple member type by a (unique) member identifier. |
int |
getTypeIndex(java.lang.String typeName)
Gets the index of the first tuple member type with a type name that matches the given name. |
int |
getTypeIndex(java.lang.String typeName,
boolean[] allocation)
Gets the index of the first unallocated tuple member type with a type name that matches the given name. |
int |
getTypeIndex(Type type)
Gets the index of the tuple member type that best matches the given type. |
int |
getTypeIndex(Type templateType,
boolean[] allocation)
Gets the index of an unallocated tuple member type that best matches the given type. |
int[] |
getTypeIndexes(java.lang.String typeName)
Gets all the indexes of the unallocated tuple member types with a type name that matches the given name. |
int[] |
getTypeIndexes(java.lang.String typeName,
boolean[] allocation)
Gets all the indexes of the unallocated tuple member types with a type name that matches the given name. |
int[] |
getTypeIndexMap(TupleType templateType)
Creates an index map that maps the elements of the given tuple type to the elements of this tuple type. |
java.lang.Class |
getValueClass()
Gets value container class. |
int |
hashCode()
Returns a hash code value for the object. |
boolean |
isNumber(int index)
Tests if the given member is a NumberType instance. |
java.util.Set |
keySet()
Returns a set view of the element keys contained in this type. |
TupleData |
rearrange(TupleData data,
int[] map)
Re-arranges the elements in the given tuple to a new tuple of this type in an efficient way. |
void |
setAdditionalValues(java.util.Map additionalValues)
Sets additional values map. |
void |
setFormat(java.lang.String format)
Sets the tuple format type specification string. |
void |
setType(int index,
Type type)
Sets a tuple member. |
DataValue |
toData(java.sql.CallableStatement statement,
int column)
Converts a callable statement variable to a data value. |
DataValue |
toData(java.lang.Object value)
Converts an object to a tuple data object. |
DataValue |
toData(java.sql.ResultSet resultSet,
int column)
Converts a result set column value to a data value. |
DataValue |
toData(java.lang.String stringValue,
java.text.ParsePosition status)
Converts a string to a data value. |
java.lang.String |
toString()
Gets tuple type string representation. |
DataValue |
zero()
Gets zero data value for this type. |
| Methods inherited from class com.davisor.data.FormatType |
clearFormatter, getFormatter, getPattern, getSample, setFormat, setLocale, setPattern, setSample |
| Methods inherited from class com.davisor.data.LocaleType |
getLocale, setLocale |
| Methods inherited from class com.davisor.data.Type |
ceil, check, check, compare, create, create, create, create, create, dup, floor, format, getCompatibility, getDataName, getId, getID, getMetaData, getMetaData, getSpecs, getSQLName, getSQLName, getTypeName, isNull, parseObject, register, register, setDataName, setId, setID, setMetaData, setMetaData, setSpecs, toXML, xmlEnd, xmlStart |
| Methods inherited from class java.text.Format |
clone, format, formatToCharacterIterator, parseObject |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final java.lang.String TYPENAME
protected java.util.Map M_keys
protected java.util.Map M_additionalValues
| Constructor Detail |
public TupleType(TupleType tt)
public TupleType(java.lang.String dataName,
java.lang.String id,
java.lang.String format)
throws NoSuchTypeException
setFormat
method, but at that time it will not affect the number or type of
tuple members anymore.
The given specification string is broken into tuple members as
described by TupleFormat class documentation.
This is the constructor the SQL type mapper Type.create(Integer,String,String,String) method will call to
create a type that matches given SQL type.
dataName - data nameid - type identityformat - tuple member and format specification patternFormatType.getFormatter(),
createFormatter(),
setFormat(java.lang.String),
TupleFormat
public TupleType(java.lang.String dataName,
java.lang.String id,
java.text.MessageFormat formatter)
throws NoSuchTypeException
dataName - data nameid - type identityformatter - java message format
public TupleType(java.lang.String dataName,
java.lang.String id,
int size)
setType(int, com.davisor.data.Type)
method.
dataName - data nameid - type identitysize - number of tuple memberssetType(int, com.davisor.data.Type)
public TupleType(java.lang.String dataName,
java.lang.String id,
Type type)
dataName - data name (may ne null)id - type identity (may be null)type - first tuple member type (may be null)
public TupleType(java.lang.String dataName,
java.lang.String id,
Type type1,
Type type2)
dataName - data name (may be null)id - type identity (may be null)type1 - first tuple member type (may be null)type2 - second tuple member type (may be null)
public TupleType(java.lang.String dataName,
java.lang.String id,
Type type1,
Type type2,
Type type3)
dataName - data name (may be null)id - type identity (may be null)type1 - First tuple member type (may be null)type2 - Second tuple member type (may be null)type3 - Third tuple member type (may be null)
public TupleType(java.sql.ResultSet rs,
java.lang.String[] dataNames)
throws java.sql.SQLException
rs - result set column type and name informationdataNames - data names (may be null)
public TupleType(java.sql.ResultSet rs,
java.util.Map dataNames)
throws java.sql.SQLException
rs - result set column type and name informationdataNames - data names (may be null)
public TupleType(java.sql.ResultSetMetaData rsmd,
java.lang.String[] dataNames)
throws java.sql.SQLException
create method. Result set (unique) column
names are used to give (lowercase) identification strings to each
type. Type names, if given, are used name individual types. Type
names not explicitly given default to result set column names.
See class documentation for information about the differences between type identification strings and type names.
rsmd - result set column type and name informationdataNames - array that associates column indexes to type
names (may be null). Array indexes go from 0 to N-1, where N is
the number of database columns, corresponding to the SQL column
indexes 1 to N.
java.lang.ArrayIndexOutOfBoundsException - if the type name array exists
but does not have enough columns
java.sql.SQLException - if a SQL error occurs
public TupleType(java.sql.ResultSetMetaData rsmd,
java.util.Map dataNames)
throws java.sql.SQLException
create method. Result set (unique) column names
are used to give (lowercase) identification strings to each type.
Type names, if given, are used name individual types. Type names
not explicitly given default to result set column names.
See class documentation for information about the differences between type identification strings and type names.
rsmd - result set column type and name informationdataNames - map that associates column names with type names
(may be null)
java.sql.SQLException - if a SQL error occurs
protected TupleType(java.lang.String typeName,
java.lang.String dataName,
java.lang.String id,
java.util.Map metaData,
java.util.Locale locale,
java.lang.String pattern,
java.lang.Object sample,
Type[] types,
java.util.Map keys)
typeName - type namedataName - data nameid - type identitymetaData - type meta data map (may be null)locale - type locale (may be null)pattern - format pattern (may be null)sample - format sample (may be null)types - member typeskeys - member identitiesFormatType.setLocale(java.util.Locale),
FormatType.setPattern(java.lang.String),
FormatType.setSample(java.lang.Object)| Method Detail |
public com.davisor.core.Dupable dup()
dup in interface com.davisor.core.Dupabledup in class Typeprotected java.text.Format createFormatter()
TupleFormat instance from the current
pattern, locale, and additional value settings.
createFormatter in class FormatTypeFormatType.getFormatter(),
setAdditionalValues(java.util.Map),
FormatType.setFormat(Locale,String),
FormatType.setPattern(String),
setFormat(String),
TupleFormatpublic boolean equals(java.lang.Object o)
Tuple types are equal if their super-classes and member types are.
equals in interface java.util.Comparatorequals in class FormatTypeCompare.equals(Object,Object)public int hashCode()
hashCode in class FormatTypeCompare.hashCode(java.lang.Object)public java.lang.String toString()
toString in class TypeType.xmlEnd(),
Type.xmlStart(),
Strings.toXML(String,Object)public boolean containsKey(java.lang.String key)
true if this type contains an element for
the specified key.
public java.util.Map getAdditionalValues()
The returned value map is typically associated with the current tuple format, too, provided that the format is currently defined at all. Additional value maps may however be explicitly defined for tuple types and tuple formats alike, so it is also possible that these maps are different.
createFormatter(),
FormatType.getFormatter(),
setAdditionalValues(java.util.Map),
TupleData.get(Object,Map),
TupleFormat.getAdditionalValues()public int getMaxDepth()
public java.lang.String getId(int index)
throws NoSuchTypeException
getID(int)
NoSuchTypeException
public java.lang.String getID(int index)
throws NoSuchTypeException
NoSuchTypeException - if the given index does not match
any member.getType(int),
getIndex(java.lang.String),
setType(int, com.davisor.data.Type)
public int getIndex(java.lang.String memberId)
throws NoSuchTypeException
NoSuchTypeException - if the given id does not match any membergetID(int),
getType(int),
setType(int, com.davisor.data.Type)public int getSize()
public Type getType(int index)
null if the index did not match
any membergetID(int),
getType(java.lang.String),
setType(int, com.davisor.data.Type)
public Type getType(java.lang.String memberId)
throws NoSuchTypeException
NoSuchTypeException - if the given id does not match any member.getID(int),
getType(int),
setType(int, com.davisor.data.Type)
public int getTypeIndex(java.lang.String typeName)
throws NoSuchTypeException
NoSuchTypeException - if given name does not match any member.getTypeIndex(String,boolean[]),
getTypeIndexMap(com.davisor.data.TupleType)
public int getTypeIndex(Type type)
throws NoSuchTypeException
Two types match if they are considered equal by the source type
equals method. If this testing fails to find a
matching type, then the types are further matched according to
their general compatibility, as determined by the
getCompatibility method. In this case, a target type
matches the source type with the highest compatibility score. If
several source types give the same compatibility value, then the
first source type is used.
NoSuchTypeException - if the given type does not match
any member.getTypeIndex(Type,boolean [])
public int getTypeIndex(java.lang.String typeName,
boolean[] allocation)
throws NoSuchTypeException
The allocation map tells which tuple elements mapping have already been mapped. If a matching unallocated index is found, then the allocation map is updated to prevent reallocation.
typeName - the type name to be searched forallocation - allocation map of size equal to the size of this type
NoSuchTypeException - if the given name does not match
any member.getSize(),
getTypeIndex(java.lang.String),
getTypeIndexMap(com.davisor.data.TupleType)public int[] getTypeIndexes(java.lang.String typeName)
getTypeIndex(java.lang.String,boolean[]),
getTypeIndexMap(com.davisor.data.TupleType)
public int[] getTypeIndexes(java.lang.String typeName,
boolean[] allocation)
The allocation map tells which tuple elements mapping have already been mapped. If a matching unallocated index is found, then the allocation map is updated to prevent reallocation.
typeName - the type name to be searched forallocation - allocation map of size equal to the size of this typegetSize(),
getTypeIndex(java.lang.String),
getTypeIndexMap(com.davisor.data.TupleType)
public int getTypeIndex(Type templateType,
boolean[] allocation)
throws NoSuchTypeException
Two types match if they are considered equal by the source type
equals method. If, however, this testing fails to find
a matching type, then the types are further matched by their general
compatibility, as determined by the getCompatibility
method. In this case, a target type matches the source type
with the highest compatibility score. If several source types
give the same compatibility value, the first source type is used.
If an allocation map, which tells to which tuple elements the mapping already has been made, also has been given, then this information is used to prevent the same element to be mapped twice. If a new index is found, however, then the allocation map is updated.
templateType - type to be matched against members of this typeallocation - allocation map of size equal to the size of this type
NoSuchTypeException - if the given type does not match
any member.getSize(),
getTypeIndex(Type,boolean [])public int[] getTypeIndexMap(TupleType templateType)
map[n] tells, which element of the given
tuple that would match element n in this tuple. A
negative value indicates that there was no match.
Mapping is based on type names only, not type equality or general compatibility. Operations that assign elements in this tuple to the elements of the target tuple are expected to arrange suitable type conversions.
The primary use for the returned map is re-arrange tuple data
objects of the given type to tuple data objects of this
type. Please see the rearrange method for more
information.
getTypeIndex(java.lang.String),
rearrange(com.davisor.data.TupleData, int[])public boolean isNumber(int index)
NumberType instance.
TupleData.isNumber(int)public java.util.Set keySet()
public TupleData rearrange(TupleData data,
int[] map)
throws InvalidDataException
Data members matching target types are not copied, only their references are. Other members are converted to their respective target types.
data - the tuple to re-arrangemap - a type index map from this tuple type to the given another type
InvalidDataException - if 'value' is not valid for the
given channelgetTypeIndexMap(com.davisor.data.TupleType),
TupleData.setValue(int,Object)public void setAdditionalValues(java.util.Map additionalValues)
TupleFormat, the new additional
values are set for it, too.
FormatType.getFormatter(),
getAdditionalValues(),
TupleData.get(Object,Map),
TupleFormat.setAdditionalValues(java.util.Map)
public void setType(int index,
Type type)
Member identity is taken from given type. If some other member already has an identity equal to the new member, the old member is removed first, even if it would have a different member index.
index - the index of the new member typetype - the new member type (may be null)public java.lang.String getFormat()
TupleFormat class description.
getFormat in class FormatTypesetFormat(java.lang.String)public int getSQLCode()
getSQLCode in class Typepublic java.lang.Class getValueClass()
getValueClass in class FormatTypepublic void setFormat(java.lang.String format)
TupleFormat class description. The specification string is set
to be the pattern of the tuple type. The locale of the tuple type
is set to null.
After the setting of the pattern and locale, the current format
is cleared with a call to FormatType.clearFormatter().
setFormat in class FormatTypeformat - type specification string (may be empty of
null)getFormat(),
TupleFormat
public DataValue toData(java.sql.CallableStatement statement,
int column)
throws InvalidDataException,
java.sql.SQLException
Tuple type first selects a member type corresponding the given SQL column, and then uses the member type to interprete the column value as data value. Tuple members N correspond to SQL columns N+1, as SQL column indexes start from one, while tuple member indexes start from zero.
If either the column value or corresponding member type are missing,
null data value is returned.
toData in class Typestatement - statement holding the data value to be convertedcolumn - SQL column index for the data value to be converted
InvalidDataException - if given object value could not be parsed
java.sql.SQLException - if a SQL error occurstoData(Object),
toData(ResultSet,int),
toData(String,ParsePosition)
public DataValue toData(java.lang.Object value)
throws InvalidDataException
TupleData, it's type is first compared
to this type. If the type is equal to this type, the tuple is
returned unmodified. Otherwise a new TupleData
object of this type is created, and the members of given tuple
are mapped to it by their name, as described by the
getTypeIndex(String,boolean[]) method. Note, that
this may leave some source members unmapped, and some target
members empty.
If the given object is not an instance of TupleData,
the string representation of the object is passed to the
toData method that converts strings to data objects.
If the given object is null, a new, empty tuple
instance of this type is created and returned.
toData in class Typevalue - an object to be converted to a data value
InvalidDataException - if the conversion failstoData(String,ParsePosition),
getTypeIndex(String,boolean[])
public DataValue toData(java.lang.String stringValue,
java.text.ParsePosition status)
throws InvalidDataException
Tuple type expects the given value to contain data string values,
compatible with current message pattern, and returns a corresponding
TupleData value.
toData in class TypestringValue - data stringstatus - parse status (may be null)
InvalidDataException - if given string value could not be parsedtoData(CallableStatement,int),
toData(Object),
toData(ResultSet,int),
TupleData
public DataValue toData(java.sql.ResultSet resultSet,
int column)
throws InvalidDataException,
java.sql.SQLException
Tuple type first selects a member type corresponding the given SQL column, and then uses the member type to interprete the column value as data value. Tuple members N correspond to SQL columns N+1, as SQL column indexes start from one, while tuple member indexes start from zero.
If either the column value or corresponding member type are missing,
null data value is returned.
toData in class TyperesultSet - resultSet holding the data value to be convertedcolumn - SQL column index for the data value to be converted
InvalidDataException - if given object value could not be parsed
java.sql.SQLException - if a SQL error occurstoData(CallableStatement,int),
toData(Object),
toData(String,ParsePosition)public DataValue zero()
zero in class TypeTupleData object sharing this typeDataValue.deinterpolate(com.davisor.data.DataValue, com.davisor.data.DataValue),
DataValue.interpolate(double, com.davisor.data.DataValue)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||