CellDeduplicationHelper { public static List<Cell> deduplicateFamily(Mutation mutation, byte[] family) { List<Cell> result = new LinkedList<>(); Map<QualifierOnlyKey, Cell> latestCells = new HashMap<>(); List<Cell> familyCells = mutation.getFamilyCellMap().get(family); if (familyCells == null || family.length == 0) { return new LinkedList<>(); } for (Cell cell : familyCells) { QualifierOnlyKey key = new QualifierOnlyKey(CellUtil.cloneQualifier(cell)); latestCells.put(key, cell); } result.addAll(latestCells.values()); return result; }  static List<Cell> deduplicateFamily(Mutation mutation, byte[] family);  }
@Test public void testCellsAreDeduplicated() { Append append = new Append(Bytes.toBytes("Ignored")); append.add(Bytes.toBytes("fam1"), Bytes.toBytes("qual1"), Bytes.toBytes("val1.1")); append.add(Bytes.toBytes("fam1"), Bytes.toBytes("qual2"), Bytes.toBytes("val2.1")); append.add(Bytes.toBytes("fam1"), Bytes.toBytes("qual1"), Bytes.toBytes("val1.2")); append.add(Bytes.toBytes("fam2"), Bytes.toBytes("qual1"), Bytes.toBytes("val1.2")); List<Cell> deduplicatedCells = CellDeduplicationHelper.deduplicateFamily(append, Bytes.toBytes("fam1")); Assert.assertEquals(2, deduplicatedCells.size()); for (Cell cell : deduplicatedCells) { byte[] family = CellUtil.cloneFamily(cell); Assert.assertArrayEquals(Bytes.toBytes("fam1"), family); if (Arrays.equals(Bytes.toBytes("qual1"), CellUtil.cloneQualifier(cell))) { Assert.assertArrayEquals(Bytes.toBytes("val1.2"), CellUtil.cloneValue(cell)); } else if (Arrays.equals(Bytes.toBytes("qual2"), CellUtil.cloneQualifier(cell))) { Assert.assertArrayEquals(Bytes.toBytes("val2.1"), CellUtil.cloneValue(cell)); } else { Assert.fail( "Unexpected qualifier encountered: " + Bytes.toString(CellUtil.cloneQualifier(cell))); } } }