/** * Create a new aggregating map expression using a backing TreeMap * * @param key key for the map entries * @param value value for the map entries * @return wrapper expression */ public static <K extends Comparable<? super K>, V, U> AbstractGroupExpression<Pair<K, V>, SortedMap<K, U>> sortedMap(Expression<K> key, GroupExpression<V, U> value) { return sortedMap(new GOne<K>(key), value); }
/** * Create a new aggregating map expression using a backing TreeMap * * @param key key for the map entries * @param value value for the map entries * @return wrapper expression */ public static <K, V, T extends Comparable<? super T>> AbstractGroupExpression<Pair<K, V>, SortedMap<T, V>> sortedMap(GroupExpression<K, T> key, Expression<V> value) { return sortedMap(key, new GOne<V>(value)); }
/** * Create a new aggregating map expression using a backing TreeMap using the given comparator * * @param key key for the map entries * @param value value for the map entries * @param comparator comparator for the created TreeMap instances * @return wrapper expression */ public static <K, V, U> AbstractGroupExpression<Pair<K, V>, SortedMap<K, U>> sortedMap(Expression<K> key, GroupExpression<V, U> value, Comparator<? super K> comparator) { return sortedMap(new GOne<K>(key), value, comparator); }
/** * Create a new aggregating map expression using a backing TreeMap using the given comparator * * @param key key for the map entries * @param value value for the map entries * @param comparator comparator for the created TreeMap instances * @return wrapper expression */ public static <K, V, T> AbstractGroupExpression<Pair<K, V>, SortedMap<T, V>> sortedMap(GroupExpression<K, T> key, Expression<V> value, Comparator<? super T> comparator) { return sortedMap(key, new GOne<V>(value), comparator); }
@Test public void map_sorted() { Map<Integer, Group> results = MAP_RESULTS.transform( groupBy(postId).as(postName, sortedMap(commentId, commentText))); Group group = results.get(1); Iterator<Map.Entry<Integer, String>> it = group.getMap(commentId, commentText).entrySet().iterator(); assertEquals(1, it.next().getKey().intValue()); assertEquals(2, it.next().getKey().intValue()); assertEquals(3, it.next().getKey().intValue()); }
@Test public void map_sorted_reverse() { Map<Integer, Group> results = MAP_RESULTS.transform( groupBy(postId).as(postName, sortedMap(commentId, commentText, Ordering.natural().reverse()))); Group group = results.get(1); Iterator<Map.Entry<Integer, String>> it = group.getMap(commentId, commentText).entrySet().iterator(); assertEquals(3, it.next().getKey().intValue()); assertEquals(2, it.next().getKey().intValue()); assertEquals(1, it.next().getKey().intValue()); }
@Test public void signature() { StringPath str = Expressions.stringPath("str"); NumberPath<BigDecimal> bigd = Expressions.numberPath(BigDecimal.class, "bigd"); ResultTransformer<Map<String, SortedMap<BigDecimal, SortedMap<BigDecimal, Map<String, String>>>>> resultTransformer = GroupBy.groupBy(str).as( GroupBy.sortedMap(bigd, GroupBy.sortedMap(bigd, GroupBy.map(str, str), Ordering.natural().nullsLast()), Ordering.natural().nullsFirst())); assertNotNull(resultTransformer); }
/** * Create a new aggregating map expression using a backing TreeMap * * @param key key for the map entries * @param value value for the map entries * @return wrapper expression */ public static <K, V, T extends Comparable<? super T>> AbstractGroupExpression<Pair<K, V>, SortedMap<T, V>> sortedMap(GroupExpression<K, T> key, Expression<V> value) { return sortedMap(key, new GOne<V>(value)); }
/** * Create a new aggregating map expression using a backing TreeMap * * @param key key for the map entries * @param value value for the map entries * @return wrapper expression */ public static <K extends Comparable<? super K>, V, U> AbstractGroupExpression<Pair<K, V>, SortedMap<K, U>> sortedMap(Expression<K> key, GroupExpression<V, U> value) { return sortedMap(new GOne<K>(key), value); }
/** * Create a new aggregating map expression using a backing TreeMap using the given comparator * * @param key key for the map entries * @param value value for the map entries * @param comparator comparator for the created TreeMap instances * @return wrapper expression */ public static <K, V, T> AbstractGroupExpression<Pair<K, V>, SortedMap<T, V>> sortedMap(GroupExpression<K, T> key, Expression<V> value, Comparator<? super T> comparator) { return sortedMap(key, new GOne<V>(value), comparator); }
/** * Create a new aggregating map expression using a backing TreeMap using the given comparator * * @param key key for the map entries * @param value value for the map entries * @param comparator comparator for the created TreeMap instances * @return wrapper expression */ public static <K, V, U> AbstractGroupExpression<Pair<K, V>, SortedMap<K, U>> sortedMap(Expression<K> key, GroupExpression<V, U> value, Comparator<? super K> comparator) { return sortedMap(new GOne<K>(key), value, comparator); }