### Question:
DisplayHierarchyNode { public List<DisplayHierarchyNode> extractByPredicate( Object... properties ) { List<DisplayHierarchyNode> extracted = new ArrayList<DisplayHierarchyNode>(); for (Object p: properties) { Property prop = rdfNode().toProperty( p ); int index = indexOfChildProperty( prop ); if (index >= 0) { extracted.add( children.remove( index ) ); } } return extracted; } DisplayHierarchyNode( PropertyPath pathTo, DisplayHierarchyNode parent,
                                 DisplayRdfNode rdfNode, ShortNameRenderer shortNameRenderer ); PropertyPath pathTo(); RDFNodeWrapper terminalLink(); boolean isOnExplicitPath(); Set<PropertyPath> explicitPaths(); DisplayHierarchyNode parent(); boolean isRoot(); DisplayRdfNode rdfNode(); boolean isLoop(); boolean findAncestor( DisplayRdfNode resource ); boolean isLeaf( DisplayHierarchyContext context ); List<DisplayHierarchyNode> children(); void addSibling( DisplayHierarchyNode sibling ); List<DisplayHierarchyNode> siblings(); boolean hasSiblings(); void addHint( String hint ); String hintsString(); boolean hasHint( String hint ); boolean isSimpleResource(); String relatedLinksHTML(); List<Link> relatedLinks(); boolean hasAllProperties( Object... properties ); boolean hasAllProperties( List<Object> properties ); void pullToStart( Object... properties ); void pullToStart( List<Object> properties ); List<DisplayHierarchyNode> extractByPredicate( Object... properties ); List<DisplayHierarchyNode> extractByPredicate( List<Object> properties ); boolean isResource(); boolean isLiteral(); boolean isAnon(); boolean isList(); String getLexicalForm(); String getName(); Object getValue(); String getURI(); @Override String toString(); static final String SORT_BY_FORMAT; static final int MAX_RELATED_LINK_LABEL_LENGTH; }### Answer:
@Test public void testExtractByPredicate() { String ns = "http: Property p1 = ResourceFactory.createProperty( ns + "p1" ); Property p2 = ResourceFactory.createProperty( ns + "p2" ); Property p3 = ResourceFactory.createProperty( ns + "p3" ); Property p4 = ResourceFactory.createProperty( ns + "p4" ); Resource r1 = ResourceFactory.createResource( ns+"r1"); new DisplayHierarchyNode( dhn.pathTo().append( "p1", p1.getURI(), null ), dhn, new DisplayRdfNode( rm.page(), r1 ), null ); Resource r2 = ResourceFactory.createResource( ns+"r2"); new DisplayHierarchyNode( dhn.pathTo().append( "p2", p2.getURI(), null ), dhn, new DisplayRdfNode( rm.page(), r2 ), null ); Resource r3 = ResourceFactory.createResource( ns+"r3"); new DisplayHierarchyNode( dhn.pathTo().append( "p3", p3.getURI(), null ), dhn, new DisplayRdfNode( rm.page(), r3 ), null ); assertEquals( r1, dhn.children().get( 0 ).rdfNode().asResource() ); assertEquals( r2, dhn.children().get( 1 ).rdfNode().asResource() ); assertEquals( r3, dhn.children().get( 2 ).rdfNode().asResource() ); List<DisplayHierarchyNode> ex = dhn.extractByPredicate( p1.getURI(), p3, p4.getURI() ); assertEquals( 1, dhn.children().size() ); assertEquals( r2, dhn.children().get( 0 ).rdfNode().asResource() ); assertEquals( 2, ex.size() ); assertEquals( r1, ex.get( 0 ).rdfNode().asResource() ); assertEquals( r3, ex.get( 1 ).rdfNode().asResource() ); }