// check all the products for duplicates by comparing PDSs
if( checkPDS ) {
HashMap<Long, Integer> pdsMap = new HashMap<Long, Integer>();
ArrayList<Integer> duplicate1 = new ArrayList<Integer>();
ArrayList<Integer> duplicate2 = new ArrayList<Integer>();
CRC32 crc32 = new CRC32();
// initialize pdsMap with already indexed records
int originalSize = recordList.size();
for (int i = 0; i < recordList.size(); i++) {
Grib2WriteIndex.RawRecord rr = recordList.get( i );
crc32.reset();
crc32.update( rr.pdsData );
ByteBuffer bb = ByteBuffer.allocate(12);
bb.putInt( rr.discipline );
bb.putLong( rr.refTime );
crc32.update(bb.array());
pdsMap.put( crc32.getValue(), i );
}
Calendar cal = Calendar.getInstance();
// now check new records for duplicates, assumes original index has no duplicates
for (int i = 0; i < products.size(); i++) {
Grib2Product product = products.get( i );
crc32.reset();
crc32.update(product.getPDS().getPdsVars().getPDSBytes());
ByteBuffer bb = ByteBuffer.allocate(12);
bb.putInt( product.getDiscipline());
bb.putLong( product.getRefTime());
crc32.update(bb.array());
long crcv = crc32.getValue();
Integer recnum = pdsMap.get(crcv);
// duplicate found
if ( recnum != null) {
StringBuilder str = new StringBuilder( "Duplicate record with Discipline " );
str.append( product.getDiscipline() );