public final class HDF5CompoundMemberMapping
extends java.lang.Object
Example on how to use:
static class Record { int i; String s; HDF5EnumerationValue e; Record(int i, String s, HDF5EnumerationValue e) { this.i = i; this.e = e; this.s = s; } Record() { } static HDF5CompoundType<Record> getHDF5Type(HDF5Reader reader) { final HDF5EnumerationType enumType = reader.getEnumType("someEnumType", new String[] { "1", "Two", "THREE" }); return reader.getCompoundType(Record.class, mapping("i"), mapping("s", 20), mapping("e", enumType)); } } ... final HDF5Writer writer = new HDF5Writer(new File("test.h5").open(); final HDF5CompoundType<Record> compoundType = Record.getHDF5Type(writer); final HDF5EnumerationType enumType = writer.getEnumType("someEnumType"); Record[] array = new Record[] { new Record(1, "some text", new HDF5EnumerationValue(enumType, "THREE")), new Record(2, "some note", new HDF5EnumerationValue(enumType, "1")), }; writer.writeCompound("/testCompound", compoundType, recordWritten); writer.close();A simpler form is to let JHDF5 infer the mapping between fields in the Java object and members of the compound data type, see
inferMapping(Class)
and inferMapping(Class, Map)
Modifier and Type | Method and Description |
---|---|
static HDF5CompoundMemberMapping[] |
addHints(HDF5CompoundMemberMapping[] mapping,
HDF5CompoundMappingHints hintsOrNull)
Adds the given hintsOrNull to all mapping.
|
static java.lang.String |
constructCompoundTypeName(java.util.Collection<java.lang.String> memberNames,
boolean sort)
Infers a name for a compound type from the given memberNames by concatenating
them.
|
HDF5CompoundMemberMapping |
dimensions(int[] memberTypeDimensions)
Sets the dimensions of the member type to use for the mapping.
|
HDF5CompoundMemberMapping |
dimensions(int memberTypeDimensionX,
int memberTypeDimensionY)
Sets the dimensions of the member type to use for the mapping.
|
HDF5CompoundMemberMapping |
enumType(HDF5EnumerationType enumType)
Sets the enumeration type to use for the mapping.
|
HDF5CompoundMemberMapping |
enumTypeName(java.lang.String enumTypeName)
Sets the name to be used for the comitted HDF5 datatype (for Java enum types only, overriding
the simple class name which is used by default as the type name.
|
HDF5CompoundMemberMapping |
fieldName(java.lang.String fieldName)
Sets the field name in the Java class to use for the mapping, overriding the member name
which is used by default to find the field.
|
HDF5CompoundMemberMapping |
hints(HDF5CompoundMappingHints hints)
Sets mapping hints for this mapping.
|
static <T> java.util.Map<java.lang.String,HDF5EnumerationType> |
inferEnumerationTypeMap(T pojo,
IHDF5EnumTypeRetriever enumTypeRetriever)
Infers the map from field names to
HDF5EnumerationType s for the given pojo
object. |
static HDF5CompoundMemberMapping[] |
inferMapping(java.lang.Class<?> pojoClass)
Returns the inferred compound member mapping for the given pojoClass.
|
static HDF5CompoundMemberMapping[] |
inferMapping(java.lang.Class<?> pojoClass,
HDF5CompoundMappingHints hintsOrNull)
Returns the inferred compound member mapping for the given pojoClass.
|
static HDF5CompoundMemberMapping[] |
inferMapping(java.lang.Class<?> pojoClass,
java.util.Map<java.lang.String,HDF5EnumerationType> fieldNameToEnumTypeMapOrNull)
Returns the inferred compound member mapping for the given pojoClass.
|
static HDF5CompoundMemberMapping[] |
inferMapping(java.util.List<java.lang.String> memberNames,
java.util.List<?> memberValues)
Returns the inferred compound member mapping for the given memberNames and
memberValues.
|
static HDF5CompoundMemberMapping[] |
inferMapping(java.util.List<java.lang.String> memberNames,
java.util.List<?> memberValues,
HDF5CompoundMappingHints hintsOrNull)
Returns the inferred compound member mapping for the given memberNames and
memberValues.
|
static HDF5CompoundMemberMapping[] |
inferMapping(java.util.Map<java.lang.String,java.lang.Object> compoundMap)
Returns the inferred compound member mapping for the given compoundMap.
|
static HDF5CompoundMemberMapping[] |
inferMapping(java.util.Map<java.lang.String,java.lang.Object> compoundMap,
HDF5CompoundMappingHints hintsOrNull)
Returns the inferred compound member mapping for the given compoundMap.
|
static HDF5CompoundMemberMapping[] |
inferMapping(java.lang.Object[] pojo,
java.util.Map<java.lang.String,HDF5EnumerationType> fieldNameToEnumTypeMapOrNull)
This method is using pojo to infer length and dimension information.
|
static HDF5CompoundMemberMapping[] |
inferMapping(java.lang.Object[] pojo,
java.util.Map<java.lang.String,HDF5EnumerationType> fieldNameToEnumTypeMapOrNull,
boolean useVariableLengthStringTypes)
This method is using pojo to infer length and dimension information.
|
static HDF5CompoundMemberMapping[] |
inferMapping(java.lang.Object pojo,
java.util.Map<java.lang.String,HDF5EnumerationType> fieldNameToEnumTypeMapOrNull) |
static HDF5CompoundMemberMapping[] |
inferMapping(java.lang.Object pojo,
java.util.Map<java.lang.String,HDF5EnumerationType> fieldNameToEnumTypeMapOrNull,
boolean useVariableLengthStringTypes)
This method is using pojo to infer length and dimension information.
|
static HDF5CompoundMemberMapping[] |
inferMapping(java.lang.String[] memberNames,
java.lang.Object[] memberValues)
Returns the inferred compound member mapping for the given memberNames and
memberValues.
|
static HDF5CompoundMemberMapping[] |
inferMapping(java.lang.String[] memberNames,
java.lang.Object[] memberValues,
HDF5CompoundMappingHints hints)
Returns the inferred compound member mapping for the given memberNames and
memberValues.
|
boolean |
isReference()
Returns
true if this field should be mapped to a refernce type. |
boolean |
isVariableLength()
Returns
true if this field should be mapped to a variable-length string. |
HDF5CompoundMemberMapping |
length(int memberTypeLength)
Sets the length of the member type to use for the mapping.
|
static HDF5CompoundMemberMapping |
mapping(java.lang.String memberName)
Adds a member mapping for memberName.
|
HDF5CompoundMemberMapping |
memberClass(java.lang.Class<?> memberClass)
Sets the member class to use for the mapping.
|
HDF5CompoundMemberMapping |
reference()
Sets this field to a reference type.
|
HDF5CompoundMemberMapping |
reference(boolean reference)
Sets this field to a reference type, if reference is
true . |
java.lang.Class<?> |
tryGetMemberClass() |
HDF5CompoundMemberMapping |
typeVariant(HDF5DataTypeVariant typeVariant)
Sets the data type variant to use for the mapping.
|
HDF5CompoundMemberMapping |
unsigned()
Sets this field to an unsigned type.
|
HDF5CompoundMemberMapping |
unsigned(boolean unsigned)
Sets this field to an unsigned type, if unsigned is
true . |
HDF5CompoundMemberMapping |
variableLength()
Sets this field to a variable-length type.
|
HDF5CompoundMemberMapping |
variableLength(boolean variableLength)
Sets this field to a variable-length type, if variableLength is
true . |
public static HDF5CompoundMemberMapping mapping(java.lang.String memberName)
memberName
- The name of the member in the compound type. field in the Java class. Will
also be used to find the name of the field in the Java class if not overridden by
fieldName(String)
.public static HDF5CompoundMemberMapping[] inferMapping(java.lang.Class<?> pojoClass)
CompoundType
and CompoundElement
.
Note 1: All fields that correspond to members with a variable length (e.g. Strings,
primitive arrays and matrices and objects of type MDXXXArray
) need to be
annotated with CompoundElement
specifying their dimensions using
CompoundElement.dimensions()
. .
Note 2: pojoClass containing HDF5 enumerations cannot have their mapping inferred as the HDF5 enumeration type needs to be explicitly specified in the mapping.
Example 1:
class Record1 { @CompoundElement(dimension = 10) String s; float f; }will lead to:
inferMapping(Record1.class) -> { mapping("s", 10), mapping("f") }Example 2:
@CompoundType(mapAllFields = false) class Record2 { @CompoundElement(memberName = "someString", dimension = 10) String s; float f; }will lead to:
inferMapping(Record2.class) -> { mapping("s", "someString", 10) }
public static HDF5CompoundMemberMapping[] inferMapping(java.lang.Class<?> pojoClass, java.util.Map<java.lang.String,HDF5EnumerationType> fieldNameToEnumTypeMapOrNull)
CompoundType
and CompoundElement
.
Note 1: All fields that correspond to members with a dimension (e.g. Strings,
primitive arrays and matrices and objects of type MDXXXArray
) need to be
annotated with CompoundElement
specifying their dimensions using
CompoundElement.dimensions()
. Strings can alternatively also be annotated as
CompoundElement.variableLength = true
.
Note 2: pojoClass containing HDF5 enumerations need to have their
HDF5EnumerationType
specified in the fieldNameToEnumTypeMapOrNull. You may
use inferEnumerationTypeMap(Object, IHDF5EnumTypeRetriever)
to create
fieldNameToEnumTypeMapOrNull.
Example 1:
class Record1 { @CompoundElement(dimension = 10) String s; float f; }will lead to:
inferMapping(Record1.class) -> { mapping("s", 10), mapping("f") }Example 2:
@CompoundType(mapAllFields = false) class Record2 { @CompoundElement(memberName = "someString", dimension = 10) String s; float f; }will lead to:
inferMapping(Record2.class) -> { mapping("s", "someString", 10) }
public static HDF5CompoundMemberMapping[] inferMapping(java.lang.Class<?> pojoClass, HDF5CompoundMappingHints hintsOrNull)
CompoundType
and CompoundElement
.
Note 1: All fields that correspond to members with a dimension (e.g. Strings,
primitive arrays and matrices and objects of type MDXXXArray
) need to be
annotated with CompoundElement
specifying their dimensions using
CompoundElement.dimensions()
. Strings can alternatively also be annotated as
CompoundElement.variableLength = true
.
Note 2: pojoClass containing HDF5 enumerations need to have their
HDF5EnumerationType
specified in the fieldNameToEnumTypeMapOrNull. You may
use inferEnumerationTypeMap(Object, IHDF5EnumTypeRetriever)
to create
fieldNameToEnumTypeMapOrNull.
Example 1:
class Record1 { @CompoundElement(dimension = 10) String s; float f; }will lead to:
inferMapping(Record1.class) -> { mapping("s", 10), mapping("f") }Example 2:
@CompoundType(mapAllFields = false) class Record2 { @CompoundElement(memberName = "someString", dimension = 10) String s; float f; }will lead to:
inferMapping(Record2.class) -> { mapping("s", "someString", 10) }
public static HDF5CompoundMemberMapping[] inferMapping(java.lang.Object pojo, java.util.Map<java.lang.String,HDF5EnumerationType> fieldNameToEnumTypeMapOrNull)
public static HDF5CompoundMemberMapping[] inferMapping(java.lang.Object pojo, java.util.Map<java.lang.String,HDF5EnumerationType> fieldNameToEnumTypeMapOrNull, boolean useVariableLengthStringTypes)
pojo
- The popo to infer member names, length and dimension information from.fieldNameToEnumTypeMapOrNull
- The map to get member name to enumeration type mapping
from.useVariableLengthStringTypes
- If true
, use variable-length string types
for all strings in the pojo template.
public static HDF5CompoundMemberMapping[] inferMapping(java.lang.Object[] pojo, java.util.Map<java.lang.String,HDF5EnumerationType> fieldNameToEnumTypeMapOrNull)
public static HDF5CompoundMemberMapping[] inferMapping(java.lang.Object[] pojo, java.util.Map<java.lang.String,HDF5EnumerationType> fieldNameToEnumTypeMapOrNull, boolean useVariableLengthStringTypes)
pojo
- The popo arrau to infer member names, length and dimension information from.fieldNameToEnumTypeMapOrNull
- The map to get member name to enumeration type mapping
from.useVariableLengthStringTypes
- If true
, use variable-length string types
for all strings in the pojo template.
public static HDF5CompoundMemberMapping[] addHints(HDF5CompoundMemberMapping[] mapping, HDF5CompoundMappingHints hintsOrNull)
public static HDF5CompoundMemberMapping[] inferMapping(java.util.Map<java.lang.String,java.lang.Object> compoundMap)
Example:
Map<String, Object> mw = new HashMap<String, Object>(); mw.put("date", new Date()); mw.put("temperatureInDegreeCelsius", 19.5f); mw.put("voltagesInMilliVolts", new double[][] { 1, 2, 3 }, { 4, 5, 6 } });will lead to:
inferMapping(mw) -> { mapping("date").memberClass(Date.class), mapping("temperatureInDegreeCelsius").memberClass(float.class), mapping("voltagesInMilliVolts").memberClass(double[][].class).dimensions(new int[] { 3, 3 } }
public static HDF5CompoundMemberMapping[] inferMapping(java.util.Map<java.lang.String,java.lang.Object> compoundMap, HDF5CompoundMappingHints hintsOrNull)
Example:
Map<String, Object> mw = new HashMap<String, Object>(); mw.put("date", new Date()); mw.put("temperatureInDegreeCelsius", 19.5f); mw.put("voltagesInMilliVolts", new double[][] { 1, 2, 3 }, { 4, 5, 6 } });will lead to:
inferMapping(mw) -> { mapping("date").memberClass(Date.class), mapping("temperatureInDegreeCelsius").memberClass(float.class), mapping("voltagesInMilliVolts").memberClass(double[][].class).dimensions(new int[] { 3, 3 } }
public static HDF5CompoundMemberMapping[] inferMapping(java.util.List<java.lang.String> memberNames, java.util.List<?> memberValues)
Example:
List<String> n = Arrays.asList("date", "temperatureInDegreeCelsius", "voltagesInMilliVolts"); List<Object> l = Arrays. <Object>asList(new Date(), 19.5f, new double[][] { 1, 2, 3 }, { 4, 5, 6 } });will lead to:
inferMapping(n, l) -> { mapping("date").memberClass(Date.class), mapping("temperatureInDegreeCelsius").memberClass(float.class), mapping("voltagesInMilliVolts").memberClass(double[][].class).dimensions(new int[] { 3, 3 } }
public static HDF5CompoundMemberMapping[] inferMapping(java.util.List<java.lang.String> memberNames, java.util.List<?> memberValues, HDF5CompoundMappingHints hintsOrNull)
Example:
List<String> n = Arrays.asList("date", "temperatureInDegreeCelsius", "voltagesInMilliVolts"); List<Object> l = Arrays. <Object>asList(new Date(), 19.5f, new double[][] { 1, 2, 3 }, { 4, 5, 6 } });will lead to:
inferMapping(n, l) -> { mapping("date").memberClass(Date.class), mapping("temperatureInDegreeCelsius").memberClass(float.class), mapping("voltagesInMilliVolts").memberClass(double[][].class).dimensions(new int[] { 3, 3 } }
public static HDF5CompoundMemberMapping[] inferMapping(java.lang.String[] memberNames, java.lang.Object[] memberValues)
Example:
String[] n = new String[] { "date", "temperatureInDegreeCelsius", "voltagesInMilliVolts" }; Object[] l = new Object[] { new Date(), 19.5f, new double[][] { 1, 2, 3 }, { 4, 5, 6 } } };will lead to:
inferMapping(n, l) -> { mapping("date").memberClass(Date.class), mapping("temperatureInDegreeCelsius").memberClass(float.class), mapping("voltagesInMilliVolts").memberClass(double[][].class).dimensions(new int[] { 3, 3 } }
public static HDF5CompoundMemberMapping[] inferMapping(java.lang.String[] memberNames, java.lang.Object[] memberValues, HDF5CompoundMappingHints hints)
Example:
String[] n = new String[] { "date", "temperatureInDegreeCelsius", "voltagesInMilliVolts" }; Object[] l = new Object[] { new Date(), 19.5f, new double[][] { 1, 2, 3 }, { 4, 5, 6 } } };will lead to:
inferMapping(n, l) -> { mapping("date").memberClass(Date.class), mapping("temperatureInDegreeCelsius").memberClass(float.class), mapping("voltagesInMilliVolts").memberClass(double[][].class).dimensions(new int[] { 3, 3 } }
public static java.lang.String constructCompoundTypeName(java.util.Collection<java.lang.String> memberNames, boolean sort)
memberNames
- The names of the members to use to build the compound type name from.sort
- If true
, the names will be sorted before they are concatenated.public static <T> java.util.Map<java.lang.String,HDF5EnumerationType> inferEnumerationTypeMap(T pojo, IHDF5EnumTypeRetriever enumTypeRetriever)
HDF5EnumerationType
s for the given pojo
object.public HDF5CompoundMemberMapping fieldName(java.lang.String fieldName)
public HDF5CompoundMemberMapping enumTypeName(java.lang.String enumTypeName)
public HDF5CompoundMemberMapping memberClass(java.lang.Class<?> memberClass)
public java.lang.Class<?> tryGetMemberClass()
public HDF5CompoundMemberMapping length(int memberTypeLength)
dimensions(int[])
for array members of
rank 1.public HDF5CompoundMemberMapping dimensions(int memberTypeDimensionX, int memberTypeDimensionY)
dimensions(int[])
for array members of rank 2.public HDF5CompoundMemberMapping dimensions(int[] memberTypeDimensions)
public HDF5CompoundMemberMapping unsigned()
public HDF5CompoundMemberMapping unsigned(boolean unsigned)
true
. Must be an
integer.public HDF5CompoundMemberMapping variableLength()
public HDF5CompoundMemberMapping variableLength(boolean variableLength)
true
.
Must be a string.public boolean isVariableLength()
true
if this field should be mapped to a variable-length string.public HDF5CompoundMemberMapping reference()
public HDF5CompoundMemberMapping reference(boolean reference)
true
. Must be a
string.public boolean isReference()
true
if this field should be mapped to a refernce type.public HDF5CompoundMemberMapping hints(HDF5CompoundMappingHints hints)
public HDF5CompoundMemberMapping enumType(HDF5EnumerationType enumType)
public HDF5CompoundMemberMapping typeVariant(HDF5DataTypeVariant typeVariant)