ProductDeDuplicator { public static void deduplicate(List<ProductInventoryEntry> inventory) { long cursorMicros = 0; ProductInventoryEntry cursorEntry = null; for (ProductInventoryEntry entry : inventory) { long startMicros = getMJDMicros(entry.getStartTime()); long endMicros = getMJDMicros(entry.getStopTime()); if (entry.getLength() <= 1 || !entry.getMessage().equalsIgnoreCase("Good") || startMicros == 0 || endMicros == 0) { entry.setProcessLength(0); } else { if (cursorMicros == 0 || startMicros > cursorMicros) { cursorMicros = endMicros; cursorEntry = entry; } else if (endMicros <= cursorMicros) { entry.setProcessLength(0); } else if (startMicros <= cursorMicros) { long perLineMicros = (endMicros - startMicros) / (entry.getLength() - 1); double microOverlap = cursorMicros - startMicros; int overlapLines = (int) Math.round((microOverlap / perLineMicros) + 1); int firstPartLines = overlapLines / 2; int secondPartLines = overlapLines - firstPartLines; cursorEntry.setProcessLength(cursorEntry.getProcessLength() - firstPartLines); entry.setProcessStartLine(secondPartLines); entry.setProcessLength(entry.getLength() - secondPartLines); cursorMicros = endMicros; cursorEntry = entry; } } } } private  ProductDeDuplicator(); static void sort(List<ProductInventoryEntry> inventory); static List<ProductInventoryEntry> missing(List<ProductInventoryEntry> src, List<ProductInventoryEntry> target); static void deduplicate(List<ProductInventoryEntry> inventory); static void printHistogram(List<ProductInventoryEntry> inventory); static DeduplicationStatistics getStatistics(List<ProductInventoryEntry> inventory);  }
@Test public void testDeduplicate() throws Exception { ProductInventoryEntry entry1 = ProductInventoryEntry.create("2001-10-02-13-10-11.123400", "2001-10-02-13-12-14.456789", "100", "0", "100", "Good"); ProductInventoryEntry entry2 = ProductInventoryEntry.create("2001-10-02-13-12-15.456789", "2001-10-02-13-16-14.456789", "200", "0", "200", "Good"); ProductInventoryEntry entry3 = ProductInventoryEntry.create("2001-10-02-13-12-15.456789", "2001-10-02-13-16-14.456789", "200", "0", "200", "Good"); List<ProductInventoryEntry> inventory = new ArrayList<ProductInventoryEntry>(); inventory.add(entry1); inventory.add(entry2); ProductDeDuplicator.deduplicate(inventory); assertEquals(2, inventory.size()); }