Package org.openjdk.jmc.common.unit
Class MutableConstrainedMap<K>
- java.lang.Object
-
- org.openjdk.jmc.common.unit.MutableConstrainedMap<K>
-
- Type Parameters:
K- the type of the keys in the map
- All Implemented Interfaces:
IConstrainedMap<K>,IMutableConstrainedMap<K>
- Direct Known Subclasses:
SimpleConstrainedMap
public abstract class MutableConstrainedMap<K> extends Object implements IMutableConstrainedMap<K>
A mutable extension toIConstrainedMap. Note that it is the values that can be mutated. Existing constraints cannot be modified. However, some implementations may allow adding constraints for keys that currently doesn't have a constraint, and thus no current value.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMutableConstrainedMap()protectedMutableConstrainedMap(HashMap<K,Object> values)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddConstraint(K key, IConstraint<?> constraint)Objectget(K key)Get the mapped value forkey, or null if no value is currently mapped.abstract IConstraint<?>getConstraint(K key)StringgetPersistableString(K key)Get the persistable string of the mapped value forkey, or null if no value is currently mapped.protected IConstraint<?>getSuggestedConstraint(K key)This method will only be called for keys for whichgetConstraint(Object)currently returns null for.Set<K>keySet()voidput(K key, Object value)Mapkeytovalue, if allowed according to either an existingconstraintor an implicit default constraint, if available.<T> voidput(K key, IConstraint<T> constraint, T value)Mapkeytovalue, if allowed according toconstraintand additional restrictions on this map such as a conflictingconstraintbeing in effect for thiskey.voidputPersistedString(K key, String persisted)Mapkeyto the value obtained by parsingpersisted, if allowed according to either an existingconstraintor an implicit default constraint, if available.<T> voidputPersistedString(K key, IConstraint<T> constraint, String persisted)Mapkeyto the value obtained by parsingpersisted, if allowed according toconstraintand additional restrictions on this map such as a conflictingconstraintbeing in effect for thiskey.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openjdk.jmc.common.unit.IConstrainedMap
emptyWithSameConstraints, mutableCopy
-
-
-
-
Method Detail
-
keySet
public Set<K> keySet()
- Specified by:
keySetin interfaceIConstrainedMap<K>- Returns:
- A
setof keys which are known to be valid. That is, those that currently are known to have aconstraint. This includes all keys which currently have a value, but additional keys may be included. In other words,IConstrainedMap.get(Object)may returnnullfor some keys included in this set.
-
get
public Object get(K key)
Description copied from interface:IConstrainedMapGet the mapped value forkey, or null if no value is currently mapped. If this method ever returns a non-null value,IConstrainedMap.getConstraint(Object)for the samekeywill from that point forward return the same matching non-null constraint.- Specified by:
getin interfaceIConstrainedMap<K>- Returns:
- the mapped value or
null
-
getConstraint
public abstract IConstraint<?> getConstraint(K key)
Description copied from interface:IConstrainedMap- Specified by:
getConstraintin interfaceIConstrainedMap<K>- Returns:
- a constraint or
null
-
getSuggestedConstraint
protected IConstraint<?> getSuggestedConstraint(K key)
This method will only be called for keys for whichgetConstraint(Object)currently returns null for. Thus, it doesn't matter, and is unspecified, what it would return for keys whichgetConstraint(Object)return non-null for, which typically simplifies the implementations.
-
getPersistableString
public String getPersistableString(K key)
Description copied from interface:IConstrainedMapGet the persistable string of the mapped value forkey, or null if no value is currently mapped. If this method ever returns a non-null value,IConstrainedMap.getConstraint(Object)for the samekeywill from that point forward return the same matching non-null constraint.- Specified by:
getPersistableStringin interfaceIConstrainedMap<K>- Returns:
- a persistable string or
null
-
put
public void put(K key, Object value) throws QuantityConversionException
Description copied from interface:IMutableConstrainedMapMapkeytovalue, if allowed according to either an existingconstraintor an implicit default constraint, if available.- Specified by:
putin interfaceIMutableConstrainedMap<K>- Throws:
QuantityConversionException- ifvalueis rejected by the constraint in some other way
-
putPersistedString
public void putPersistedString(K key, String persisted) throws QuantityConversionException
Description copied from interface:IMutableConstrainedMapMapkeyto the value obtained by parsingpersisted, if allowed according to either an existingconstraintor an implicit default constraint, if available.- Specified by:
putPersistedStringin interfaceIMutableConstrainedMap<K>- Throws:
QuantityConversionException- ifpersistedis rejected by the constraint in some way
-
put
public <T> void put(K key, IConstraint<T> constraint, T value) throws QuantityConversionException
Description copied from interface:IMutableConstrainedMapMapkeytovalue, if allowed according toconstraintand additional restrictions on this map such as a conflictingconstraintbeing in effect for thiskey.- Specified by:
putin interfaceIMutableConstrainedMap<K>- Throws:
QuantityConversionException- ifvalueis rejected by the constraint in some other way
-
addConstraint
protected void addConstraint(K key, IConstraint<?> constraint)
-
putPersistedString
public <T> void putPersistedString(K key, IConstraint<T> constraint, String persisted) throws QuantityConversionException
Description copied from interface:IMutableConstrainedMapMapkeyto the value obtained by parsingpersisted, if allowed according toconstraintand additional restrictions on this map such as a conflictingconstraintbeing in effect for thiskey.- Specified by:
putPersistedStringin interfaceIMutableConstrainedMap<K>- Throws:
QuantityConversionException- ifpersistedis rejected by the constraint in some other way
-
-