package org.archive.format.gzip.zipnum; import org.archive.util.iterator.CloseableIterator; public class TimestampCustomDedupIterator extends TimestampDedupIterator { // The additional field used as status field from the timestamp private int additionalFieldNum = 3; private int sep = ' '; public TimestampCustomDedupIterator(CloseableIterator<String> inner, int timestampDedupLength) { super(inner, timestampDedupLength); } @Override protected boolean isSame(String currStamp, String nextStamp, String currLine, String nextLine) { if (!super.isSame(currStamp, nextStamp, currLine, nextLine)) { return false; } //Same only if status code also matches String currStatus = getNthField(currLine, currStamp.length(), additionalFieldNum, sep); if (currStatus == null) { return false; } String nextStatus = getNthField(nextLine, nextStamp.length(), additionalFieldNum, sep); if (nextStatus == null) { return false; } return currStatus.equals(nextStatus); } private String getNthField(String source, int start, int num, int ch) { int lastIndex = -1; int index = start; for (int i = 0; i <= num; i++) { lastIndex = index; index = source.indexOf(' ', index) + 1; if (index < 0) { return null; } } return source.substring(lastIndex, index - 1); } }