Class Map<K,V>
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.vilTypes.Map<K,V>
-
- Type Parameters:
K- the key type of the mapV- the value type of the map
- All Implemented Interfaces:
IStringValueProvider,IVilGenericType,IVilType
- Direct Known Subclasses:
UnmodifiableMap
public class Map<K,V> extends java.lang.Object implements IVilGenericType, IStringValueProvider
Defines the VIL type "Map".- Author:
- Holger Eichelberger
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider
IStringValueProvider.StringComparator
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Map<?,?>DEFAULTprivate TypeDescriptor<?>[]genericsprivate java.util.Map<java.lang.Object,java.lang.Object>mapprivate TypeDescriptor<?>type
-
Constructor Summary
Constructors Constructor Description Map(java.util.Map<java.lang.Object,java.lang.Object> map, TypeDescriptor<?>[] generics)Creates a map wrapper.Map(TypeDescriptor<?>[] types)Creates a new map.Map(TypeDescriptor<?>[] types, int size)Creates a new map.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.Object key, V value)Adds a key-value pair to this map and overrides existing mappings.Vat(java.lang.Object key)Returns the value assigned tokey.static java.lang.ObjectcheckConvertEmpty(TypeDescriptor<?> type, java.lang.Object value)Convertsvalueto an empty map with parameter types fromtype, iftypeis a map andvalueis an empty map instance.voidclear()Clears all entries.Map<K,V>cloneMap()Clones this map.booleancontainsKey(java.lang.Object key)Returns whether this map contains a mapping for the givenkey.static Map<?,?>convert(Sequence<?> sequence)Converts the given sequence into a map.booleanequals(java.lang.Object object)Vget(java.lang.Object key)Returns the value assigned tokey.Vget(java.lang.Object key, V deflt)Returns the value assigned tokey, if there is nonedeflt.intgetDimensionCount()Returns the number of dimensions ofT.TypeDescriptor<?>getDimensionType(int index)Returns the type of the specified dimension ofT.Set<K>getKeys()Returns the keys of this map.VgetOrAdd(java.lang.Object key, V deflt)Returns the value assigned tokey, if there is none it associateskeywithdeflt, i.e., addsdeflt.intgetSize()Returns the size of the map.static java.lang.StringgetStringValue(java.util.Map<?,?> map, IStringValueProvider.StringComparator comparator)Returns the string value of the givenmap.java.lang.StringgetStringValue(IStringValueProvider.StringComparator comparator)Returns the string value of this object.TypeDescriptor<?>getType()Returns the actual type including generics.Set<V>getValues()Returns the values of this map.inthashCode()private static booleanisAny(TypeDescriptor<?> type)Returns whethertypeis Any.private static booleanisAnyMap(Map<?,?> map)Returns whethermapis anmap. booleanisEmpty()Returns whether the map is empty.Set<K>keys()Returns the keys of this map.booleannotEmpty()Returns whether the map is not empty.voidput(java.lang.Object key, V value)Adds a key-value pair to this map and overrides existing mappings.voidremove(java.lang.Object key)Removes the givenkeyfrom the map.Sequence<V>sortByKeys(ExpressionEvaluator evaluator)Sorts values in this map according to keys.java.util.Map<java.lang.Object,java.lang.Object>toMap()Converts back to a map for utilizing this with external classes.java.util.Map<K,V>toMappedMap()Translates this VIL map to a Java map.java.lang.StringtoString()Set<V>values()Returns the values of this map.
-
-
-
Field Detail
-
DEFAULT
public static final java.util.Map<?,?> DEFAULT
-
map
private java.util.Map<java.lang.Object,java.lang.Object> map
-
generics
private TypeDescriptor<?>[] generics
-
type
private TypeDescriptor<?> type
-
-
Constructor Detail
-
Map
Map(TypeDescriptor<?>[] types)
Creates a new map.- Parameters:
types- the parameter types of this map
-
Map
Map(TypeDescriptor<?>[] types, int size)
Creates a new map.- Parameters:
types- the parameter types of this mapsize- the initial size of this map
-
Map
public Map(java.util.Map<java.lang.Object,java.lang.Object> map, TypeDescriptor<?>[] generics)Creates a map wrapper.- Parameters:
map- the map to be wrappedgenerics- the generic types inmap
-
-
Method Detail
-
at
public V at(java.lang.Object key)
Returns the value assigned tokey.- Parameters:
key- the key to search the value for- Returns:
- the value for key (may be null)
-
containsKey
public boolean containsKey(java.lang.Object key)
Returns whether this map contains a mapping for the givenkey.- Parameters:
key- the key to search for- Returns:
trueif key is included,falseelse
-
get
public V get(java.lang.Object key)
Returns the value assigned tokey.- Parameters:
key- the key to search the value for- Returns:
- the value for key (may be null)
-
get
public V get(java.lang.Object key, V deflt)
Returns the value assigned tokey, if there is nonedeflt.- Parameters:
key- the key to search the value fordeflt- the default value ifkeydoes not exist- Returns:
- the value for key (
defltif no key-value mapping is defined)
-
getOrAdd
public V getOrAdd(java.lang.Object key, V deflt)
Returns the value assigned tokey, if there is none it associateskeywithdeflt, i.e., addsdeflt.- Parameters:
key- the key to search the value fordeflt- the default value ifkeydoes not exist, a key-value mapping will be added- Returns:
- the value for key (
defltif no key-value mapping is defined)
-
add
public void add(java.lang.Object key, V value)Adds a key-value pair to this map and overrides existing mappings.- Parameters:
key- the key for the mapping (null is ignored)value- the value of the mapping
-
put
public void put(java.lang.Object key, V value)Adds a key-value pair to this map and overrides existing mappings.- Parameters:
key- the key for the mapping (null is ignored)value- the value of the mapping
-
isAnyMap
private static final boolean isAnyMap(Map<?,?> map)
Returns whethermapis anmap. - Parameters:
map- the map to test- Returns:
trueif it is anmap, falseelse
-
isAny
private static final boolean isAny(TypeDescriptor<?> type)
Returns whethertypeis Any.- Parameters:
type- the type to test- Returns:
trueiftypeis Any,falseelse
-
remove
public void remove(java.lang.Object key)
Removes the givenkeyfrom the map.- Parameters:
key- the key to be removed
-
clear
public void clear()
Clears all entries.
-
getDimensionCount
public int getDimensionCount()
Returns the number of dimensions ofT.- Returns:
- the number of dimensions
-
getType
public TypeDescriptor<?> getType()
Description copied from interface:IVilGenericTypeReturns the actual type including generics. "Overrides"PseudoAny.getType(Object).- Specified by:
getTypein interfaceIVilGenericType- Returns:
- the actual type
-
getSize
public int getSize()
Returns the size of the map.- Returns:
- the size of the map
-
getDimensionType
public TypeDescriptor<?> getDimensionType(int index)
Returns the type of the specified dimension ofT.- Parameters:
index- the 0-based index of the dimension- Returns:
- the actual type of the dimension
-
convert
public static Map<?,?> convert(Sequence<?> sequence) throws VilException
Converts the given sequence into a map.- Parameters:
sequence- the sequence to be converted- Returns:
- the resulting map
- Throws:
VilException- in case that types or dimensions cannot be converted
-
getStringValue
public java.lang.String getStringValue(IStringValueProvider.StringComparator comparator)
Description copied from interface:IStringValueProviderReturns the string value of this object.- Specified by:
getStringValuein interfaceIStringValueProvider- Parameters:
comparator- if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned- Returns:
- the string value
-
getStringValue
public static java.lang.String getStringValue(java.util.Map<?,?> map, IStringValueProvider.StringComparator comparator)Returns the string value of the givenmap.- Parameters:
map- the map to be turned into a Stringcomparator- if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned- Returns:
- the string value
-
checkConvertEmpty
public static java.lang.Object checkConvertEmpty(TypeDescriptor<?> type, java.lang.Object value)
Convertsvalueto an empty map with parameter types fromtype, iftypeis a map andvalueis an empty map instance. This is needed for initialization.- Parameters:
type- the (target) type to be checkedvalue- the value to be checked- Returns:
valueor an empty map of the given types
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toMap
public java.util.Map<java.lang.Object,java.lang.Object> toMap()
Converts back to a map for utilizing this with external classes.- Returns:
- the internal map
-
sortByKeys
public Sequence<V> sortByKeys(ExpressionEvaluator evaluator) throws VilException
Sorts values in this map according to keys.- Parameters:
evaluator- the evaluator- Returns:
- the map values sorted according to the keys
- Throws:
VilException- in case that evaluating fails
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toMappedMap
public java.util.Map<K,V> toMappedMap()
Translates this VIL map to a Java map.- Returns:
- the translated map
-
isEmpty
public boolean isEmpty()
Returns whether the map is empty.- Returns:
truefor empty,falseelse
-
notEmpty
public boolean notEmpty()
Returns whether the map is not empty.- Returns:
falsefor empty,trueelse
-
-