CpcClassification extends PatentClassification { public static <T extends PatentClassification> Map<String, List<CpcClassification>> filterCpc( Collection<T> classes) { return classes.stream().filter(CpcClassification.class::isInstance).map(CpcClassification.class::cast) .collect(Collectors.groupingBy(s -> (s.isMainOrInventive() ? "inventive" : "additional"), TreeMap::new, Collectors.toList())); } CpcClassification(String originalText, boolean mainOrInventive); boolean isParseFailed(); @Override ClassificationType getType(); String getSection(); void setSection(String section); String getMainClass(); void setMainClass(String mainClass); String getSubClass(); void setSubClass(String subClass); String[] getMainGroup(); void setMainGroup(String[] mainGroup); String[] getSubGroup(); void setSubGroup(String[] subGroup); @Override String getTextNormalized(); @Override List<String> getSearchTokens(); String standardize(); @Override Tree getTree(); @Override int getDepth(); @Override boolean isContained(PatentClassification check); @Override boolean equals(Object obj); @Override void parseText(final String classificationStr); @Override boolean validate(); @Override String toString(); static Map<String, List<CpcClassification>> filterCpc(
			Collection<T> classes);  }
@Test public void filterCPC() throws ParseException { Set<PatentClassification> clazs = new TreeSet<PatentClassification>(); CpcClassification cpcClass = new CpcClassification("D21", true); cpcClass.parseText("D21"); clazs.add(cpcClass); CpcClassification cpcClass2 = new CpcClassification("D07B2201/2051", false); cpcClass2.parseText("D07B2201/2051"); clazs.add(cpcClass2); CpcClassification cpcClass3 = new CpcClassification("D07B2201", false); cpcClass3.parseText("D07B2201"); clazs.add(cpcClass3); Map<String, List<CpcClassification>> cpcClasses = CpcClassification.filterCpc(clazs); assertEquals(cpcClasses.get("inventive").size(), 1); assertEquals(cpcClass, cpcClasses.get("inventive").get(0)); assertEquals(cpcClasses.get("additional").size(), 2); assertEquals(cpcClass3, cpcClasses.get("additional").get(0)); assertEquals(cpcClass2, cpcClasses.get("additional").get(1)); }