Package com.google.zxing.common
Class MinimalECIInput
- java.lang.Object
-
- com.google.zxing.common.MinimalECIInput
-
- All Implemented Interfaces:
ECIInput
- Direct Known Subclasses:
MinimalEncoder.Input
public class MinimalECIInput extends java.lang.Object implements ECIInput
Class that converts a character string into a sequence of ECIs and bytes The implementation uses the Dijkstra algorithm to produce minimal encodings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classMinimalECIInput.InputEdge
-
Field Summary
Fields Modifier and Type Field Description private int[]bytesprivate static intCOST_PER_ECIprivate intfnc1
-
Constructor Summary
Constructors Constructor Description MinimalECIInput(java.lang.String stringToEncode, java.nio.charset.Charset priorityCharset, int fnc1)Constructs a minimal input
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static voidaddEdge(MinimalECIInput.InputEdge[][] edges, int to, MinimalECIInput.InputEdge edge)(package private) static voidaddEdges(java.lang.String stringToEncode, ECIEncoderSet encoderSet, MinimalECIInput.InputEdge[][] edges, int from, MinimalECIInput.InputEdge previous, int fnc1)charcharAt(int index)Returns thebytevalue at the specified index.(package private) static int[]encodeMinimally(java.lang.String stringToEncode, ECIEncoderSet encoderSet, int fnc1)intgetECIValue(int index)Returns theintECI value at the specified index.intgetFNC1Character()booleanhaveNCharacters(int index, int n)booleanisECI(int index)Determines if a value is an ECIbooleanisFNC1(int index)Determines if a value is the FNC1 characterintlength()Returns the length of this input.java.lang.CharSequencesubSequence(int start, int end)Returns aCharSequencethat is a subsequence of this sequence.java.lang.StringtoString()
-
-
-
Field Detail
-
COST_PER_ECI
private static final int COST_PER_ECI
- See Also:
- Constant Field Values
-
bytes
private final int[] bytes
-
fnc1
private final int fnc1
-
-
Constructor Detail
-
MinimalECIInput
public MinimalECIInput(java.lang.String stringToEncode, java.nio.charset.Charset priorityCharset, int fnc1)Constructs a minimal input- Parameters:
stringToEncode- the character string to encodepriorityCharset- The preferredCharset. When the value of the argument is null, the algorithm chooses charsets that leads to a minimal representation. Otherwise the algorithm will use the priority charset to encode any character in the input that can be encoded by it if the charset is among the supported charsets.fnc1- denotes the character in the input that represents the FNC1 character or -1 if this is not GS1 input.
-
-
Method Detail
-
getFNC1Character
public int getFNC1Character()
-
length
public int length()
Returns the length of this input. The length is the number ofbytes, FNC1 characters or ECIs in the sequence.
-
haveNCharacters
public boolean haveNCharacters(int index, int n)- Specified by:
haveNCharactersin interfaceECIInput
-
charAt
public char charAt(int index)
Returns thebytevalue at the specified index. An index ranges from zero tolength() - 1. The firstbytevalue of the sequence is at index zero, the next at index one, and so on, as for array indexing.- Specified by:
charAtin interfaceECIInput- Parameters:
index- the index of thebytevalue to be returned- Returns:
- the specified
bytevalue as character or the FNC1 character - Throws:
java.lang.IndexOutOfBoundsException- if theindexargument is negative or not less thanlength()java.lang.IllegalArgumentException- if the value at theindexargument is an ECI (@see #isECI)
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)Returns aCharSequencethat is a subsequence of this sequence. The subsequence starts with thecharvalue at the specified index and ends with thecharvalue at indexend - 1. The length (inchars) of the returned sequence isend - start, so ifstart == endthen an empty sequence is returned.- Specified by:
subSequencein interfaceECIInput- Parameters:
start- the start index, inclusiveend- the end index, exclusive- Returns:
- the specified subsequence
- Throws:
java.lang.IndexOutOfBoundsException- ifstartorendare negative, ifendis greater thanlength(), or ifstartis greater thanendjava.lang.IllegalArgumentException- if a value in the rangestart-endis an ECI (@see #isECI)
-
isECI
public boolean isECI(int index)
Determines if a value is an ECI
-
isFNC1
public boolean isFNC1(int index)
Determines if a value is the FNC1 character- Parameters:
index- the index of the value- Returns:
- true if the value at position
indexis the FNC1 character - Throws:
java.lang.IndexOutOfBoundsException- if theindexargument is negative or not less thanlength()
-
getECIValue
public int getECIValue(int index)
Returns theintECI value at the specified index. An index ranges from zero tolength() - 1. The firstbytevalue of the sequence is at index zero, the next at index one, and so on, as for array indexing.- Specified by:
getECIValuein interfaceECIInput- Parameters:
index- the index of theintvalue to be returned- Returns:
- the specified
intECI value. The ECI specified the encoding of all bytes with a higher index until the next ECI or until the end of the input if no other ECI follows. - Throws:
java.lang.IndexOutOfBoundsException- if theindexargument is negative or not less thanlength()java.lang.IllegalArgumentException- if the value at theindexargument is not an ECI (@see #isECI)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
addEdge
static void addEdge(MinimalECIInput.InputEdge[][] edges, int to, MinimalECIInput.InputEdge edge)
-
addEdges
static void addEdges(java.lang.String stringToEncode, ECIEncoderSet encoderSet, MinimalECIInput.InputEdge[][] edges, int from, MinimalECIInput.InputEdge previous, int fnc1)
-
encodeMinimally
static int[] encodeMinimally(java.lang.String stringToEncode, ECIEncoderSet encoderSet, int fnc1)
-
-