ElementDedupeFilterProcessor extends FilterProcessor { @Override public boolean test(final LazyElementCell elementCell) { final Cell cell = elementCell.getCell(); final byte flag = getFlag(cell); final boolean isEdge = flag != HBaseStoreConstants.ENTITY; if (!edges && isEdge) { return false; } if (!entities && !isEdge) { return false; } return !isEdge || testEdge(flag, cell); } ElementDedupeFilterProcessor(final boolean entities, final boolean edges, final DirectedType directedType); @Override boolean test(final LazyElementCell elementCell); boolean isEdges(); boolean isEntities(); boolean isUnDirectedEdges(); boolean isDirectedEdges();  }
@Test public void shouldOnlyAcceptEdges() throws OperationException, SerialisationException { final ElementDedupeFilterProcessor processor = new ElementDedupeFilterProcessor(false, true, DirectedType.EITHER); for (final Element element : ELEMENTS) { final boolean expectedResult = element instanceof Edge; final Pair<LazyElementCell, LazyElementCell> cells = CellUtil.getLazyCells(element, serialisation); assertEquals(expectedResult, processor.test(cells.getFirst()), "Failed for element: " + element.toString()); if (null != cells.getSecond()) { assertEquals(false, processor.test(cells.getSecond()), "Failed for element: " + element.toString()); } } }
@Test public void shouldOnlyAcceptDirectedEdges() throws OperationException, SerialisationException { final ElementDedupeFilterProcessor processor = new ElementDedupeFilterProcessor(false, true, DirectedType.DIRECTED); for (final Element element : ELEMENTS) { final boolean expectedResult = element instanceof Edge && ((Edge) element).isDirected(); final Pair<LazyElementCell, LazyElementCell> cells = CellUtil.getLazyCells(element, serialisation); assertEquals(expectedResult, processor.test(cells.getFirst()), "Failed for element: " + element.toString()); if (null != cells.getSecond()) { assertEquals(false, processor.test(cells.getSecond()), "Failed for element: " + element.toString()); } } }
@Test public void shouldOnlyAcceptUndirectedEdges() throws OperationException, SerialisationException { final ElementDedupeFilterProcessor processor = new ElementDedupeFilterProcessor(false, true, DirectedType.UNDIRECTED); for (final Element element : ELEMENTS) { final boolean expectedResult = element instanceof Edge && !((Edge) element).isDirected(); final Pair<LazyElementCell, LazyElementCell> cells = CellUtil.getLazyCells(element, serialisation); assertEquals(expectedResult, processor.test(cells.getFirst()), "Failed for element: " + element.toString()); if (null != cells.getSecond()) { assertEquals(false, processor.test(cells.getSecond()), "Failed for element: " + element.toString()); } } }
@Test public void shouldAcceptOnlyEntities() throws OperationException, SerialisationException { final ElementDedupeFilterProcessor processor = new ElementDedupeFilterProcessor(true, false, null); for (final Element element : ELEMENTS) { final boolean expectedResult = element instanceof Entity; final Pair<LazyElementCell, LazyElementCell> cells = CellUtil.getLazyCells(element, serialisation); assertEquals(expectedResult, processor.test(cells.getFirst()), "Failed for element: " + element.toString()); if (null != cells.getSecond()) { assertEquals(expectedResult, processor.test(cells.getSecond()), "Failed for element: " + element.toString()); } } }