public final class StructUtils extends java.lang.Object
StructUtils.StructEntry
.
Those fields will be respected when converting an object to a Map
and back.Modifier and Type | Class and Description |
---|---|
static interface |
StructUtils.StructEntry
Annotation used for converting objects to String Maps and vice versa.
|
static interface |
StructUtils.WriteExplicitly
Annotation used for converting objects to String Maps.
|
Modifier | Constructor and Description |
---|---|
private |
StructUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
deserializeStruct(java.util.Map<java.lang.String,java.lang.String> hash,
java.lang.Class<T> klass)
Converts a String-Map to an object of a certain class, by comparing map keys to field names of the class and assigning
map values to the corresponding fields.
|
static <T> java.util.List<T> |
getListOfStructs(IPreferences preferences,
java.lang.String key,
java.lang.Class<T> klass)
Get a list of hashes which are represented by a struct-like class.
|
static <T> java.util.List<T> |
getListOfStructs(IPreferences preferences,
java.lang.String key,
java.util.Collection<T> def,
java.lang.Class<T> klass)
same as above, but returns def if nothing was found
|
private static java.util.Map |
mapFromJson(java.lang.String s) |
private static java.lang.String |
mapToJson(java.util.Map map) |
private static MultiMap |
multiMapFromJson(java.lang.String s) |
private static java.lang.String |
multiMapToJson(MultiMap map) |
static <T> boolean |
putListOfStructs(IPreferences preferences,
java.lang.String key,
java.util.Collection<T> val,
java.lang.Class<T> klass)
Convenience method that saves a MapListSetting which is provided as a collection of objects.
|
private static <T> java.util.List<java.util.Map<java.lang.String,java.lang.String>> |
serializeListOfStructs(java.util.Collection<T> l,
java.lang.Class<T> klass) |
static <T> java.util.HashMap<java.lang.String,java.lang.String> |
serializeStruct(T struct,
java.lang.Class<T> klass)
Convert an object to a String Map, by using field names and values as map key and value.
|
private StructUtils()
public static <T> java.util.List<T> getListOfStructs(IPreferences preferences, java.lang.String key, java.lang.Class<T> klass)
T
- klass typepreferences
- preferences to look up the valuekey
- main preference keyklass
- The struct classpublic static <T> java.util.List<T> getListOfStructs(IPreferences preferences, java.lang.String key, java.util.Collection<T> def, java.lang.Class<T> klass)
T
- klass typepreferences
- preferences to look up the valuekey
- main preference keydef
- default valueklass
- The struct classdef
if nothing was foundpublic static <T> boolean putListOfStructs(IPreferences preferences, java.lang.String key, java.util.Collection<T> val, java.lang.Class<T> klass)
Map<String, String>
using the fields with StructUtils.StructEntry
annotation.
The field name is the key and the value will be converted to a string.
Considers only fields that have the @StructEntry
annotation.
In addition it does not write fields with null values. (Thus they are cleared)
Default values are given by the field values after default constructor has been called.
Fields equal to the default value are not written unless the field has the StructUtils.WriteExplicitly
annotation.T
- the class,preferences
- the preferences to save tokey
- main preference keyval
- the list that is supposed to be savedklass
- The struct classprivate static <T> java.util.List<java.util.Map<java.lang.String,java.lang.String>> serializeListOfStructs(java.util.Collection<T> l, java.lang.Class<T> klass)
public static <T> java.util.HashMap<java.lang.String,java.lang.String> serializeStruct(T struct, java.lang.Class<T> klass)
StructUtils.StructEntry
are taken into account.
Fields will not be written to the map if the value is null or unchanged
(compared to an object created with the no-arg-constructor).
The StructUtils.WriteExplicitly
annotation overrides this behavior, i.e. the default value will also be written.T
- the class of the object struct
struct
- the object to be convertedklass
- the class Tstruct
)public static <T> T deserializeStruct(java.util.Map<java.lang.String,java.lang.String> hash, java.lang.Class<T> klass)
StructUtils.StructEntry
are taken into account.T
- the classhash
- the string map with initial valuesklass
- the class Tprivate static java.lang.String mapToJson(java.util.Map map)
private static java.util.Map mapFromJson(java.lang.String s)
private static java.lang.String multiMapToJson(MultiMap map)
private static MultiMap multiMapFromJson(java.lang.String s)