@Test public void testGetSuperOrdinateStandard() { ThesaurusConcept c1 = new ThesaurusConcept(); ThesaurusConcept c2 = new ThesaurusConcept(); ThesaurusConcept c3 = new ThesaurusConcept(); ThesaurusConcept c21 = new ThesaurusConcept(); Set<ThesaurusConcept> c21Parents = new HashSet<ThesaurusConcept>(); c21Parents.add(c1); c21Parents.add(c2); c21.setParentConcepts(c21Parents); ThesaurusConcept c22 = new ThesaurusConcept(); Set<ThesaurusConcept> c22Parents = new HashSet<ThesaurusConcept>(); c22Parents.add(c2); c22.setParentConcepts(c22Parents); ThesaurusConcept c23 = new ThesaurusConcept(); Set<ThesaurusConcept> c23Parents = new HashSet<ThesaurusConcept>(); c23Parents.add(c2); c23Parents.add(c3); c23.setParentConcepts(c23Parents); Set<ThesaurusConcept> membersConcepts = new HashSet<ThesaurusConcept>(); membersConcepts.add(c21); membersConcepts.add(c22); membersConcepts.add(c23); ThesaurusConcept actualSuperOrdinateConcept = ConceptHierarchyUtil .getSuperOrdinate(membersConcepts); Assert.assertEquals(c2, actualSuperOrdinateConcept); Set<ThesaurusConcept> rootsConcepts = new HashSet<ThesaurusConcept>(); membersConcepts.add(c1); membersConcepts.add(c2); membersConcepts.add(c3); ThesaurusConcept rootsSuperOrdinateConcept = ConceptHierarchyUtil .getSuperOrdinate(rootsConcepts); Assert.assertNull(rootsSuperOrdinateConcept); }
public static ThesaurusConcept getSuperOrdinate( Set<ThesaurusConcept> membersConcepts) { Set<ThesaurusConcept> result = new HashSet<ThesaurusConcept>(); boolean allRoot = true; boolean first = true; for (ThesaurusConcept thesaurusConcept : membersConcepts) { if (!thesaurusConcept.getParentConcepts().isEmpty()) { allRoot = false; Set<ThesaurusConcept> parentConcepts = thesaurusConcept .getParentConcepts(); if (first) { result.addAll(parentConcepts); first = false; } else { result.retainAll(parentConcepts); } } } if (result.isEmpty() && !allRoot) { throw new BusinessException( "Unable to find thesaurus array concepts common parent", "import-no-superordinate"); } else if (result.isEmpty() && allRoot) { return null; } else if (result.size() > 1) { throw new BusinessException( "Unable to get thesaurus array concepts common parent", "import-too-many-superordinate"); } return result.iterator().next(); }
ConceptHierarchyUtil { public static ThesaurusConcept getSuperOrdinate( Set<ThesaurusConcept> membersConcepts) { Set<ThesaurusConcept> result = new HashSet<ThesaurusConcept>(); boolean allRoot = true; boolean first = true; for (ThesaurusConcept thesaurusConcept : membersConcepts) { if (!thesaurusConcept.getParentConcepts().isEmpty()) { allRoot = false; Set<ThesaurusConcept> parentConcepts = thesaurusConcept .getParentConcepts(); if (first) { result.addAll(parentConcepts); first = false; } else { result.retainAll(parentConcepts); } } } if (result.isEmpty() && !allRoot) { throw new BusinessException( "Unable to find thesaurus array concepts common parent", "import-no-superordinate"); } else if (result.isEmpty() && allRoot) { return null; } else if (result.size() > 1) { throw new BusinessException( "Unable to get thesaurus array concepts common parent", "import-too-many-superordinate"); } return result.iterator().next(); } }
ConceptHierarchyUtil { public static ThesaurusConcept getSuperOrdinate( Set<ThesaurusConcept> membersConcepts) { Set<ThesaurusConcept> result = new HashSet<ThesaurusConcept>(); boolean allRoot = true; boolean first = true; for (ThesaurusConcept thesaurusConcept : membersConcepts) { if (!thesaurusConcept.getParentConcepts().isEmpty()) { allRoot = false; Set<ThesaurusConcept> parentConcepts = thesaurusConcept .getParentConcepts(); if (first) { result.addAll(parentConcepts); first = false; } else { result.retainAll(parentConcepts); } } } if (result.isEmpty() && !allRoot) { throw new BusinessException( "Unable to find thesaurus array concepts common parent", "import-no-superordinate"); } else if (result.isEmpty() && allRoot) { return null; } else if (result.size() > 1) { throw new BusinessException( "Unable to get thesaurus array concepts common parent", "import-too-many-superordinate"); } return result.iterator().next(); } private  ConceptHierarchyUtil(); }
ConceptHierarchyUtil { public static ThesaurusConcept getSuperOrdinate( Set<ThesaurusConcept> membersConcepts) { Set<ThesaurusConcept> result = new HashSet<ThesaurusConcept>(); boolean allRoot = true; boolean first = true; for (ThesaurusConcept thesaurusConcept : membersConcepts) { if (!thesaurusConcept.getParentConcepts().isEmpty()) { allRoot = false; Set<ThesaurusConcept> parentConcepts = thesaurusConcept .getParentConcepts(); if (first) { result.addAll(parentConcepts); first = false; } else { result.retainAll(parentConcepts); } } } if (result.isEmpty() && !allRoot) { throw new BusinessException( "Unable to find thesaurus array concepts common parent", "import-no-superordinate"); } else if (result.isEmpty() && allRoot) { return null; } else if (result.size() > 1) { throw new BusinessException( "Unable to get thesaurus array concepts common parent", "import-too-many-superordinate"); } return result.iterator().next(); } private  ConceptHierarchyUtil(); static ThesaurusConcept getSuperOrdinate(
			Set<ThesaurusConcept> membersConcepts); }
ConceptHierarchyUtil { public static ThesaurusConcept getSuperOrdinate( Set<ThesaurusConcept> membersConcepts) { Set<ThesaurusConcept> result = new HashSet<ThesaurusConcept>(); boolean allRoot = true; boolean first = true; for (ThesaurusConcept thesaurusConcept : membersConcepts) { if (!thesaurusConcept.getParentConcepts().isEmpty()) { allRoot = false; Set<ThesaurusConcept> parentConcepts = thesaurusConcept .getParentConcepts(); if (first) { result.addAll(parentConcepts); first = false; } else { result.retainAll(parentConcepts); } } } if (result.isEmpty() && !allRoot) { throw new BusinessException( "Unable to find thesaurus array concepts common parent", "import-no-superordinate"); } else if (result.isEmpty() && allRoot) { return null; } else if (result.size() > 1) { throw new BusinessException( "Unable to get thesaurus array concepts common parent", "import-too-many-superordinate"); } return result.iterator().next(); } private  ConceptHierarchyUtil(); static ThesaurusConcept getSuperOrdinate(
			Set<ThesaurusConcept> membersConcepts);  }