java.lang.Object
org.refcodes.numerical.BaseConverterBuilder
- All Implemented Interfaces:
org.refcodes.mixin.CharSetAccessor,org.refcodes.mixin.CharSetAccessor.CharSetBuilder<BaseConverterBuilder>,org.refcodes.mixin.CharSetAccessor.CharSetMutator,org.refcodes.mixin.CharSetAccessor.CharSetProperty,NumberBaseAccessor,NumberBaseAccessor.NumberBaseBuilder<BaseConverterBuilder>,NumberBaseAccessor.NumberBaseMutator,NumberBaseAccessor.NumberBaseProperty
public class BaseConverterBuilder
extends Object
implements org.refcodes.mixin.CharSetAccessor.CharSetProperty, org.refcodes.mixin.CharSetAccessor.CharSetBuilder<BaseConverterBuilder>, NumberBaseAccessor.NumberBaseProperty, NumberBaseAccessor.NumberBaseBuilder<BaseConverterBuilder>
A base converter from and to long values and which may also convert to and
from byte arrays. You set a number base via
withNumberBase(int) or
setNumberBase(int) and you can convert forth and back with
toDigits(long) or toNumber(String).-
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.CharSetPropertyNested classes/interfaces inherited from interface org.refcodes.numerical.NumberBaseAccessor
NumberBaseAccessor.NumberBaseBuilder<B extends NumberBaseAccessor.NumberBaseBuilder<B>>, NumberBaseAccessor.NumberBaseMutator, NumberBaseAccessor.NumberBaseProperty -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longDecodes the given (number base encoded) data to a byte array as of the given number base and the charset for the value's digits.static StringasEncoded(long aNumber, int aNumberBase, char... aCharSet) Encodes the given bytes to aStringas of the given number base and the charset for the value's digits.char[]Retrieves the number base value from the number base value property.longRetrieves the number from the number property.intRetrieves the value from the number base property.voidsetCharSet(char[] aCharSet) voidSets the number base value for the number base value property.voidsetNumber(long aNumber) Sets the number for the number property.voidsetNumberBase(int aNumberBase) Sets the value for the number base property.toDigits(long aNumber) Retrieves the number base value calculated from the number.longRetrieves the number calculated from the provided number base value.withCharSet(char[] aCharSet) withDigits(String aDigits) Sets the number base value for the number base value property.withNumber(long aNumber) Sets the number for the number property.withNumberBase(int aNumberBase) Sets the number base for the number base property.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.refcodes.mixin.CharSetAccessor.CharSetProperty
letCharSetMethods inherited from interface org.refcodes.numerical.NumberBaseAccessor.NumberBaseProperty
letNumberBase
-
Constructor Details
-
BaseConverterBuilder
public BaseConverterBuilder()Instantiates a new base converter builder impl.
-
-
Method Details
-
getCharSet
public char[] getCharSet()- Specified by:
getCharSetin interfaceorg.refcodes.mixin.CharSetAccessor
-
setCharSet
public void setCharSet(char[] aCharSet) - Specified by:
setCharSetin interfaceorg.refcodes.mixin.CharSetAccessor.CharSetMutator
-
withCharSet
- Specified by:
withCharSetin interfaceorg.refcodes.mixin.CharSetAccessor.CharSetBuilder<BaseConverterBuilder>
-
setNumberBase
public void setNumberBase(int aNumberBase) Sets the value for the number base property.- Specified by:
setNumberBasein 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:
getNumberBasein interfaceNumberBaseAccessor- Returns:
- The name stored by the number base property.
-
toDigits
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).- 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.- Returns:
- The number stored by the number property.
-
toNumber
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).- Parameters:
aDigits- The number base value to be decoded.- Returns:
- The number decoded from the number base value.
- Throws:
IllegalArgumentException- the illegal argument exception
-
setNumber
public void setNumber(long aNumber) Sets the number for the number property.- Parameters:
aNumber- The number to be stored by the number property.
-
getDigits
Retrieves the number base value from the number base value property.- Returns:
- The number base value stored by the number base value property.
-
setDigits
Sets the number base value for the number base value property.- Parameters:
aDigits- The number base value to be stored by the number base value property.
-
withNumberBase
Sets the number base for the number base property.- Specified by:
withNumberBasein interfaceNumberBaseAccessor.NumberBaseBuilder<BaseConverterBuilder>- Parameters:
aNumberBase- The number base to be stored by the number base property.- Returns:
- The builder for applying multiple build operations.
-
withDigits
Sets the number base value for the number base value property.- Parameters:
aDigits- The number base value to be stored by the number base value property.- Returns:
- The builder for applying multiple build operations.
-
withNumber
Sets the number for the number property.- Parameters:
aNumber- The number to be stored by the number property.- Returns:
- The builder for applying multiple build operations.
-
asEncoded
Encodes the given bytes to aStringas of the given number base and the charset for the value's digits.- Parameters:
aNumber- The data to be encoded.aNumberBase- The number base to be used for encoding.aCharSet- The charset to be used for the digits of the targeted number base.- Returns:
- Returns the accordingly encoded data as a
String.
-
asDecoded
Decodes the given (number base encoded) data to a byte array as of the given number base and the charset for the value's digits.- Parameters:
aDigits- The (number base encoded) data to be decoded.aNumberBase- The number base to be used for decoding.aCharSet- The charset to be used for the digits of the used number base.- Returns:
- Returns the accordingly decoded data .
-