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 class
MinimalECIInput.InputEdge
-
Field Summary
Fields Modifier and Type Field Description private int[]
bytes
private static int
COST_PER_ECI
private int
fnc1
-
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 void
addEdge(MinimalECIInput.InputEdge[][] edges, int to, MinimalECIInput.InputEdge edge)
(package private) static void
addEdges(java.lang.String stringToEncode, ECIEncoderSet encoderSet, MinimalECIInput.InputEdge[][] edges, int from, MinimalECIInput.InputEdge previous, int fnc1)
char
charAt(int index)
Returns thebyte
value at the specified index.(package private) static int[]
encodeMinimally(java.lang.String stringToEncode, ECIEncoderSet encoderSet, int fnc1)
int
getECIValue(int index)
Returns theint
ECI value at the specified index.int
getFNC1Character()
boolean
haveNCharacters(int index, int n)
boolean
isECI(int index)
Determines if a value is an ECIboolean
isFNC1(int index)
Determines if a value is the FNC1 characterint
length()
Returns the length of this input.java.lang.CharSequence
subSequence(int start, int end)
Returns aCharSequence
that is a subsequence of this sequence.java.lang.String
toString()
-
-
-
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 ofbyte
s, FNC1 characters or ECIs in the sequence.
-
haveNCharacters
public boolean haveNCharacters(int index, int n)
- Specified by:
haveNCharacters
in interfaceECIInput
-
charAt
public char charAt(int index)
Returns thebyte
value at the specified index. An index ranges from zero tolength() - 1
. The firstbyte
value of the sequence is at index zero, the next at index one, and so on, as for array indexing.- Specified by:
charAt
in interfaceECIInput
- Parameters:
index
- the index of thebyte
value to be returned- Returns:
- the specified
byte
value as character or the FNC1 character - Throws:
java.lang.IndexOutOfBoundsException
- if theindex
argument is negative or not less thanlength()
java.lang.IllegalArgumentException
- if the value at theindex
argument is an ECI (@see #isECI)
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)
Returns aCharSequence
that is a subsequence of this sequence. The subsequence starts with thechar
value at the specified index and ends with thechar
value at indexend - 1
. The length (inchar
s) of the returned sequence isend - start
, so ifstart == end
then an empty sequence is returned.- Specified by:
subSequence
in interfaceECIInput
- Parameters:
start
- the start index, inclusiveend
- the end index, exclusive- Returns:
- the specified subsequence
- Throws:
java.lang.IndexOutOfBoundsException
- ifstart
orend
are negative, ifend
is greater thanlength()
, or ifstart
is greater thanend
java.lang.IllegalArgumentException
- if a value in the rangestart
-end
is 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
index
is the FNC1 character - Throws:
java.lang.IndexOutOfBoundsException
- if theindex
argument is negative or not less thanlength()
-
getECIValue
public int getECIValue(int index)
Returns theint
ECI value at the specified index. An index ranges from zero tolength() - 1
. The firstbyte
value of the sequence is at index zero, the next at index one, and so on, as for array indexing.- Specified by:
getECIValue
in interfaceECIInput
- Parameters:
index
- the index of theint
value to be returned- Returns:
- the specified
int
ECI 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 theindex
argument is negative or not less thanlength()
java.lang.IllegalArgumentException
- if the value at theindex
argument is not an ECI (@see #isECI)
-
toString
public java.lang.String toString()
- Overrides:
toString
in 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)
-
-