Package org.refcodes.numerical
Class BaseConverterBuilderImpl
- java.lang.Object
-
- org.refcodes.numerical.BaseConverterBuilderImpl
-
- All Implemented Interfaces:
org.refcodes.mixin.CharSetAccessor
,org.refcodes.mixin.CharSetAccessor.CharSetBuilder<BaseConverterBuilder>
,org.refcodes.mixin.CharSetAccessor.CharSetMutator
,org.refcodes.mixin.CharSetAccessor.CharSetProperty
,BaseConverterBuilder
,NumberBaseAccessor
,NumberBaseAccessor.NumberBaseBuilder<BaseConverterBuilder>
,NumberBaseAccessor.NumberBaseMutator
,NumberBaseAccessor.NumberBaseProperty
public class BaseConverterBuilderImpl extends java.lang.Object implements BaseConverterBuilder
This is a hacky implementation of theBaseConverterBuilder
interface breaking with anIllegalArgumentException
in case the numbers to be converted are too large for the algorithm.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.CharSetAccessor
org.refcodes.mixin.CharSetAccessor.CharSetBuilder<B extends org.refcodes.mixin.CharSetAccessor.CharSetBuilder<B>>, org.refcodes.mixin.CharSetAccessor.CharSetMutator, org.refcodes.mixin.CharSetAccessor.CharSetProperty
-
Nested classes/interfaces inherited from interface org.refcodes.numerical.NumberBaseAccessor
NumberBaseAccessor.NumberBaseBuilder<B extends NumberBaseAccessor.NumberBaseBuilder<B>>, NumberBaseAccessor.NumberBaseMutator, NumberBaseAccessor.NumberBaseProperty
-
-
Constructor Summary
Constructors Constructor Description BaseConverterBuilderImpl()
Instantiates a new base converter builder impl.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description char[]
getCharSet()
long
getNumber()
Retrieves the number from the number property.int
getNumberBase()
Retrieves the value from the number base property.java.lang.String
getNumberBaseValue()
Retrieves the number base value from the number base value property.byte[]
getNumberData()
Retrieves the number from the number property.void
setCharSet(char[] aCharSet)
void
setNumber(long aNumber)
Sets the number for the number property.void
setNumberBase(int aNumberBase)
Sets the value for the number base property.void
setNumberBaseValue(java.lang.String aNumberBaseValue)
Sets the number base value for the number base value property.void
setNumberData(byte[] aNumberData)
Sets the number for the number property.long
toNumber(java.lang.String aNumberBaseValue)
Retrieves the number calculated from the provided number base value.java.lang.String
toNumberBaseValue(byte[] aNumberData)
Retrieves the number base value calculated from the number.java.lang.String
toNumberBaseValue(long aNumber)
Retrieves the number base value calculated from the number.byte[]
toNumberData(java.lang.String aNumberBaseValue)
Retrieves the number calculated from the provided number base value.protected static java.lang.String
toVerboseString(byte[] aBytes)
TODO: This helper is required to help making the code break when it reaches its bad implementations.BaseConverterBuilder
withCharSet(char[] aCharSet)
-
Methods inherited from interface org.refcodes.numerical.BaseConverterBuilder
withNumber, withNumberBase, withNumberBaseValue, withNumberData
-
-
-
-
Method Detail
-
getCharSet
public char[] getCharSet()
- Specified by:
getCharSet
in interfaceorg.refcodes.mixin.CharSetAccessor
-
setCharSet
public void setCharSet(char[] aCharSet)
- Specified by:
setCharSet
in interfaceorg.refcodes.mixin.CharSetAccessor.CharSetMutator
-
withCharSet
public BaseConverterBuilder withCharSet(char[] aCharSet)
- Specified by:
withCharSet
in interfaceorg.refcodes.mixin.CharSetAccessor.CharSetBuilder<BaseConverterBuilder>
-
setNumberBase
public void setNumberBase(int aNumberBase)
Sets the value for the number base property.- Specified by:
setNumberBase
in interfaceNumberBaseAccessor.NumberBaseMutator
- Parameters:
aNumberBase
- The value to be stored by the number base property.
-
getNumberBase
public int getNumberBase()
Retrieves the value from the number base property.- Specified by:
getNumberBase
in interfaceNumberBaseAccessor
- Returns:
- The name stored by the number base property.
-
toNumberBaseValue
public java.lang.String toNumberBaseValue(long aNumber)
Retrieves the number base value calculated from the number. This method is to be side effect free in terms of the number (and the encoded result) is not part of the state for this instance (from the point of view of this method). For avoiding thread race conditions / side effects regarding the decoded data (and the encoded result), use this method instead of the combination ofBaseConverterBuilder.withNumberData(byte[])
withBaseConverterBuilder.getNumberBaseValue()
- Specified by:
toNumberBaseValue
in interfaceBaseConverterBuilder
- Parameters:
aNumber
- The number to be encoded.- Returns:
- The number base value calculated from the number.
-
getNumber
public long getNumber()
Retrieves the number from the number property.- Specified by:
getNumber
in interfaceBaseConverterBuilder
- Returns:
- The number stored by the number property.
-
toNumber
public long toNumber(java.lang.String aNumberBaseValue) throws java.lang.IllegalArgumentException
Retrieves the number calculated from the provided number base value. This method is to be side effect free in terms of the number base value (and the decoded result) is not part of the state for this instance (from the point of view of this method). For avoiding thread race conditions / side effects regarding the encoded text (and the decoded result), use this method instead of the combination ofBaseConverterBuilder.withNumberBaseValue(String)
withBaseConverterBuilder.getNumberData()
.- Specified by:
toNumber
in interfaceBaseConverterBuilder
- Parameters:
aNumberBaseValue
- The number base value to be decoded.- Returns:
- The number decoded from the number base value.
- Throws:
java.lang.IllegalArgumentException
- the illegal argument exception
-
setNumber
public void setNumber(long aNumber)
Sets the number for the number property.- Specified by:
setNumber
in interfaceBaseConverterBuilder
- Parameters:
aNumber
- The number to be stored by the number property.
-
getNumberBaseValue
public java.lang.String getNumberBaseValue()
Retrieves the number base value from the number base value property.- Specified by:
getNumberBaseValue
in interfaceBaseConverterBuilder
- Returns:
- The number base value stored by the number base value property.
-
setNumberBaseValue
public void setNumberBaseValue(java.lang.String aNumberBaseValue)
Sets the number base value for the number base value property.- Specified by:
setNumberBaseValue
in interfaceBaseConverterBuilder
- Parameters:
aNumberBaseValue
- The number base value to be stored by the number base value property.
-
getNumberData
public byte[] getNumberData()
Retrieves the number from the number property.- Specified by:
getNumberData
in interfaceBaseConverterBuilder
- Returns:
- The number stored by the number property.
-
setNumberData
public void setNumberData(byte[] aNumberData)
Sets the number for the number property.- Specified by:
setNumberData
in interfaceBaseConverterBuilder
- Parameters:
aNumberData
- The number to be stored by the number property.
-
toNumberBaseValue
public java.lang.String toNumberBaseValue(byte[] aNumberData)
Retrieves the number base value calculated from the number. This method is to be side effect free in terms of the number (and the encoded result) is not part of the state for this instance (from the point of view of this method). For avoiding thread race conditions / side effects regarding the decoded data (and the encoded result), use this method instead of the combination ofBaseConverterBuilder.withNumberData(byte[])
withBaseConverterBuilder.getNumberBaseValue()
- Specified by:
toNumberBaseValue
in interfaceBaseConverterBuilder
- Parameters:
aNumberData
- The number to be encoded.- Returns:
- The number base value calculated from the number.
-
toNumberData
public byte[] toNumberData(java.lang.String aNumberBaseValue)
Retrieves the number calculated from the provided number base value. This method is to be side effect free in terms of the number base value (and the decoded result) is not part of the state for this instance (from the point of view of this method). For avoiding thread race conditions / side effects regarding the encoded text (and the decoded result), use this method instead of the combination ofBaseConverterBuilder.withNumberBaseValue(String)
withBaseConverterBuilder.getNumberData()
.- Specified by:
toNumberData
in interfaceBaseConverterBuilder
- Parameters:
aNumberBaseValue
- The number base value to be decoded.- Returns:
- The number decoded from the number base value.
-
toVerboseString
protected static java.lang.String toVerboseString(byte[] aBytes)
TODO: This helper is required to help making the code break when it reaches its bad implementations. Bad bad hack! Remove when code is fixed.- Parameters:
aBytes
- the bytes- Returns:
- the string
-
-