Class SimpleChangeableNumber
- java.lang.Object
-
- bitchanger.calculations.SimpleChangeableNumber
-
- All Implemented Interfaces:
ChangeableNumber
public class SimpleChangeableNumber extends Object implements ChangeableNumber
The class SimpleChangeableNumber offers a complete implementation ofChangeableNumber.Each instance of this class wraps a value, that gets set from different numeral systems and can get converted into any numeral system. The strings in these numeral systems do not contain any prefixes that refer to the base.
The string representations of the number systems are splitted into blocks for better readability. The blocks are four characters long in the hexadecimal and binary systems, in all other number systems the blocks are three characters long.
- Since:
- Bitchanger 0.1.0
- Version:
- 1.0.2
- Author:
- Tim Muehle, Moritz Wolter
- See Also:
ChangeableNumber
-
-
Field Summary
-
Fields inherited from interface bitchanger.calculations.ChangeableNumber
NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY
-
-
Constructor Summary
Constructors Constructor Description SimpleChangeableNumber()Generates a new instance with 0 as wrapped valueSimpleChangeableNumber(String decValue)Generates a new instance that represents the committed decimal value
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javafx.beans.property.IntegerPropertybaseProperty()javafx.beans.property.ReadOnlyStringPropertylogicStringProperty()voidreset()Resets the wrapped value.voidset(double decValue)voidsetBin(String binValue)Sets the value of thisChangeableNumberto the value of a binary stringvoidsetDec(String decValue)Sets the value of thisChangeableNumberto the value of a decimal stringvoidsetHex(String hexValue)Sets the value of thisChangeableNumberto the value of a hexadecimal stringvoidsetIEEE(String ieee, IEEEStandard standard)Sets the value of thisChangeableNumberto a value of one of both IEEE standards (16 Bit or 32 Bit)voidsetOct(String octValue)Sets the value of thisChangeableNumberto the value of an octal stringvoidsetValue(String value, int baseOfValue)Sets the value of thisChangeableNumberto a value of any numeral systemjavafx.beans.property.ReadOnlyStringPropertystringProperty()StringtoBaseString(int base)Returns the string representation of thisChangeableNumberto any base.StringtoBinString()Returns the string representation of thisChangeableNumberas a binary string.StringtoDecString()Returns the string representation of thisChangeableNumberas a decimal string.StringtoHexString()Returns the string representation of thisChangeableNumberas a hexadecimal string.StringtoIEEEString(IEEEStandard standard)Returns the String representation of thisChangeableNumberas IEEE standard String.StringtoOctString()Returns the string representation of thisChangeableNumberas an octal string.StringtoString()Returns aStringthat includes the hexadecimal, decimal, octal and binary presentation of the wrapped value.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface bitchanger.calculations.ChangeableNumber
asDouble
-
-
-
-
Constructor Detail
-
SimpleChangeableNumber
public SimpleChangeableNumber()
Generates a new instance with 0 as wrapped value
-
SimpleChangeableNumber
public SimpleChangeableNumber(String decValue) throws NullPointerException, NumberFormatException, IllegalArgumentException
Generates a new instance that represents the committed decimal value- Parameters:
decValue- Value that should be wrapped by this object- Throws:
NullPointerException- if the parameterdecValueisnullNumberFormatException- if the parameterdecValueis not a number of the decimal systemIllegalArgumentException- ifdecValueis an empty string
-
-
Method Detail
-
set
public void set(double decValue) throws NullPointerException, NumberFormatException, IllegalArgumentException, NumberOverflowException- Specified by:
setin interfaceChangeableNumber- Throws:
NullPointerExceptionNumberFormatExceptionIllegalArgumentExceptionNumberOverflowException
-
setHex
public void setHex(String hexValue) throws NullPointerException, NumberFormatException, IllegalArgumentException
Sets the value of thisChangeableNumberto the value of a hexadecimal string- Specified by:
setHexin interfaceChangeableNumber- Parameters:
hexValue- New Value that is represented as a hexadecimal string by this class- Throws:
NullPointerException- if the parameterhexValueisnullNumberFormatException- if the parameterhexValueis not a number of the hexadecimal systemIllegalArgumentException- ifhexValueis an empty string
-
setDec
public void setDec(String decValue) throws NullPointerException, NumberFormatException, IllegalArgumentException
Sets the value of thisChangeableNumberto the value of a decimal string- Specified by:
setDecin interfaceChangeableNumber- Parameters:
decValue- New value that is represented as a decimal string by this class- Throws:
NullPointerException- if the parameterdecValueisnullNumberFormatException- if the parameterdecValueis not a number of the decimal systemIllegalArgumentException- ifdecValueis an empty string
-
setOct
public void setOct(String octValue) throws NullPointerException, NumberFormatException, IllegalArgumentException
Sets the value of thisChangeableNumberto the value of an octal string- Specified by:
setOctin interfaceChangeableNumber- Parameters:
octValue- New value that is represented as an octal string by this class- Throws:
NullPointerException- if the parameteroctValueisnullNumberFormatException- if the parameteroctValueis not a number of the octal systemIllegalArgumentException- ifoctValueis an empty string
-
setBin
public void setBin(String binValue) throws NullPointerException, NumberFormatException, IllegalArgumentException
Sets the value of thisChangeableNumberto the value of a binary string- Specified by:
setBinin interfaceChangeableNumber- Parameters:
binValue- New value that is represented as a binary string by this class- Throws:
NullPointerException- if the parameterbinValueisnullNumberFormatException- if the parameterbinValueis not a number of the binary systemIllegalArgumentException- ifbinValueis an empty string
-
setValue
public void setValue(String value, int baseOfValue) throws NullPointerException, NumberFormatException, IllegalArgumentException
Sets the value of thisChangeableNumberto a value of any numeral system- Specified by:
setValuein interfaceChangeableNumber- Parameters:
value- New value that is represented as string by this classbaseOfValue- Base of the numeral system ofvalue- Throws:
NullPointerException- if the parametervalueisnullNumberFormatException- if the parametervalueis not a number of the binary systemIllegalArgumentException- ifvalueis an empty string or ifbaseOfValueleaves the range of values [2, 36] - seeConvertingNumbers.isValueToBase(int base, String value)
-
setIEEE
public void setIEEE(String ieee, IEEEStandard standard) throws NullPointerException, NumberFormatException, IllegalArgumentException
Sets the value of thisChangeableNumberto a value of one of both IEEE standards (16 Bit or 32 Bit)- Specified by:
setIEEEin interfaceChangeableNumber- Parameters:
ieee- New Value that is represented as a String, by this classstandard- Standard of the used IEEE standard ofieee- Throws:
NullPointerException- if the parameterieeeisnullNumberFormatException- if the parameterieeeis not a number of the binary system or has more characters than 16 respectively 32IllegalArgumentException- ifieeeis an empty String orstandardis something else than 16 or 32
-
reset
public void reset()
Resets the wrapped value. The previous value gets deleted! If a toString method is called after this method, an empty string will be returned.The wrapped value can be set again by using one of the set methods.
- Specified by:
resetin interfaceChangeableNumber
-
toHexString
public String toHexString()
Returns the string representation of thisChangeableNumberas a hexadecimal string.The string is not labeled as hexadecimal, so the prefix is not leading!
- Specified by:
toHexStringin interfaceChangeableNumber- Returns:
- hexadecimal string representation of this
ChangeableNumber
-
toDecString
public String toDecString()
Returns the string representation of thisChangeableNumberas a decimal string.- Specified by:
toDecStringin interfaceChangeableNumber- Returns:
- decimal string representation of this
ChangeableNumber
-
toOctString
public String toOctString()
Returns the string representation of thisChangeableNumberas an octal string.The string is not labeled as octal, so the prefix is not leading!
- Specified by:
toOctStringin interfaceChangeableNumber- Returns:
- octal string representation of this
ChangeableNumber
-
toBinString
public String toBinString()
Returns the string representation of thisChangeableNumberas a binary string.The string is not labeled as binary, so the prefix is not leading!
- Specified by:
toBinStringin interfaceChangeableNumber- Returns:
- binary string representation of this
ChangeableNumber
-
toBaseString
public String toBaseString(int base) throws IllegalArgumentException
Returns the string representation of thisChangeableNumberto any base.The String is not labeled by a prefix!
- Specified by:
toBaseStringin interfaceChangeableNumber- Parameters:
base- Base of the numeral system, in which thisChangeableNumberis represented- Returns:
- String representation of this
ChangeableNumberto the committed base - Throws:
IllegalArgumentException- ifbaseleaves the range of values [2, 36] - seeConvertingNumbers.isValueToBase(int, String)
-
toString
public String toString()
Returns aStringthat includes the hexadecimal, decimal, octal and binary presentation of the wrapped value.
-
toIEEEString
public String toIEEEString(IEEEStandard standard) throws ArithmeticException
Returns the String representation of thisChangeableNumberas IEEE standard String.- Specified by:
toIEEEStringin interfaceChangeableNumber- Parameters:
standard- IEEE standard that is used for converting- Returns:
- IEEE as String representation of this
ChangeableNumber - Throws:
ArithmeticException- if this number cannot be presented by the given ieee standard
-
stringProperty
public javafx.beans.property.ReadOnlyStringProperty stringProperty()
- Specified by:
stringPropertyin interfaceChangeableNumber- Returns:
-
logicStringProperty
public javafx.beans.property.ReadOnlyStringProperty logicStringProperty()
- Specified by:
logicStringPropertyin interfaceChangeableNumber- Returns:
-
baseProperty
public javafx.beans.property.IntegerProperty baseProperty()
- Specified by:
basePropertyin interfaceChangeableNumber- Returns:
-
-