Convert from one alphabet to another, with the possibility of leaving certain characters unencoded.
The target and 'do not encode' languages must be in the Unicode BMP, but the source language does not.
The encoding will all be of a fixed length, except for the 'do not encode' chars, which will be of length 1
Character[] originals; // a, b, c, d
Character[] encoding; // 0, 1, d
Character[] doNotEncode; // d
AlphabetConverter ac = AlphabetConverter.createConverterFromChars(originals,
encoding, doNotEncode);
ac.encode("a"); // 00
ac.encode("b"); // 01
ac.encode("c"); // 0d
ac.encode("d"); // d
ac.encode("abcd"); // 00010dd
#ThreadSafe# AlphabetConverter class methods are thread-safe as they do not change internal state.
| Modifier and Type | Field and Description |
|---|---|
| private static final String | ARROW
Arrow constant, used for converting the object into a string. |
| private final int | encodedLetterLength
Length of the encoded letter. |
| private final Map | encodedToOriginal
Encoding alphabet. |
| private final Map | originalToEncoded
Original string to be encoded. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private void | addSingleEncoding(final int
at which point it should add a single encoding. level, final String current encoding. currentEncoding, final Collection<Integer> letters encoding. encoding, final Iterator<Integer> original values. originals, final Map<Integer, String> map of values that should not be encoded. doNotEncodeMap)Recursive method used when creating encoder/decoder. |
| private static String | Returns: a new string with the new code point.code point. i)Creates new String that contains just the given code point. |
| private static Integer[] | Returns: an equivalent array of integers.array of characters. chars)Converts characters to integers. |
| public static AlphabetConverter | Returns: The AlphabetConverter.an array of ints representing the original alphabet in code points. original, final Integer[] an array of ints representing the alphabet to be used for encoding, in code points. encoding, final Integer[] an array of ints representing the chars to be encoded using the original alphabet - every char here must appear in both the previous
params. doNotEncode)Creates an alphabet converter, for converting from the original alphabet, to the encoded alphabet, while leaving the characters in doNotEncode as they are (if possible). |
| public static AlphabetConverter | Returns: The AlphabetConverteran array of chars representing the original alphabet original, final Character[] an array of chars representing the alphabet to be used
for encoding encoding, final Character[] an array of chars to be encoded using the original
alphabet - every char here must appear in
both the previous params doNotEncode)Creates an alphabet converter, for converting from the original alphabet, to the encoded alphabet, while leaving the characters in doNotEncode as they are (if possible). |
| public static AlphabetConverter | Returns: The reconstructed AlphabetConverter.a map returned from getOriginalToEncoded(). originalToEncoded)Creates a new converter from a map. |
| public String | |
| public String | |
| public boolean | equals(final Object obj)
Overrides java. Indicates whether some other object is "equal to" this one. |
| public int | Returns: The length of the encoded char.Gets the length of characters in the encoded alphabet that are necessary for each character in the original alphabet. |
| public Map | Returns: The original map.Gets the mapping from integer code point of source language to encoded string. |
| public int | |
| public String |
| ARROW | back to summary |
|---|---|
| private static final String ARROW Arrow constant, used for converting the object into a string. | |
| encodedLetterLength | back to summary |
|---|---|
| private final int encodedLetterLength Length of the encoded letter. | |
| encodedToOriginal | back to summary |
|---|---|
| private final Map<String, String> encodedToOriginal Encoding alphabet. | |
| originalToEncoded | back to summary |
|---|---|
| private final Map<Integer, String> originalToEncoded Original string to be encoded. | |
| AlphabetConverter | back to summary |
|---|---|
| private AlphabetConverter(final Map<Integer, String> originalToEncoded, final Map<String, String> encodedToOriginal, final int encodedLetterLength) Hidden constructor for alphabet converter. Used by static helper methods. | |
| addSingleEncoding | back to summary |
|---|---|
| private void addSingleEncoding(final int level, final String currentEncoding, final Collection<Integer> encoding, final Iterator<Integer> originals, final Map<Integer, String> doNotEncodeMap) Recursive method used when creating encoder/decoder. | |
| codePointToString | back to summary |
|---|---|
| private static String codePointToString(final int i) Creates new String that contains just the given code point.
| |
| convertCharsToIntegers | back to summary |
|---|---|
| private static Integer[] convertCharsToIntegers(final Character[] chars) Converts characters to integers. | |
| createConverter | back to summary |
|---|---|
| public static AlphabetConverter createConverter(final Integer[] original, final Integer[] encoding, final Integer[] doNotEncode) Creates an alphabet converter, for converting from the original alphabet, to the encoded alphabet, while leaving the characters in doNotEncode as they are (if possible). Duplicate letters in either original or encoding will be ignored.
| |
| createConverterFromChars | back to summary |
|---|---|
| public static AlphabetConverter createConverterFromChars(final Character[] original, final Character[] encoding, final Character[] doNotEncode) Creates an alphabet converter, for converting from the original alphabet, to the encoded alphabet, while leaving the characters in doNotEncode as they are (if possible). Duplicate letters in either original or encoding will be ignored.
| |
| createConverterFromMap | back to summary |
|---|---|
| public static AlphabetConverter createConverterFromMap(final Map<Integer, String> originalToEncoded) Creates a new converter from a map.
| |
| decode | back to summary |
|---|---|
| public String decode(final String encoded) throws UnsupportedEncodingException Decodes a given string.
| |
| encode | back to summary |
|---|---|
| public String encode(final String original) throws UnsupportedEncodingException Encodes a given string.
| |
| equals | back to summary |
|---|---|
| public boolean equals(final Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
| |
| getEncodedCharLength | back to summary |
|---|---|
| public int getEncodedCharLength() Gets the length of characters in the encoded alphabet that are necessary for each character in the original alphabet.
| |
| getOriginalToEncoded | back to summary |
|---|---|
| public Map Gets the mapping from integer code point of source language to encoded string. Use to reconstruct converter from serialized map. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |