public class MappedStringEncoder extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
UNSIGNED |
| Constructor and Description |
|---|
MappedStringEncoder()
Creates a blank encoder that is unable to encode or decode any values.
|
MappedStringEncoder(int encodedStringLength,
boolean supportNegativeValues)
Creates a default encoder with a symmetrical encoding matrix.
|
MappedStringEncoder(int encodedStringLength,
int signIndex)
Creates a default encoder with a symmetrical encoding matrix.
|
| Modifier and Type | Method and Description |
|---|---|
void |
buildEncodingMatrix(char[] columnValues,
int numberOfColumns,
boolean shiftColumnValues)
Builds a symmetrical encoding matrix with the specified parameters.
|
void |
buildEncodingMatrix(char[] columnValues,
int numberOfColumns,
boolean shiftColumnValues,
int signColumnIndex)
Builds a symmetrical encoding matrix with the specified parameters.
|
long |
decode(String encoded)
Decode a code string back to a number.
|
String |
encode(long number,
boolean pad)
Encodes a number to a code string.
|
static MappedStringEncoder |
forMaximumValue(long maxValue,
boolean supportNegativeValues)
Will create the shortest possible encoder that can encode the maximum value specified.
|
int |
getCodeLength() |
long |
getMaxValue() |
long |
getMinValue() |
boolean |
isNegativeValuesSupported() |
void |
setEncodingMatrix(char[][] encodingMatrix)
Sets the encoding matrix to use for encoding/decoding unsigned values.
|
void |
setEncodingMatrix(char[][] encodingMatrix,
int signIndex)
Sets the encoding matrix to use.
|
public static final int UNSIGNED
public MappedStringEncoder()
setEncodingMatrix(char[][]).public MappedStringEncoder(int encodedStringLength,
boolean supportNegativeValues)
encodedStringLength - Length of a generated - fully padded - code.supportNegativeValues - True if a position should be sacrificed to encode the sign.public MappedStringEncoder(int encodedStringLength,
int signIndex)
encodedStringLength - Length of a generated - fully padded - code.signIndex - Index of the position where the sign value should be.public void setEncodingMatrix(char[][] encodingMatrix)
encodingMatrix - Character matrix to use for encoding/decoding.public void setEncodingMatrix(char[][] encodingMatrix,
int signIndex)
encodingMatrix - Character matrix to use for encoding/decoding.signIndex - Index of the position where the sign value should be.public void buildEncodingMatrix(char[] columnValues,
int numberOfColumns,
boolean shiftColumnValues)
columnValues - The possible values for a single position.numberOfColumns - Number of positions in the code - also the code length.shiftColumnValues - True if column values should be shifted for every position.public void buildEncodingMatrix(char[] columnValues,
int numberOfColumns,
boolean shiftColumnValues,
int signColumnIndex)
columnValues - The possible values for a single position.numberOfColumns - Number of positions in the code - also the code length.shiftColumnValues - True if column values should be shifted for every position.signColumnIndex - Index of the position where the sign value should be.public String encode(long number, boolean pad)
number - Number to encode.pad - True if resulting code should be padded to the full length.IllegalArgumentException - in case the number cannot be encodedpublic long decode(String encoded)
encoded - Code string.IllegalArgumentException - if the code cannot be decoded with this encoder instance.public int getCodeLength()
public boolean isNegativeValuesSupported()
public long getMaxValue()
public long getMinValue()
public static MappedStringEncoder forMaximumValue(long maxValue, boolean supportNegativeValues)
maxValue - Maximum value that needs to be encoded.supportNegativeValues - True if negative values need to be encodable as well.Copyright © 2017. All rights reserved.