Package me.datafox.dfxengine.values
Class ValueImpl
java.lang.Object
me.datafox.dfxengine.dependencies.AbstractDependency
me.datafox.dfxengine.dependencies.DependencyDependent
me.datafox.dfxengine.values.ValueImpl
- All Implemented Interfaces:
Comparable<Handled>,Dependency,Dependent,Handled,Value
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 set(Numeral) and
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 value is lazily
calculated when getValue() is called, but only when the base Numeral or any of the Modifiers have changed.
These changes are tracked with Dependencies and Dependents.-
Field Summary
Fields inherited from class me.datafox.dfxengine.dependencies.AbstractDependency
dependents, logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddModifier(Modifier modifier) booleanaddModifiers(Collection<? extends Modifier> modifiers) voidapply(DualParameterOperation operation, MathContext context, Numeral parameter1, Numeral parameter2) voidapply(Operation operation, MathContext context, Numeral... parameters) voidapply(SingleParameterOperation operation, MathContext context, Numeral parameter) voidapply(SourceOperation operation, MathContext context) booleancanConvert(NumeralType type) 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()This implementation always returnsfalse.protected voidThis method should be treated as the equivalent ofDependent.invalidate()for classes extending DependencyDependent.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.toString()Methods inherited from class me.datafox.dfxengine.dependencies.DependencyDependent
invalidateMethods inherited from class me.datafox.dfxengine.dependencies.AbstractDependency
addDependent, addDependents, containsDependent, containsDependentRecursive, containsDependents, containsDependentsRecursive, dependentStream, getDependents, invalidateDependents, recursiveDependentStream, removeDependent, removeDependentsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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
-
Constructor Details
-
Method Details
-
getHandle
-
getBase
-
getValue
-
isStatic
public boolean isStatic()This implementation always returnsfalse. -
isImmutable
public boolean isImmutable()Description copied from interface:ValueStatic values are always immutable.- Specified by:
isImmutablein interfaceValue- Returns:
trueif this value is immutable
-
canConvert
- Specified by:
canConvertin interfaceValue- 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
- Specified by:
convertin interfaceValue- 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
- Specified by:
convertIfAllowedin interfaceValue- 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
public 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.- Specified by:
toIntegerin interfaceValue- Returns:
trueif the baseNumeralwas changed as a result of this operation- Throws:
UnsupportedOperationException- if this value is immutable
-
toDecimal
public 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.- Specified by:
toDecimalin interfaceValue- Returns:
trueif the baseNumeralwas changed as a result of this operation- Throws:
UnsupportedOperationException- if this value is immutable
-
toSmallestType
public boolean toSmallestType()Converts the baseNumeralto the smallest type that can hold its represented value. Will not convert between integer and decimal representations.- Specified by:
toSmallestTypein interfaceValue- Returns:
trueif the baseNumeralwas changed as a result of this operation
-
set
- Specified by:
setin interfaceValue- Parameters:
value- value to replace the current baseNumeral- Throws:
UnsupportedOperationException- if this value is immutable
-
apply
- Specified by:
applyin interfaceValue- Parameters:
operation-SourceOperationto be applied to the baseNumeralcontext-MathContextfor the operation- Throws:
UnsupportedOperationException- if this value is immutable
-
apply
- Specified by:
applyin interfaceValue- Parameters:
operation-SingleParameterOperationto be applied to the baseNumeralcontext-MathContextfor the operationparameter- parameter for the operation- Throws:
UnsupportedOperationException- if this value is immutable
-
apply
public void apply(DualParameterOperation operation, MathContext context, Numeral parameter1, Numeral parameter2) - Specified by:
applyin interfaceValue- 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 immutable
-
apply
- Specified by:
applyin interfaceValue- 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
- Specified by:
comparein interfaceValue- Parameters:
comparison-Comparisonto be usedcontext-ComparisonContextfor the comparisonother-Numeralto be compared with- Returns:
trueif the specifiedComparisonreturnstrue
-
getModifiers
- Specified by:
getModifiersin interfaceValue- Returns:
Modifiersassociated with this value
-
addModifier
- Specified by:
addModifierin interfaceValue- Parameters:
modifier-Modifierto be added- Returns:
trueif theModifiersof this value changed as a result of this operation
-
addModifiers
- Specified by:
addModifiersin interfaceValue- Parameters:
modifiers-Modifiersto be added- Returns:
trueif theModifiersof this value changed as a result of this operation
-
removeModifier
- Specified by:
removeModifierin interfaceValue- Parameters:
modifier-Modifierto be removed- Returns:
trueif theModifiersof this value changed as a result of this operation
-
removeModifiers
- Specified by:
removeModifiersin interfaceValue- Parameters:
modifiers-Modifiersto be removed- Returns:
trueif theModifiersof this value changed as a result of this operation
-
containsModifier
- Specified by:
containsModifierin interfaceValue- Parameters:
modifier-Modifierto be checked for- Returns:
trueif the specifiedModifieris associated with this value
-
containsModifiers
- Specified by:
containsModifiersin interfaceValue- Parameters:
modifiers-Modifiersto be checked for- Returns:
trueif all of the specifiedModifiersare associated with this value
-
onInvalidate
protected void onInvalidate()Description copied from class:DependencyDependentThis method should be treated as the equivalent ofDependent.invalidate()for classes extending DependencyDependent. This exists to avoid the need for callingsuper.invalidate()orAbstractDependency.invalidateDependents()which may cause hidden or hard to find bugs when forgotten.- Specified by:
onInvalidatein classDependencyDependent
-
toString
-