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.IntegerProperty
baseProperty()
javafx.beans.property.ReadOnlyStringProperty
logicStringProperty()
void
reset()
Resets the wrapped value.void
set(double decValue)
void
setBin(String binValue)
Sets the value of thisChangeableNumber
to the value of a binary stringvoid
setDec(String decValue)
Sets the value of thisChangeableNumber
to the value of a decimal stringvoid
setHex(String hexValue)
Sets the value of thisChangeableNumber
to the value of a hexadecimal stringvoid
setIEEE(String ieee, IEEEStandard standard)
Sets the value of thisChangeableNumber
to a value of one of both IEEE standards (16 Bit or 32 Bit)void
setOct(String octValue)
Sets the value of thisChangeableNumber
to the value of an octal stringvoid
setValue(String value, int baseOfValue)
Sets the value of thisChangeableNumber
to a value of any numeral systemjavafx.beans.property.ReadOnlyStringProperty
stringProperty()
String
toBaseString(int base)
Returns the string representation of thisChangeableNumber
to any base.String
toBinString()
Returns the string representation of thisChangeableNumber
as a binary string.String
toDecString()
Returns the string representation of thisChangeableNumber
as a decimal string.String
toHexString()
Returns the string representation of thisChangeableNumber
as a hexadecimal string.String
toIEEEString(IEEEStandard standard)
Returns the String representation of thisChangeableNumber
as IEEE standard String.String
toOctString()
Returns the string representation of thisChangeableNumber
as an octal string.String
toString()
Returns aString
that 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 parameterdecValue
isnull
NumberFormatException
- if the parameterdecValue
is not a number of the decimal systemIllegalArgumentException
- ifdecValue
is an empty string
-
-
Method Detail
-
set
public void set(double decValue) throws NullPointerException, NumberFormatException, IllegalArgumentException, NumberOverflowException
- Specified by:
set
in interfaceChangeableNumber
- Throws:
NullPointerException
NumberFormatException
IllegalArgumentException
NumberOverflowException
-
setHex
public void setHex(String hexValue) throws NullPointerException, NumberFormatException, IllegalArgumentException
Sets the value of thisChangeableNumber
to the value of a hexadecimal string- Specified by:
setHex
in interfaceChangeableNumber
- Parameters:
hexValue
- New Value that is represented as a hexadecimal string by this class- Throws:
NullPointerException
- if the parameterhexValue
isnull
NumberFormatException
- if the parameterhexValue
is not a number of the hexadecimal systemIllegalArgumentException
- ifhexValue
is an empty string
-
setDec
public void setDec(String decValue) throws NullPointerException, NumberFormatException, IllegalArgumentException
Sets the value of thisChangeableNumber
to the value of a decimal string- Specified by:
setDec
in interfaceChangeableNumber
- Parameters:
decValue
- New value that is represented as a decimal string by this class- Throws:
NullPointerException
- if the parameterdecValue
isnull
NumberFormatException
- if the parameterdecValue
is not a number of the decimal systemIllegalArgumentException
- ifdecValue
is an empty string
-
setOct
public void setOct(String octValue) throws NullPointerException, NumberFormatException, IllegalArgumentException
Sets the value of thisChangeableNumber
to the value of an octal string- Specified by:
setOct
in interfaceChangeableNumber
- Parameters:
octValue
- New value that is represented as an octal string by this class- Throws:
NullPointerException
- if the parameteroctValue
isnull
NumberFormatException
- if the parameteroctValue
is not a number of the octal systemIllegalArgumentException
- ifoctValue
is an empty string
-
setBin
public void setBin(String binValue) throws NullPointerException, NumberFormatException, IllegalArgumentException
Sets the value of thisChangeableNumber
to the value of a binary string- Specified by:
setBin
in interfaceChangeableNumber
- Parameters:
binValue
- New value that is represented as a binary string by this class- Throws:
NullPointerException
- if the parameterbinValue
isnull
NumberFormatException
- if the parameterbinValue
is not a number of the binary systemIllegalArgumentException
- ifbinValue
is an empty string
-
setValue
public void setValue(String value, int baseOfValue) throws NullPointerException, NumberFormatException, IllegalArgumentException
Sets the value of thisChangeableNumber
to a value of any numeral system- Specified by:
setValue
in interfaceChangeableNumber
- Parameters:
value
- New value that is represented as string by this classbaseOfValue
- Base of the numeral system ofvalue
- Throws:
NullPointerException
- if the parametervalue
isnull
NumberFormatException
- if the parametervalue
is not a number of the binary systemIllegalArgumentException
- ifvalue
is an empty string or ifbaseOfValue
leaves 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 thisChangeableNumber
to a value of one of both IEEE standards (16 Bit or 32 Bit)- Specified by:
setIEEE
in 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 parameterieee
isnull
NumberFormatException
- if the parameterieee
is not a number of the binary system or has more characters than 16 respectively 32IllegalArgumentException
- ifieee
is an empty String orstandard
is 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:
reset
in interfaceChangeableNumber
-
toHexString
public String toHexString()
Returns the string representation of thisChangeableNumber
as a hexadecimal string.The string is not labeled as hexadecimal, so the prefix is not leading!
- Specified by:
toHexString
in interfaceChangeableNumber
- Returns:
- hexadecimal string representation of this
ChangeableNumber
-
toDecString
public String toDecString()
Returns the string representation of thisChangeableNumber
as a decimal string.- Specified by:
toDecString
in interfaceChangeableNumber
- Returns:
- decimal string representation of this
ChangeableNumber
-
toOctString
public String toOctString()
Returns the string representation of thisChangeableNumber
as an octal string.The string is not labeled as octal, so the prefix is not leading!
- Specified by:
toOctString
in interfaceChangeableNumber
- Returns:
- octal string representation of this
ChangeableNumber
-
toBinString
public String toBinString()
Returns the string representation of thisChangeableNumber
as a binary string.The string is not labeled as binary, so the prefix is not leading!
- Specified by:
toBinString
in interfaceChangeableNumber
- Returns:
- binary string representation of this
ChangeableNumber
-
toBaseString
public String toBaseString(int base) throws IllegalArgumentException
Returns the string representation of thisChangeableNumber
to any base.The String is not labeled by a prefix!
- Specified by:
toBaseString
in interfaceChangeableNumber
- Parameters:
base
- Base of the numeral system, in which thisChangeableNumber
is represented- Returns:
- String representation of this
ChangeableNumber
to the committed base - Throws:
IllegalArgumentException
- ifbase
leaves the range of values [2, 36] - seeConvertingNumbers.isValueToBase(int, String)
-
toString
public String toString()
Returns aString
that 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 thisChangeableNumber
as IEEE standard String.- Specified by:
toIEEEString
in 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:
stringProperty
in interfaceChangeableNumber
- Returns:
-
logicStringProperty
public javafx.beans.property.ReadOnlyStringProperty logicStringProperty()
- Specified by:
logicStringProperty
in interfaceChangeableNumber
- Returns:
-
baseProperty
public javafx.beans.property.IntegerProperty baseProperty()
- Specified by:
baseProperty
in interfaceChangeableNumber
- Returns:
-
-