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
A mutable extension to
IConstrainedMap
. 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.-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
protected
MutableConstrainedMap
(HashMap<K, Object> values) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addConstraint
(K key, IConstraint<?> constraint) Get the mapped value forkey
, or null if no value is currently mapped.abstract IConstraint<?>
getConstraint
(K key) 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.keySet()
void
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
-
Field Details
-
values
-
-
Constructor Details
-
MutableConstrainedMap
protected MutableConstrainedMap() -
MutableConstrainedMap
-
-
Method Details
-
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
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
Description copied from interface:IConstrainedMap
- Specified by:
getConstraint
in interfaceIConstrainedMap<K>
- Returns:
- a constraint or
null
-
getSuggestedConstraint
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
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
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
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
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
-
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
-