List of usage examples for org.apache.commons.collections4 SetValuedMap get
@Override Set<V> get(K key);
From source file:com.github.alexfalappa.nbspringboot.navigator.MappedElement.java
private final String computeHandlerSignature(Element element) { StringBuilder sb = new StringBuilder(element.getSimpleName()); if (element instanceof ExecutableElement) { // store arguments with same unqualified type name ExecutableElement eel = (ExecutableElement) element; SetValuedMap<String, String> mm = new HashSetValuedHashMap<>(); for (VariableElement var : eel.getParameters()) { String fullType = var.asType().toString(); mm.put(Utils.shortenJavaType(fullType), fullType); }/*from w ww. ja v a 2 s .co m*/ // build up argument list sb.append('('); for (int i = 0; i < eel.getParameters().size(); i++) { VariableElement var = eel.getParameters().get(i); String fullType = var.asType().toString(); final String shortType = Utils.shortenJavaType(fullType); if (mm.get(shortType).size() > 1) { sb.append(fullType); } else { sb.append(shortType); } if (i < eel.getParameters().size() - 1) { sb.append(", "); } } sb.append(") : "); sb.append(Utils.shortenJavaType(eel.getReturnType().toString())); } return sb.toString(); }
From source file:org.decampo.examples.collections.MoreCollectorsTest.java
@Test public void toSetValuedMapTest() throws Exception { // Make a set valued map where the key is the first element in each // array and the set contains all the elements of the array final SetValuedMap<String, String> result = Arrays.stream(DATA) // convert to arrays of length two .flatMap(arr -> Arrays.stream(arr).map(s -> new String[] { arr[0], s })) // Now collect the 2-element arrays into a map .collect(MoreCollectors.toSetValuedMap(arr -> arr[0], arr -> arr[1])); // Now we verify Arrays.stream(DATA).forEach(arr -> { assertEquals(//from w w w. j ava2s. c o m // a set containing the elements of the array new HashSet<>(Arrays.asList(arr)), // equals the set corresponding to the first element result.get(arr[0])); }); }
From source file:org.decampo.examples.collections.MoreCollectorsTest.java
@Test public void groupingByDistinctTest() throws Exception { final Num[] english = { new Num(0, "zero"), new Num(1, "one"), new Num(2, "two") }; final Num[] espanol = { new Num(0, "cero"), new Num(1, "uno"), new Num(2, "dos") }; final Num[] deutsche = { new Num(0, "null"), new Num(1, "eins"), new Num(2, "zwei") }; final SetValuedMap<Integer, Num> result = Stream.of(english, espanol, deutsche, espanol, english) .flatMap(Arrays::stream).collect(MoreCollectors.groupingByDistinct(Num::getValue)); assertEquals(new HashSet<>(Arrays.asList(0, 1, 2)), result.keySet()); assertEquals(new HashSet<>(Arrays.asList(english[0], espanol[0], deutsche[0])), result.get(0)); assertEquals(new HashSet<>(Arrays.asList(english[1], espanol[1], deutsche[1])), result.get(1)); assertEquals(new HashSet<>(Arrays.asList(english[2], espanol[2], deutsche[2])), result.get(2)); }