Interface Value
- All Superinterfaces:
Comparable<Handled>,Dependency,Dependent,Handled
- All Known Implementing Classes:
MappingOperationModifier.SpecialValue,StaticValue,ValueImpl
A mutable numeric value identified by a Handle and backed with a Numeral that supports dynamic
Modifiers. Each value contains a base Numeral that can be changed with
convert(NumeralType), convertIfAllowed(NumeralType), toInteger(), toDecimal(),
set(Numeral), apply(Operation, MathContext, Numeral...) and other apply(...) methods. Each
value also contains a value Numeral, which represents the base Numeral with all the Modifiers applied to it. This
Numeral should be lazily calculated when getValue() is called, but only when the base Numeral or any of the
Modifiers have changed. It is recommended for the implementation to extend DependencyDependent to simplify
invalidating the cached value.
Values can be immutable. The base Numeral of an immutable value can not be changed, but immutable values can still
have Modifiers. Calling convert(NumeralType), toInteger(), toDecimal(),
set(Numeral) or any of the apply(...) methods should throw UnsupportedOperationException,
and calling convertIfAllowed(NumeralType) or toSmallestType() should return false with no
other action.
Values can also be considered static. A static value should be immutable, unmodifiable and not identified by a
Handle. In addition to the rules for immutable values, getHandle() should return null and all
Modifier-related methods should return false with no other action.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanaddModifier(Modifier modifier) booleanaddModifiers(Collection<? extends Modifier> modifiers) default voidapply(DualParameterOperation operation, Numeral parameter1, Numeral parameter2) UsesMathContext.defaults()for context.voidapply(DualParameterOperation operation, MathContext context, Numeral parameter1, Numeral parameter2) default voidUsesMathContext.defaults()for context.voidapply(Operation operation, MathContext context, Numeral... parameters) default voidapply(SingleParameterOperation operation, Numeral parameter) UsesMathContext.defaults()for context.voidapply(SingleParameterOperation operation, MathContext context, Numeral parameter) default voidapply(SourceOperation operation) UsesMathContext.defaults()for context.voidapply(SourceOperation operation, MathContext context) booleancanConvert(NumeralType type) default booleancompare(Comparison comparison, Numeral other) UsesComparisonContext.defaults()for context.booleancompare(Comparison comparison, ComparisonContext context, Numeral other) booleancontainsModifier(Modifier modifier) booleancontainsModifiers(Collection<? extends Modifier> modifiers) booleanconvert(NumeralType type) booleanconvertIfAllowed(NumeralType type) getBase()getValue()booleanStatic values are always immutable.booleanisStatic()booleanremoveModifier(Modifier modifier) booleanremoveModifiers(Collection<? extends Modifier> modifiers) voidbooleanIf the baseNumeraldoes not represent a decimal value (NumeralType.isDecimal()isfalseforNumeral.getType()), converts it to the smallest decimal type that hold the represented value.booleanIf the baseNumeraldoes not represent an integer value (NumeralType.isInteger()isfalseforNumeral.getType()), converts it to the smallest integer type that hold the represented value.booleanConverts the baseNumeralto the smallest type that can hold its represented value.Methods inherited from interface me.datafox.dfxengine.dependencies.Dependency
addDependent, addDependents, containsDependent, containsDependentRecursive, containsDependents, containsDependentsRecursive, dependentStream, getDependents, invalidateDependents, recursiveDependentStream, removeDependent, removeDependentsMethods inherited from interface me.datafox.dfxengine.dependencies.Dependent
invalidate
-
Method Details
-
getHandle
Handle getHandle() -
getBase
Numeral getBase()- Returns:
- base
Numeralof this value
-
getValue
Numeral getValue() -
isStatic
boolean isStatic()- Returns:
trueif this value is static
-
isImmutable
boolean isImmutable()Static values are always immutable.- Returns:
trueif this value is immutable
-
canConvert
- Parameters:
type-NumeralTypeto be checked for- Returns:
trueif the baseNumeralof this value can be converted to the specified type- 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
-
convert
- Parameters:
type-NumeralTypefor the baseNumeralof this value to be converted to- Returns:
trueif the baseNumeralof this value was changed as a result of this operation- Throws:
ExtendedArithmeticException- if the baseNumeralof this value is outside the specified type's boundsNullPointerException- 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 value is immutable
-
convertIfAllowed
- Parameters:
type-NumeralTypefor the baseNumeralof this value to be converted to- Returns:
trueif the baseNumeralof this value was changed as a result of this operation- 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
boolean toInteger()If the baseNumeraldoes not represent an integer value (NumeralType.isInteger()isfalseforNumeral.getType()), converts it to the smallest integer type that hold the represented value.- Returns:
trueif the baseNumeralwas changed as a result of this operation- Throws:
UnsupportedOperationException- if this value is immutable
-
toDecimal
boolean toDecimal()If the baseNumeraldoes not represent a decimal value (NumeralType.isDecimal()isfalseforNumeral.getType()), converts it to the smallest decimal type that hold the represented value.- Returns:
trueif the baseNumeralwas changed as a result of this operation- Throws:
UnsupportedOperationException- if this value is immutable
-
toSmallestType
boolean toSmallestType()Converts the baseNumeralto the smallest type that can hold its represented value. Will not convert between integer and decimal representations.- Returns:
trueif the baseNumeralwas changed as a result of this operation
-
set
- Parameters:
value- value to replace the current baseNumeral- Throws:
UnsupportedOperationException- if this value is immutable
-
apply
- Parameters:
operation-SourceOperationto be applied to the baseNumeralcontext-MathContextfor the operation- Throws:
UnsupportedOperationException- if this value is immutable
-
apply
- Parameters:
operation-SingleParameterOperationto be applied to the baseNumeralcontext-MathContextfor the operationparameter- parameter for the operation- Throws:
UnsupportedOperationException- if this value is immutable
-
apply
void apply(DualParameterOperation operation, MathContext context, Numeral parameter1, Numeral parameter2) - Parameters:
operation-DualParameterOperationto be applied to the baseNumeralcontext-MathContextfor the operationparameter1- first parameter for the operationparameter2- second parameter for the operation- Throws:
UnsupportedOperationException- if this value is static
-
apply
- Parameters:
operation-Operationto be applied to the baseNumeralcontext-MathContextfor the operationparameters- parameters for the operation- Throws:
IllegalArgumentException- if the amount of parameters is not equal toOperation.getParameterCount()UnsupportedOperationException- if this value is immutable
-
compare
- Parameters:
comparison-Comparisonto be usedcontext-ComparisonContextfor the comparisonother-Numeralto be compared with- Returns:
trueif the specifiedComparisonreturnstrue
-
getModifiers
Collection<Modifier> getModifiers()- Returns:
Modifiersassociated with this value
-
addModifier
-
addModifiers
-
removeModifier
-
removeModifiers
-
containsModifier
-
containsModifiers
-
apply
UsesMathContext.defaults()for context.- Parameters:
operation-SourceOperationto be applied to the baseNumeral- Throws:
UnsupportedOperationException- if this value is static
-
apply
UsesMathContext.defaults()for context.- Parameters:
operation-SingleParameterOperationto be applied to the baseNumeralparameter- parameter for the operation- Throws:
UnsupportedOperationException- if this value is static
-
apply
UsesMathContext.defaults()for context.- Parameters:
operation-DualParameterOperationto be applied to the baseNumeralparameter1- first parameter for the operationparameter2- second parameter for the operation- Throws:
UnsupportedOperationException- if this value is static
-
apply
UsesMathContext.defaults()for context.- Parameters:
operation-Operationto be applied to the baseNumeralparameters- parameters for the operation- Throws:
IllegalArgumentException- if the amount of parameters is not equal toOperation.getParameterCount()UnsupportedOperationException- if this value is static
-
compare
UsesComparisonContext.defaults()for context.- Parameters:
comparison-Comparisonto be usedother-Numeralto be compared with- Returns:
trueif the specifiedComparisonreturnstrue
-