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

View file

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

View file

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