mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Improve generic type constraints
Add sorted* variants with comparators Remove brdige annotations
This commit is contained in:
parent
82c97d948b
commit
9a6fd4e75a
@ -13,10 +13,7 @@
|
||||
*/
|
||||
package com.querydsl.core.group;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.*;
|
||||
|
||||
import com.mysema.commons.lang.Pair;
|
||||
|
||||
@ -43,7 +40,7 @@ abstract class GMap<K, V> extends AbstractGroupExpression<Pair<K, V>, Map<K, V>>
|
||||
};
|
||||
}
|
||||
|
||||
public static <T, U> GMap<T, U> createSorted(QPair<T, U> expr) {
|
||||
public static <T extends Comparable<? super T>, U> GMap<T, U> createSorted(QPair<T, U> expr) {
|
||||
return new GMap<T, U>(expr) {
|
||||
@Override
|
||||
protected Map<T, U> createMap() {
|
||||
@ -52,6 +49,15 @@ abstract class GMap<K, V> extends AbstractGroupExpression<Pair<K, V>, Map<K, V>>
|
||||
};
|
||||
}
|
||||
|
||||
public static <T, U> GMap<T, U> createSorted(QPair<T, U> expr, final Comparator<? super T> comparator) {
|
||||
return new GMap<T, U>(expr) {
|
||||
@Override
|
||||
protected Map<T, U> createMap() {
|
||||
return new TreeMap<T, U>(comparator);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupCollector<Pair<K,V>, Map<K, V>> createGroupCollector() {
|
||||
return new GroupCollector<Pair<K,V>, Map<K, V>>() {
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
*/
|
||||
package com.querydsl.core.group;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
@ -37,7 +38,7 @@ abstract class GSet<T> extends AbstractGroupExpression<T, Set<T>> {
|
||||
};
|
||||
}
|
||||
|
||||
public static <U> GSet<U> createSorted(Expression<U> expr) {
|
||||
public static <U extends Comparable<? super U>> GSet<U> createSorted(Expression<U> expr) {
|
||||
return new GSet<U>(expr) {
|
||||
@Override
|
||||
protected Set<U> createSet() {
|
||||
@ -46,6 +47,15 @@ abstract class GSet<T> extends AbstractGroupExpression<T, Set<T>> {
|
||||
};
|
||||
}
|
||||
|
||||
public static <U> GSet<U> createSorted(Expression<U> expr, final Comparator<? super U> comparator) {
|
||||
return new GSet<U>(expr) {
|
||||
@Override
|
||||
protected Set<U> createSet() {
|
||||
return new TreeSet<U>(comparator);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public GSet(Expression<T> expr) {
|
||||
super(Set.class, expr);
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
*/
|
||||
package com.querydsl.core.group;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -125,14 +126,23 @@ public final class GroupBy {
|
||||
* @param expression
|
||||
* @return
|
||||
*/
|
||||
public static <E> AbstractGroupExpression<E, Set<E>> sortedSet(Expression<E> expression) {
|
||||
public static <E extends Comparable<? super E>> AbstractGroupExpression<E, Set<E>> sortedSet(Expression<E> expression) {
|
||||
return GSet.createSorted(expression);
|
||||
}
|
||||
|
||||
public static <E, F> GroupExpression<E, Set<F>> sortedSet(GroupExpression<E, F> groupExpression) {
|
||||
public static <E, F extends Comparable<? super F>> GroupExpression<E, Set<F>> sortedSet(GroupExpression<E, F> groupExpression) {
|
||||
return new MixinGroupExpression<E, F, Set<F>>(groupExpression, GSet.createSorted(groupExpression));
|
||||
}
|
||||
|
||||
public static <E> AbstractGroupExpression<E, Set<E>> sortedSet(Expression<E> expression, Comparator<? super E> comparator) {
|
||||
return GSet.createSorted(expression, comparator);
|
||||
}
|
||||
|
||||
public static <E, F> GroupExpression<E, Set<F>> sortedSet(GroupExpression<E, F> groupExpression, Comparator<? super F> comparator) {
|
||||
return new MixinGroupExpression<E, F, Set<F>>(groupExpression, GSet.createSorted(groupExpression, comparator));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new aggregating map expression using a backing LinkedHashMap
|
||||
*
|
||||
@ -164,23 +174,39 @@ public final class GroupBy {
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
@WithBridgeMethods(value=Expression.class,castRequired=true)
|
||||
public static <K, V> AbstractGroupExpression<Pair<K, V>,Map<K, V>> sortedMap(Expression<K> key, Expression<V> value) {
|
||||
public static <K extends Comparable<? super K>, V> AbstractGroupExpression<Pair<K, V>,Map<K, V>> sortedMap(Expression<K> key, Expression<V> value) {
|
||||
return GMap.createSorted(QPair.create(key, value));
|
||||
}
|
||||
|
||||
public static <K, V, T> AbstractGroupExpression<Pair<K, V>, Map<T, V>> sortedMap(GroupExpression<K, T> key, Expression<V> value) {
|
||||
public static <K extends Comparable<? super K>, V, T extends Comparable<? super T>> AbstractGroupExpression<Pair<K, V>, Map<T, V>> sortedMap(GroupExpression<K, T> key, Expression<V> value) {
|
||||
return sortedMap(key, new GOne<V>(value));
|
||||
}
|
||||
|
||||
public static <K, V, U> AbstractGroupExpression<Pair<K, V>, Map<K, U>> sortedMap(Expression<K> key, GroupExpression<V, U> value) {
|
||||
public static <K extends Comparable<? super K>, V, U> AbstractGroupExpression<Pair<K, V>, Map<K, U>> sortedMap(Expression<K> key, GroupExpression<V, U> value) {
|
||||
return sortedMap(new GOne<K>(key), value);
|
||||
}
|
||||
|
||||
public static <K, V, T, U> AbstractGroupExpression<Pair<K, V>, Map<T, U>> sortedMap(GroupExpression<K, T> key, GroupExpression<V, U> value) {
|
||||
public static <K extends Comparable<? super K>, V, T extends Comparable<? super T>, U> AbstractGroupExpression<Pair<K, V>, Map<T, U>> sortedMap(GroupExpression<K, T> key, GroupExpression<V, U> value) {
|
||||
return new GMap.Mixin<K, V, T, U, Map<T, U>>(key, value, GMap.createSorted(QPair.create(key, value)));
|
||||
}
|
||||
|
||||
public static <K, V> AbstractGroupExpression<Pair<K, V>,Map<K, V>> sortedMap(Expression<K> key, Expression<V> value, Comparator<? super K> comparator) {
|
||||
return GMap.createSorted(QPair.create(key, value), comparator);
|
||||
}
|
||||
|
||||
public static <K, V, T> AbstractGroupExpression<Pair<K, V>, Map<T, V>> sortedMap(GroupExpression<K, T> key, Expression<V> value, Comparator<? super K> comparator) {
|
||||
return sortedMap(key, new GOne<V>(value), comparator);
|
||||
}
|
||||
|
||||
public static <K, V, U> AbstractGroupExpression<Pair<K, V>, Map<K, U>> sortedMap(Expression<K> key, GroupExpression<V, U> value, Comparator<? super U> comparator) {
|
||||
return sortedMap(new GOne<K>(key), value, comparator);
|
||||
}
|
||||
|
||||
public static <K, V, T, U> AbstractGroupExpression<Pair<K, V>, Map<T, U>> sortedMap(GroupExpression<K, T> key, GroupExpression<V, U> value, Comparator<? super T> comparator) {
|
||||
return new GMap.Mixin<K, V, T, U, Map<T, U>>(key, value, GMap.createSorted(QPair.create(key, value), comparator));
|
||||
}
|
||||
|
||||
|
||||
private GroupBy() {}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user