/** * <p> * Answer the maximal lower elements of the given collection, given the partial * ordering <code>rel</code>. See {@link #maximalLowerElements( Iterator, Property, boolean )} * for details. * </p> * * @param resources A collection of resources * @param rel A property defining a partial-ordering on <code>resources</code> * @param inverse If true, we invert the given property (by reversing the order * of the arguments), which allows us to use eg subClassOf as a partial order * operator for both sub-class and super-class relationships * @return The collection that contains only those <code>resources</code> are not * greater than another resource under the partial order. */ public static <T extends Resource> List<T> maximalLowerElements( Collection<T> resources, Property rel, boolean inverse ) { return maximalLowerElements( resources.iterator(), rel, inverse ); }
/** * <p> * Answer the maximal lower elements of the given collection, given the partial * ordering <code>rel</code>. See {@link #maximalLowerElements( Iterator, Property, boolean )} * for details. * </p> * * @param resources A collection of resources * @param rel A property defining a partial-ordering on <code>resources</code> * @param inverse If true, we invert the given property (by reversing the order * of the arguments), which allows us to use eg subClassOf as a partial order * operator for both sub-class and super-class relationships * @return The collection that contains only those <code>resources</code> are not * greater than another resource under the partial order. */ public static <T extends Resource> List<T> maximalLowerElements( Collection<T> resources, Property rel, boolean inverse ) { return maximalLowerElements( resources.iterator(), rel, inverse ); }
s = ResourceUtils.maximalLowerElements( s, orderRel, inverse );
s = ResourceUtils.maximalLowerElements( s, orderRel, inverse );
public void testMaximalLowerElements() { Model m = ModelFactory.createDefaultModel(); Resource a = m.createResource( NS + "a" ); Resource b = m.createResource( NS + "b" ); Resource c = m.createResource( NS + "c" ); Resource d = m.createResource( NS + "d" ); b.addProperty( RDFS.subClassOf, a ); c.addProperty( RDFS.subClassOf, a ); d.addProperty( RDFS.subClassOf, c ); d.addProperty( RDFS.subClassOf, a ); List<Resource> abcd = Arrays.asList( a,b,c,d ); List<Resource> bcd = Arrays.asList( b,c,d ); List<Resource> cd = Arrays.asList( c,d ); assertEquals( "Wrong number of remaining resources", 1, ResourceUtils.maximalLowerElements( abcd, RDFS.subClassOf, true ).size() ); assertEquals( "Result should be a", a, ResourceUtils.maximalLowerElements( abcd, RDFS.subClassOf, true ).iterator().next() ); assertEquals( "Wrong number of remaining resources", 2, ResourceUtils.maximalLowerElements( bcd, RDFS.subClassOf, true ).size() ); assertEquals( "Wrong number of remaining resources", 1, ResourceUtils.maximalLowerElements( cd, RDFS.subClassOf, true ).size() ); assertEquals( "Result should be a", c, ResourceUtils.maximalLowerElements( cd, RDFS.subClassOf, true ).iterator().next() ); }
public void testMaximalLowerElements() { Model m = ModelFactory.createDefaultModel(); Resource a = m.createResource( NS + "a" ); Resource b = m.createResource( NS + "b" ); Resource c = m.createResource( NS + "c" ); Resource d = m.createResource( NS + "d" ); b.addProperty( RDFS.subClassOf, a ); c.addProperty( RDFS.subClassOf, a ); d.addProperty( RDFS.subClassOf, c ); d.addProperty( RDFS.subClassOf, a ); List<Resource> abcd = Arrays.asList( a,b,c,d ); List<Resource> bcd = Arrays.asList( b,c,d ); List<Resource> cd = Arrays.asList( c,d ); assertEquals( "Wrong number of remaining resources", 1, ResourceUtils.maximalLowerElements( abcd, RDFS.subClassOf, true ).size() ); assertEquals( "Result should be a", a, ResourceUtils.maximalLowerElements( abcd, RDFS.subClassOf, true ).iterator().next() ); assertEquals( "Wrong number of remaining resources", 2, ResourceUtils.maximalLowerElements( bcd, RDFS.subClassOf, true ).size() ); assertEquals( "Wrong number of remaining resources", 1, ResourceUtils.maximalLowerElements( cd, RDFS.subClassOf, true ).size() ); assertEquals( "Result should be a", c, ResourceUtils.maximalLowerElements( cd, RDFS.subClassOf, true ).iterator().next() ); }