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 protected
MutableConstrainedMap()
protected
MutableConstrainedMap(HashMap<K,Object> values)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addConstraint(K key, IConstraint<?> constraint)
Object
get(K key)
Get the mapped value forkey
, or null if no value is currently mapped.abstract IConstraint<?>
getConstraint(K key)
String
getPersistableString(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()
void
put(K key, Object value)
Mapkey
tovalue
, if allowed according to either an existingconstraint
or an implicit default constraint, if available.<T> void
put(K key, IConstraint<T> constraint, T value)
Mapkey
tovalue
, if allowed according toconstraint
and additional restrictions on this map such as a conflictingconstraint
being in effect for thiskey
.void
putPersistedString(K key, String persisted)
Mapkey
to the value obtained by parsingpersisted
, if allowed according to either an existingconstraint
or an implicit default constraint, if available.<T> void
putPersistedString(K key, IConstraint<T> constraint, String persisted)
Mapkey
to the value obtained by parsingpersisted
, if allowed according toconstraint
and additional restrictions on this map such as a conflictingconstraint
being 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:
keySet
in interfaceIConstrainedMap<K>
- Returns:
- A
set
of 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 returnnull
for some keys included in this set.
-
get
public Object get(K key)
Description copied from interface:IConstrainedMap
Get 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 samekey
will from that point forward return the same matching non-null constraint.- Specified by:
get
in interfaceIConstrainedMap<K>
- Returns:
- the mapped value or
null
-
getConstraint
public abstract IConstraint<?> getConstraint(K key)
Description copied from interface:IConstrainedMap
- Specified by:
getConstraint
in 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:IConstrainedMap
Get 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 samekey
will from that point forward return the same matching non-null constraint.- Specified by:
getPersistableString
in interfaceIConstrainedMap<K>
- Returns:
- a persistable string or
null
-
put
public void put(K key, Object value) throws QuantityConversionException
Description copied from interface:IMutableConstrainedMap
Mapkey
tovalue
, if allowed according to either an existingconstraint
or an implicit default constraint, if available.- Specified by:
put
in interfaceIMutableConstrainedMap<K>
- Throws:
QuantityConversionException
- ifvalue
is rejected by the constraint in some other way
-
putPersistedString
public void putPersistedString(K key, String persisted) throws QuantityConversionException
Description copied from interface:IMutableConstrainedMap
Mapkey
to the value obtained by parsingpersisted
, if allowed according to either an existingconstraint
or an implicit default constraint, if available.- Specified by:
putPersistedString
in interfaceIMutableConstrainedMap<K>
- Throws:
QuantityConversionException
- ifpersisted
is 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:IMutableConstrainedMap
Mapkey
tovalue
, if allowed according toconstraint
and additional restrictions on this map such as a conflictingconstraint
being in effect for thiskey
.- Specified by:
put
in interfaceIMutableConstrainedMap<K>
- Throws:
QuantityConversionException
- ifvalue
is 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:IMutableConstrainedMap
Mapkey
to the value obtained by parsingpersisted
, if allowed according toconstraint
and additional restrictions on this map such as a conflictingconstraint
being in effect for thiskey
.- Specified by:
putPersistedString
in interfaceIMutableConstrainedMap<K>
- Throws:
QuantityConversionException
- ifpersisted
is rejected by the constraint in some other way
-
-