PatentClassification implements Classification { public static <T extends PatentClassification> Map<ClassificationType, Set<PatentClassification>> groupByType( Collection<PatentClassification> classes) { return classes.stream() .collect(Collectors.groupingBy(PatentClassification::getType, TreeMap::new, Collectors.toSet())); } PatentClassification(String originalText, boolean mainOrInventive); @Override String getTextOriginal(); boolean isMainOrInventive(); @Override String toText(); @Override int compareTo(Classification other); static List<T> fromText(Iterable<String> classificationStrings,
			Class<T> classificationClass); static boolean match(Collection<T> classes,
			Predicate<PatentClassification> predicate); static SortedSet<T> filter(Collection<T> classes,
			Predicate<PatentClassification> predicate); static Map<ClassificationType, Set<PatentClassification>> groupByType(
			Collection<PatentClassification> classes); static SortedSet<T> filterByType(Collection<PatentClassification> classes,
			ClassificationType wantedType); static SortedSet<T> filterByType(Collection<PatentClassification> classes,
			Class<T> wantedClass); static Set<String> getFacetByType(Collection<PatentClassification> classes, ClassificationType wantedType); static Set<String> getFacet(Collection<T> classes);  }
@Test public void groupByType() throws ParseException { List<PatentClassification> claz = new ArrayList<PatentClassification>(); CpcClassification cpcClass = new CpcClassification("D23", false); cpcClass.parseText("D23"); claz.add(cpcClass); CpcClassification cpcClass2 = new CpcClassification("D21", false); cpcClass2.parseText("D21"); claz.add(cpcClass2); IpcClassification ipcClass = new IpcClassification("D22", false); ipcClass.parseText("D22"); claz.add(ipcClass); UspcClassification uspc = new UspcClassification("PLT101", false); uspc.parseText("PLT101"); claz.add(uspc); Map<ClassificationType, Set<PatentClassification>> classes = PatentClassification.groupByType(claz); Set<PatentClassification> expectCPC = new HashSet<PatentClassification>(); expectCPC.add(cpcClass); expectCPC.add(cpcClass2); assertEquals(classes.get(ClassificationType.CPC).size(), 2); assertEquals(expectCPC, classes.get(ClassificationType.CPC)); assertEquals(classes.get(ClassificationType.IPC).size(), 1); assertEquals(classes.get(ClassificationType.USPC).size(), 1); }