/** * Partition the members of an iterator into two lists, according to whether they are named or * anonymous classes * * @param i An iterator to partition * @param named A list of named classes * @param anon A list of anonymous classes */ protected static void partitionByNamed( Iterator<? extends OntClass> i, List<OntClass> named, List<OntClass> anon) { while (i.hasNext()) { OntClass c = i.next(); boolean ignore = false; // duplicate check: we ignore this class if we've already got it if (named.contains(c)) { ignore = true; } // subsumption check: c must have only anon classes or Thing // as super-classes to still qualify as a root class Resource thing = c.getProfile().THING(); for (Iterator<OntClass> j = c.listSuperClasses(); !ignore && j.hasNext(); ) { OntClass sup = j.next(); if (!((thing != null && sup.equals(thing)) || sup.isAnon() || sup.equals(c))) { ignore = true; } } if (!ignore) { // place the class in the appropriate partition (c.isAnon() ? anon : named).add(c); } } }