Simplified two loops with goto and fixed (?) a logic error in removing rows. Use raw contents as display text for RSS expanded since not all have a product ID.

git-svn-id: https://zxing.googlecode.com/svn/trunk@2514 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-11-12 19:39:50 +00:00
parent bbeafcb82e
commit ef33d45809
4 changed files with 36 additions and 18 deletions

View file

@ -37,6 +37,7 @@ public final class ExpandedProductParsedResult extends ParsedResult {
public static final String KILOGRAM = "KG"; public static final String KILOGRAM = "KG";
public static final String POUND = "LB"; public static final String POUND = "LB";
private final String rawText;
private final String productID; private final String productID;
private final String sscc; private final String sscc;
private final String lotNumber; private final String lotNumber;
@ -53,7 +54,8 @@ public final class ExpandedProductParsedResult extends ParsedResult {
// For AIS that not exist in this object // For AIS that not exist in this object
private final Map<String,String> uncommonAIs; private final Map<String,String> uncommonAIs;
public ExpandedProductParsedResult(String productID, public ExpandedProductParsedResult(String rawText,
String productID,
String sscc, String sscc,
String lotNumber, String lotNumber,
String productionDate, String productionDate,
@ -68,6 +70,7 @@ public final class ExpandedProductParsedResult extends ParsedResult {
String priceCurrency, String priceCurrency,
Map<String,String> uncommonAIs) { Map<String,String> uncommonAIs) {
super(ParsedResultType.PRODUCT); super(ParsedResultType.PRODUCT);
this.rawText = rawText;
this.productID = productID; this.productID = productID;
this.sscc = sscc; this.sscc = sscc;
this.lotNumber = lotNumber; this.lotNumber = lotNumber;
@ -134,6 +137,10 @@ public final class ExpandedProductParsedResult extends ParsedResult {
return o == null ? 0 : o.hashCode(); return o == null ? 0 : o.hashCode();
} }
public String getRawText() {
return rawText;
}
public String getProductID() { public String getProductID() {
return productID; return productID;
} }
@ -192,6 +199,6 @@ public final class ExpandedProductParsedResult extends ParsedResult {
@Override @Override
public String getDisplayResult() { public String getDisplayResult() {
return String.valueOf(productID); return String.valueOf(rawText);
} }
} }

View file

@ -133,7 +133,8 @@ public final class ExpandedProductResultParser extends ResultParser {
} }
} }
return new ExpandedProductParsedResult(productID, return new ExpandedProductParsedResult(rawText,
productID,
sscc, sscc,
lotNumber, lotNumber,
productionDate, productionDate,

View file

@ -39,6 +39,7 @@ import com.google.zxing.oned.rss.RSSUtils;
import com.google.zxing.oned.rss.expanded.decoders.AbstractExpandedDecoder; import com.google.zxing.oned.rss.expanded.decoders.AbstractExpandedDecoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Collections; import java.util.Collections;
@ -88,6 +89,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
{ 45, 135, 194, 160, 58, 174, 100, 89} { 45, 135, 194, 160, 58, 174, 100, 89}
}; };
/*
private static final int FINDER_PAT_A = 0; private static final int FINDER_PAT_A = 0;
private static final int FINDER_PAT_B = 1; private static final int FINDER_PAT_B = 1;
private static final int FINDER_PAT_C = 2; private static final int FINDER_PAT_C = 2;
@ -109,13 +111,14 @@ public final class RSSExpandedReader extends AbstractRSSReader {
}; };
private static final int LONGEST_SEQUENCE_SIZE = FINDER_PATTERN_SEQUENCES[FINDER_PATTERN_SEQUENCES.length - 1].length; private static final int LONGEST_SEQUENCE_SIZE = FINDER_PATTERN_SEQUENCES[FINDER_PATTERN_SEQUENCES.length - 1].length;
*/
private static final int MAX_PAIRS = 11; private static final int MAX_PAIRS = 11;
private final List<ExpandedPair> pairs = new ArrayList<ExpandedPair>(MAX_PAIRS); private final List<ExpandedPair> pairs = new ArrayList<ExpandedPair>(MAX_PAIRS);
private final List<ExpandedRow> rows = new ArrayList<ExpandedRow>(); private final List<ExpandedRow> rows = new ArrayList<ExpandedRow>();
private final int [] startEnd = new int[2]; private final int [] startEnd = new int[2];
private final int [] currentSequence = new int[LONGEST_SEQUENCE_SIZE]; //private final int [] currentSequence = new int[LONGEST_SEQUENCE_SIZE];
private boolean startFromEven = false; private boolean startFromEven = false;
@Override @Override
@ -217,7 +220,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
break; break;
} }
prevIsSame = erow.isEquivalent(this.pairs); prevIsSame = erow.isEquivalent(this.pairs);
insertPos += 1; insertPos++;
} }
if (nextIsSame || prevIsSame) { if (nextIsSame || prevIsSame) {
return; return;
@ -239,11 +242,12 @@ public final class RSSExpandedReader extends AbstractRSSReader {
// Remove all the rows that contains only specified pairs // Remove all the rows that contains only specified pairs
private static void removePartialRows(List<ExpandedPair> pairs, List<ExpandedRow> rows) { private static void removePartialRows(List<ExpandedPair> pairs, List<ExpandedRow> rows) {
check: for (Iterator<ExpandedRow> iterator = rows.iterator(); iterator.hasNext(); ) {
for (ExpandedRow r : rows) { ExpandedRow r = iterator.next();
if (r.getPairs().size() == pairs.size()) { if (r.getPairs().size() == pairs.size()) {
continue; continue;
} }
boolean allFound = true;
for (ExpandedPair p : r.getPairs()) { for (ExpandedPair p : r.getPairs()) {
boolean found = false; boolean found = false;
for (ExpandedPair pp : pairs) { for (ExpandedPair pp : pairs) {
@ -253,21 +257,23 @@ public final class RSSExpandedReader extends AbstractRSSReader {
} }
} }
if (!found) { if (!found) {
continue check; allFound = false;
break;
} }
} }
// 'pairs' contains all the pairs from the row 'r' if (allFound) {
rows.remove(r); // 'pairs' contains all the pairs from the row 'r'
// start from the begining iterator.remove();
removePartialRows(pairs, rows); // start from the begining
return; removePartialRows(pairs, rows);
}
} }
} }
// Returns true when one of the rows already contains all the pairs // Returns true when one of the rows already contains all the pairs
private static boolean isPartialRow(Iterable<ExpandedPair> pairs, Iterable<ExpandedRow> rows) { private static boolean isPartialRow(Iterable<ExpandedPair> pairs, Iterable<ExpandedRow> rows) {
check:
for (ExpandedRow r : rows) { for (ExpandedRow r : rows) {
boolean allFound = true;
for (ExpandedPair p : pairs) { for (ExpandedPair p : pairs) {
boolean found = false; boolean found = false;
for (ExpandedPair pp : r.getPairs()) { for (ExpandedPair pp : r.getPairs()) {
@ -277,11 +283,14 @@ public final class RSSExpandedReader extends AbstractRSSReader {
} }
} }
if (!found) { if (!found) {
continue check; allFound = false;
break;
} }
} }
// the row 'r' contain all the pairs from 'pairs' if (allFound) {
return true; // the row 'r' contain all the pairs from 'pairs'
return true;
}
} }
return false; return false;
} }

View file

@ -64,7 +64,8 @@ public final class RSSExpandedImage2resultTestCase extends Assert {
// (01)90012345678908(3103)001750 // (01)90012345678908(3103)001750
String path = "test/data/blackbox/rssexpanded-1/2.jpg"; String path = "test/data/blackbox/rssexpanded-1/2.jpg";
ExpandedProductParsedResult expected = ExpandedProductParsedResult expected =
new ExpandedProductParsedResult("90012345678908", new ExpandedProductParsedResult("(01)90012345678908(3103)001750",
"90012345678908",
null, null, null, null, null, null, null, null, null, null, null, null,
"001750", "001750",
ExpandedProductParsedResult.KILOGRAM, ExpandedProductParsedResult.KILOGRAM,