Package me.datafox.dfxengine.values
Class DelegatedValueMap
java.lang.Object
me.datafox.dfxengine.values.DelegatedValueMap
An implementation of
ValueMap that can be backed with any implementation of HandleMap. Includes a
DelegatedValueMap.Builder for easy instantiation.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDelegatedValueMap(HandleMap<Value> map, boolean immutable, org.slf4j.Logger logger) -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddModifier(Modifier modifier) booleanaddModifiers(Collection<? extends Modifier> modifiers) voidapply(DualParameterOperation operation, MapMathContext context, Collection<? extends Handle> handles, Numeral parameter1, Numeral parameter2) voidapply(DualParameterOperation operation, MathContext context, Numeral parameter1, Numeral parameter2) voidapply(Operation operation, MapMathContext context, Collection<? extends Handle> handles, Numeral... parameters) voidvoidapply(Operation operation, MathContext context, Numeral... parameters) voidapply(SingleParameterOperation operation, MapMathContext context, Collection<? extends Handle> handles, Numeral parameter) voidapply(SingleParameterOperation operation, MapMathContext context, Map<? extends Handle, Numeral> parameters) voidapply(SingleParameterOperation operation, MathContext context, Numeral parameter) voidapply(SourceOperation operation, MapMathContext context, Collection<? extends Handle> handles) voidapply(SourceOperation operation, MathContext context) static DelegatedValueMap.Buildervoidclear()Removes all of theValuesfrom this map.booleancompare(Comparison comparison, ComparisonContext context, Numeral other) booleancompare(Comparison comparison, MapComparisonContext context, Collection<? extends Handle> handles, Numeral other) booleancompare(Comparison comparison, MapComparisonContext context, Map<? extends Handle, Numeral> others) booleancontainsKey(Object key) Returnstrueif this map contains a mapping for the specified key.booleancontainsKeys(Collection<?> keys) Returnstrueif this map contains a mapping for all the specified keys.booleancontainsModifier(Modifier modifier) booleancontainsModifiers(Collection<? extends Modifier> modifiers) booleancontainsValue(Object value) voidconvert(Collection<? extends Handle> handles, NumeralType type) voidconvert(Map<? extends Handle, NumeralType> types) voidconvert(NumeralType type) voidconvertAllowed(NumeralType type) Only convertsValuesof this map that can be converted to the specified type.entrySet()Returns the value to which the specified key is mapped, ornullif none is present.Returns all values mapped to keys containing the specified tag.getByTags(Collection<?> tags) Returns all values mapped to keys containing the specified tag.getOrDefault(Object key, Value defaultValue) Returnstrueif this map contains a mapping for the specified key, or the specified default value if none is present.getSpace()Returns theSpaceassociated with this map.booleanisEmpty()booleankeySet()This method ignores the key parameter, it is recommended to useputHandled(Value)instead.voidCopies all of the mappings from the specified map to this map.putHandled(Value value) Associates aValuein this map.putIfAbsent(Handle key, Value value) Associates the specified key with the specified value and returnsnullif the specified key is not already associated with a value, otherwise returns the current value.Removes the mapping for a key from this map if it is present.booleanRemoves the entry for the specified key only if it is currently mapped to the specified value.booleanremoveModifier(Modifier modifier) booleanremoveModifiers(Collection<? extends Modifier> modifiers) voidvoidset(MapMathContext context, Collection<? extends Handle> handles, Numeral value) voidset(MapMathContext context, Map<? extends Handle, Numeral> values) intsize()voidConverts allValuesto the smallest decimal type that can hold its represented value.voidConverts allValuesto the smallest integer type that can hold its represented value.voidConverts allValuesto the smallest type that can hold its represented value.voidtoSmallestType(Collection<? extends Handle> handles) Converts specifiedValuesto the smallest type that can hold its represented value.toString()Returns an unmodifiable version of this map.values()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, hashCode, merge, replace, replace, replaceAll
-
Constructor Details
-
Method Details
-
isImmutable
public boolean isImmutable()- Specified by:
isImmutablein interfaceValueMap- Returns:
trueif this map is for immutableValues
-
convert
- Specified by:
convertin interfaceValueMap- Parameters:
type-NumeralTypefor theValuesto be converted to- Throws:
ExtendedArithmeticException- if any of theValuesin this map cannot be converted to the specified typeNullPointerException- if the specified type isnullIllegalArgumentException- if the specified type is notnull, but it is not recognised as any of the elements ofNumeralType. This should never happenUnsupportedOperationException- if this map is for immutableValues
-
convert
- Specified by:
convertin interfaceValueMap- Parameters:
handles-Handlesof theValuesto be convertedtype-NumeralTypefor theValuesto be converted to- Throws:
ExtendedArithmeticException- if any of the specified values in this map cannot be converted to the specified typeNullPointerException- if the specified type isnullIllegalArgumentException- if the specified type is notnull, but it is not recognised as any of the elements ofNumeralType. This should never happenUnsupportedOperationException- if this map is for immutableValues
-
convert
- Specified by:
convertin interfaceValueMap- Parameters:
types- map ofHandlesandNumeralTypesfor theValuesrepresented by those Handles to be converted to.- Throws:
ExtendedArithmeticException- if any of the specified values in this map cannot be converted to the specified typeNullPointerException- if the specified type isnullIllegalArgumentException- if the specified type is notnull, but it is not recognised as any of the elements ofNumeralType. This should never happenUnsupportedOperationException- if this map is for immutableValues
-
convertAllowed
Only convertsValuesof this map that can be converted to the specified type. In other words, callsNumeral.convertIfAllowed(NumeralType)on every Value of this map. If this map is for immutable Values, this method does nothing.- Specified by:
convertAllowedin interfaceValueMap- Parameters:
type-NumeralTypefor theValuesto be converted to- Throws:
NullPointerException- if the specified type isnullIllegalArgumentException- if the specified type is notnull, but it is not recognised as any of the elements ofNumeralType. This should never happen
-
toInteger
public void toInteger()Converts allValuesto the smallest integer type that can hold its represented value. Values that are already integers are not converted.- Specified by:
toIntegerin interfaceValueMap- Throws:
UnsupportedOperationException- if this map is for immutableValues
-
toDecimal
public void toDecimal()Converts allValuesto the smallest decimal type that can hold its represented value. Values that are already decimals are not converted.- Specified by:
toDecimalin interfaceValueMap- Throws:
UnsupportedOperationException- if this map is for immutableValues
-
toSmallestType
public void toSmallestType()Converts allValuesto the smallest type that can hold its represented value. Will not convert between integer and decimal representations. If this map is for immutable Values, this method does nothing.- Specified by:
toSmallestTypein interfaceValueMap
-
toSmallestType
Converts specifiedValuesto the smallest type that can hold its represented value. Will not convert between integer and decimal representations.Handlesthat are not a part of this map's associatedSpaceare ignored. If this map is for immutable Values, this method does nothing.- Specified by:
toSmallestTypein interfaceValueMap- Parameters:
handles-Handlesof the values to be converted
-
set
-
set
- Specified by:
setin interfaceValueMap- Parameters:
context-MapMathContextfor this operationhandles-Handlesof the values to be changedvalue-Numeralfor specifiedValuesof this map to be set to- Throws:
UnsupportedOperationException- if this map is for immutableValues
-
set
- Specified by:
setin interfaceValueMap- Parameters:
context-MapMathContextfor this operationvalues- map ofHandlesto be changed andNumeralsfor the specifiedValuesto be set to- Throws:
UnsupportedOperationException- if this map is for immutableValues
-
apply
- Specified by:
applyin interfaceValueMap- Parameters:
operation-SourceOperationto be applied to allValuesof this mapcontext-MathContextfor the operation- Throws:
UnsupportedOperationException- if this map is for immutableValues
-
apply
public void apply(SourceOperation operation, MapMathContext context, Collection<? extends Handle> handles) - Specified by:
applyin interfaceValueMap- Parameters:
operation-SourceOperationto be applied to specifiedValuesof this mapcontext-MapMathContextfor the operationhandles-Handlesof theValuesto be modified- Throws:
UnsupportedOperationException- if this map is for immutableValues
-
apply
- Specified by:
applyin interfaceValueMap- Parameters:
operation-SingleParameterOperationto be applied to allValuesof this mapcontext-MathContextfor the operationparameter- parameter for the operation- Throws:
UnsupportedOperationException- if this map is for immutableValues
-
apply
public void apply(SingleParameterOperation operation, MapMathContext context, Collection<? extends Handle> handles, Numeral parameter) - Specified by:
applyin interfaceValueMap- Parameters:
operation-SingleParameterOperationto be applied to specifiedValuesof this mapcontext-MapMathContextfor the operationhandles-Handlesof theValuesto be modifiedparameter- parameter for the operation- Throws:
UnsupportedOperationException- if this map is for immutableValues
-
apply
public void apply(SingleParameterOperation operation, MapMathContext context, Map<? extends Handle, Numeral> parameters) - Specified by:
applyin interfaceValueMap- Parameters:
operation-SingleParameterOperationto be applied to specifiedValuesof this mapcontext-MapMathContextfor the operationparameters- map ofHandlesof theValuesto be modified andNumeralsto be used as parameters for the operation- Throws:
UnsupportedOperationException- if this map is for immutableValues
-
apply
public void apply(DualParameterOperation operation, MathContext context, Numeral parameter1, Numeral parameter2) - Specified by:
applyin interfaceValueMap- Parameters:
operation-DualParameterOperationto be applied to allValuesof this mapcontext-MathContextfor the operationparameter1- first parameter for the operationparameter2- second parameter for the operation- Throws:
UnsupportedOperationException- if this map is for immutableValues
-
apply
public void apply(DualParameterOperation operation, MapMathContext context, Collection<? extends Handle> handles, Numeral parameter1, Numeral parameter2) - Specified by:
applyin interfaceValueMap- Parameters:
operation-DualParameterOperationto be applied to specifiedValuesof this mapcontext-MapMathContextfor the operationhandles-Handlesof theValuesto be modifiedparameter1- first parameter for the operationparameter2- second parameter for the operation- Throws:
UnsupportedOperationException- if this map is for immutableValues
-
apply
- Specified by:
applyin interfaceValueMap- Parameters:
operation-Operationto be applied to allValuesof this mapcontext-MathContextfor the operationparameters- parameters for the operation- Throws:
IllegalArgumentException- if the amount of parameters is not equal toOperation.getParameterCount()UnsupportedOperationException- if this map is for immutableValues
-
apply
public void apply(Operation operation, MapMathContext context, Collection<? extends Handle> handles, Numeral... parameters) - Specified by:
applyin interfaceValueMap- Parameters:
operation-Operationto be applied to allValuesof this mapcontext-MathContextfor the operationhandles-Handlesof theValuesto be modifiedparameters- parameters for the operation- Throws:
IllegalArgumentException- if the amount of parameters is not equal toOperation.getParameterCount()UnsupportedOperationException- if this map is for immutableValues
-
apply
public void apply(Operation operation, MapMathContext context, Map<? extends Handle, Numeral[]> parameters) - Specified by:
applyin interfaceValueMap- Parameters:
operation-Operationto be applied to allValuesof this mapcontext-MathContextfor the operationparameters- map ofHandlesof theValuesto be modified andNumeralsto be used as parameters for the operation- Throws:
IllegalArgumentException- if the amount of parameters is not equal toOperation.getParameterCount()UnsupportedOperationException- if this map is for immutableValues
-
compare
- Specified by:
comparein interfaceValueMap- Parameters:
comparison-Comparisonto be usedcontext-ComparisonContextfor the comparisonother-Numeralto be compared to- Returns:
trueif theComparisonreturnstruefor allValuesof this map
-
compare
public boolean compare(Comparison comparison, MapComparisonContext context, Collection<? extends Handle> handles, Numeral other) - Specified by:
comparein interfaceValueMap- Parameters:
comparison-Comparisonto be usedcontext-MapComparisonContextfor the comparisonhandles-Handlesof theValuesto be comparedother-Numeralto be compared to- Returns:
trueif theComparisonreturnstruefor allValuesof this map represented by the specified keys
-
compare
public boolean compare(Comparison comparison, MapComparisonContext context, Map<? extends Handle, Numeral> others) - Specified by:
comparein interfaceValueMap- Parameters:
comparison-Comparisonto be usedcontext-MapComparisonContextfor the comparisonothers- map ofHandlesof theValuesto be compared andNumeralsto be compared to- Returns:
trueif theComparisonreturnstruefor allValuesof this map represented by the specified keys
-
getBaseNumeralMap
- Specified by:
getBaseNumeralMapin interfaceValueMap- Returns:
Mapcontaining all entries of this map, but with the return value ofValue.getBase()as the map values. The returned map does not have any state and instead provides a view to this map
-
getValueNumeralMap
- Specified by:
getValueNumeralMapin interfaceValueMap- Returns:
Mapcontaining all entries of this map, but with the return value ofValue.getValue()as the map values. The returned map does not have any state and instead provides a view to this map
-
getModifiers
- Specified by:
getModifiersin interfaceValueMap- Returns:
Modifiersassociated with this map
-
addModifier
Modifiersadded to this map will be added to allValuesof this map, including ones that are added to this map after this operation. To add a modifier to a single value, useValue.addModifier(Modifier)instead.- Specified by:
addModifierin interfaceValueMap- Parameters:
modifier-Modifierto be added- Returns:
trueif theModifiersof this map changed as a result of this operation
-
addModifiers
Modifiersadded to this map will be added to allValuesof this map, including ones that are added to this map after this operation. To add modifiers to a single value, useValue.addModifiers(Collection)} instead.- Specified by:
addModifiersin interfaceValueMap- Parameters:
modifiers-Modifiersto be added- Returns:
trueif theModifiersof this map changed as a result of this operation
-
removeModifier
- Specified by:
removeModifierin interfaceValueMap- Parameters:
modifier-Modifierto be removed- Returns:
trueif theModifiersof this map changed as a result of this operation
-
removeModifiers
- Specified by:
removeModifiersin interfaceValueMap- Parameters:
modifiers-Modifiersto be removed- Returns:
trueif theModifiersof this map changed as a result of this operation
-
containsModifier
- Specified by:
containsModifierin interfaceValueMap- Parameters:
modifier-Modifierto be checked for- Returns:
trueif the specifiedModifieris associated with this map
-
containsModifiers
- Specified by:
containsModifiersin interfaceValueMap- Parameters:
modifiers-Modifiersto be checked for- Returns:
trueif all of the specifiedModifiersare associated with this map
-
getSpace
-
containsKeys
Returnstrueif this map contains a mapping for all the specified keys. The keys may either beHandlesor theirStringids.- Specified by:
containsKeysin interfaceHandleMap<Value>- Parameters:
keys-Handlekeys or theirStringids whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for all the specified keys- Throws:
ClassCastException- if any of the keys are of an inappropriate type for this mapNullPointerException- if any of the keys isnull
-
putHandled
Associates aValuein this map. If the map previously contained a mapping for theHandle, the old Value is replaced.- Specified by:
putHandledin interfaceHandleMap<Value>- Parameters:
value-Valueto be associated in this map with its associatedHandleas a key- Returns:
- the previously associated
Valuein this map, ornullif there was no previous association - Throws:
IllegalArgumentException- if theValueis static, ifValue.isImmutable()is not the same asisImmutable()or if the associatedHandleis not contained in theSpaceassociated with this map
-
unmodifiable
Returns an unmodifiable version of this map. All changes made to the original map will be reflected in the returned one.- Specified by:
unmodifiablein interfaceHandleMap<Value>- Returns:
- unmodifiable version of this map
-
getByTag
Returns all values mapped to keys containing the specified tag. The tag may be aHandleor itsStringid.- Specified by:
getByTagin interfaceHandleMap<Value>- Parameters:
tag- tagHandleor itsStringid- Returns:
- all values mapped to keys containing the specified tag
- Throws:
ClassCastException- if the tag is not aHandleor aStringNullPointerException- if the tag isnullIllegalArgumentException- if theHandleis not a tag
-
getByTags
Returns all values mapped to keys containing the specified tag. The tags may beHandlesor theirStringids.- Specified by:
getByTagsin interfaceHandleMap<Value>- Parameters:
tags- tagHandlesor theirStringids- Returns:
- all values mapped to keys containing the specified tags
- Throws:
ClassCastException- if any of the tags are notHandlesor aStringsNullPointerException- if any of the tags isnullIllegalArgumentException- if any of theHandlesis not a tag
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
Description copied from interface:HandleMapReturnstrueif this map contains a mapping for the specified key. The key may either be aHandleor itsStringid.- Specified by:
containsKeyin interfaceHandleMap<Value>- Specified by:
containsKeyin interfaceMap<Handle,Value> - Parameters:
key- key whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for the specified key
-
containsValue
- Specified by:
containsValuein interfaceMap<Handle,Value> - Parameters:
value- value whose presence in this map is to be tested- Returns:
trueif this map maps one or more keys to the specified value
-
get
Description copied from interface:HandleMap -
put
This method ignores the key parameter, it is recommended to useputHandled(Value)instead.- Specified by:
putin interfaceHandleMap<Value>- Specified by:
putin interfaceMap<Handle,Value> - Parameters:
key- ignored parametervalue-Valueto be associated with this map- Returns:
- previously associated
Valuein this map, ornullif there was no previous association - Throws:
IllegalArgumentException- if theValueis static, ifValue.isImmutable()is not the same asisImmutable()or if the associatedHandleis not contained in theSpaceassociated with this map
-
remove
Description copied from interface:HandleMap -
putAll
Description copied from interface:HandleMapCopies all of the mappings from the specified map to this map. The effect of this call is equivalent to that of callingHandleMap.put(Handle, Object)on this map once for each mapping from key to value in the specified map. AllHandlekeys must be present in this map's associatedSpace. -
getOrDefault
Returnstrueif this map contains a mapping for the specified key, or the specified default value if none is present. The key may either be aHandleor itsStringid.- Specified by:
getOrDefaultin interfaceHandleMap<Value>- Specified by:
getOrDefaultin interfaceMap<Handle,Value> - Parameters:
key-Handlekey or itsStringid whose associated value is to be returneddefaultValue- the default mapping of the key- Returns:
- the value to which the specified key is mapped, or the specified default value if this map contains no mapping for the key
- Throws:
ClassCastException- if the key is of an inappropriate type for this mapNullPointerException- if the specified key isnull
-
putIfAbsent
Associates the specified key with the specified value and returnsnullif the specified key is not already associated with a value, otherwise returns the current value.- Specified by:
putIfAbsentin interfaceHandleMap<Value>- Specified by:
putIfAbsentin interfaceMap<Handle,Value> - Parameters:
key-Handlekey with which the specified value is to be associated withvalue- value to be associated with the specified key- Returns:
- the previous value associated with the specified key, or
nullif there was no mapping for the key - Throws:
UnsupportedOperationException- if theputoperation is not supported by this mapClassCastException- if the key or value is of an inappropriate type for this mapNullPointerException- if the specified key or value isnullIllegalArgumentException- if theHandlekey is not present in this map's associatedSpace
-
remove
Removes the entry for the specified key only if it is currently mapped to the specified value. The key may either be aHandleor itsStringid.- Specified by:
removein interfaceHandleMap<Value>- Specified by:
removein interfaceMap<Handle,Value> - Parameters:
key-Handlekey or itsStringid with which the specified value is associatedvalue- value expected to be associated with the specified key- Returns:
trueif the value was removed- Throws:
UnsupportedOperationException- if theremoveoperation is not supported by this mapClassCastException- if the key or value is of an inappropriate type for this mapNullPointerException- if the specified key or value isnull
-
clear
public void clear()Removes all of theValuesfrom this map. -
keySet
-
values
-
entrySet
-
toString
-
builder
- Parameters:
space-Spaceto be associated with theDelegatedValueMap.Builder- Returns:
DelegatedValueMap.Builderwith the specifiedSpace
-