mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Use SortedSet and SortedMap as return types
This commit is contained in:
parent
fd39742221
commit
2ccef669c8
@ -21,7 +21,7 @@ import com.mysema.commons.lang.Pair;
|
||||
* @param <K>
|
||||
* @param <V>
|
||||
*/
|
||||
abstract class GMap<K, V> extends AbstractGroupExpression<Pair<K, V>, Map<K, V>> {
|
||||
abstract class GMap<K, V, M extends Map<K,V>> extends AbstractGroupExpression<Pair<K, V>, M> {
|
||||
|
||||
private static final long serialVersionUID = 7106389414200843920L;
|
||||
|
||||
@ -29,10 +29,10 @@ abstract class GMap<K, V> extends AbstractGroupExpression<Pair<K, V>, Map<K, V>>
|
||||
super(Map.class, qpair);
|
||||
}
|
||||
|
||||
protected abstract Map<K, V> createMap();
|
||||
protected abstract M createMap();
|
||||
|
||||
public static <T, U> GMap<T, U> createLinked(QPair<T, U> expr) {
|
||||
return new GMap<T, U>(expr) {
|
||||
public static <T, U> GMap<T, U, Map<T,U>> createLinked(QPair<T, U> expr) {
|
||||
return new GMap<T, U, Map<T, U>>(expr) {
|
||||
@Override
|
||||
protected Map<T, U> createMap() {
|
||||
return new LinkedHashMap<T, U>();
|
||||
@ -40,29 +40,29 @@ abstract class GMap<K, V> extends AbstractGroupExpression<Pair<K, V>, Map<K, V>>
|
||||
};
|
||||
}
|
||||
|
||||
public static <T extends Comparable<? super T>, U> GMap<T, U> createSorted(QPair<T, U> expr) {
|
||||
return new GMap<T, U>(expr) {
|
||||
public static <T extends Comparable<? super T>, U> GMap<T, U, SortedMap<T, U>> createSorted(QPair<T, U> expr) {
|
||||
return new GMap<T, U, SortedMap<T, U>>(expr) {
|
||||
@Override
|
||||
protected Map<T, U> createMap() {
|
||||
protected SortedMap<T, U> createMap() {
|
||||
return new TreeMap<T, U>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static <T, U> GMap<T, U> createSorted(QPair<T, U> expr, final Comparator<? super T> comparator) {
|
||||
return new GMap<T, U>(expr) {
|
||||
public static <T, U> GMap<T, U, SortedMap<T, U>> createSorted(QPair<T, U> expr, final Comparator<? super T> comparator) {
|
||||
return new GMap<T, U, SortedMap<T, U>>(expr) {
|
||||
@Override
|
||||
protected Map<T, U> createMap() {
|
||||
protected SortedMap<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>>() {
|
||||
public GroupCollector<Pair<K,V>, M> createGroupCollector() {
|
||||
return new GroupCollector<Pair<K,V>, M>() {
|
||||
|
||||
private final Map<K, V> map = createMap();
|
||||
private final M map = createMap();
|
||||
|
||||
@Override
|
||||
public void add(Pair<K,V> pair) {
|
||||
@ -70,7 +70,7 @@ abstract class GMap<K, V> extends AbstractGroupExpression<Pair<K, V>, Map<K, V>>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<K, V> get() {
|
||||
public M get() {
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@ -13,10 +13,7 @@
|
||||
*/
|
||||
package com.querydsl.core.group;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
|
||||
import com.querydsl.core.types.Expression;
|
||||
|
||||
@ -25,12 +22,12 @@ import com.querydsl.core.types.Expression;
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
abstract class GSet<T> extends AbstractGroupExpression<T, Set<T>> {
|
||||
abstract class GSet<T, S extends Set<T>> extends AbstractGroupExpression<T, S> {
|
||||
|
||||
private static final long serialVersionUID = -1575808026237160843L;
|
||||
|
||||
public static <U> GSet<U> createLinked(Expression<U> expr) {
|
||||
return new GSet<U>(expr) {
|
||||
public static <U> GSet<U, Set<U>> createLinked(Expression<U> expr) {
|
||||
return new GSet<U, Set<U>>(expr) {
|
||||
@Override
|
||||
protected Set<U> createSet() {
|
||||
return new LinkedHashSet<U>();
|
||||
@ -38,19 +35,19 @@ abstract class GSet<T> extends AbstractGroupExpression<T, Set<T>> {
|
||||
};
|
||||
}
|
||||
|
||||
public static <U extends Comparable<? super U>> GSet<U> createSorted(Expression<U> expr) {
|
||||
return new GSet<U>(expr) {
|
||||
public static <U extends Comparable<? super U>> GSet<U, SortedSet<U>> createSorted(Expression<U> expr) {
|
||||
return new GSet<U, SortedSet<U>>(expr) {
|
||||
@Override
|
||||
protected Set<U> createSet() {
|
||||
protected SortedSet<U> createSet() {
|
||||
return new TreeSet<U>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static <U> GSet<U> createSorted(Expression<U> expr, final Comparator<? super U> comparator) {
|
||||
return new GSet<U>(expr) {
|
||||
public static <U> GSet<U, SortedSet<U>> createSorted(Expression<U> expr, final Comparator<? super U> comparator) {
|
||||
return new GSet<U, SortedSet<U>>(expr) {
|
||||
@Override
|
||||
protected Set<U> createSet() {
|
||||
protected SortedSet<U> createSet() {
|
||||
return new TreeSet<U>(comparator);
|
||||
}
|
||||
};
|
||||
@ -60,13 +57,13 @@ abstract class GSet<T> extends AbstractGroupExpression<T, Set<T>> {
|
||||
super(Set.class, expr);
|
||||
}
|
||||
|
||||
protected abstract Set<T> createSet();
|
||||
protected abstract S createSet();
|
||||
|
||||
@Override
|
||||
public GroupCollector<T,Set<T>> createGroupCollector() {
|
||||
return new GroupCollector<T,Set<T>>() {
|
||||
public GroupCollector<T, S> createGroupCollector() {
|
||||
return new GroupCollector<T, S>() {
|
||||
|
||||
private final Set<T> set = createSet();
|
||||
private final S set = createSet();
|
||||
|
||||
@Override
|
||||
public void add(T o) {
|
||||
@ -76,7 +73,7 @@ abstract class GSet<T> extends AbstractGroupExpression<T, Set<T>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<T> get() {
|
||||
public S get() {
|
||||
return set;
|
||||
}
|
||||
|
||||
|
||||
@ -13,10 +13,7 @@
|
||||
*/
|
||||
package com.querydsl.core.group;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import com.mysema.commons.lang.Pair;
|
||||
import com.querydsl.core.types.Expression;
|
||||
@ -125,7 +122,7 @@ public final class GroupBy {
|
||||
* @param expression
|
||||
* @return
|
||||
*/
|
||||
public static <E extends Comparable<? super E>> AbstractGroupExpression<E, Set<E>> sortedSet(Expression<E> expression) {
|
||||
public static <E extends Comparable<? super E>> AbstractGroupExpression<E, SortedSet<E>> sortedSet(Expression<E> expression) {
|
||||
return GSet.createSorted(expression);
|
||||
}
|
||||
|
||||
@ -135,8 +132,8 @@ public final class GroupBy {
|
||||
* @param groupExpression
|
||||
* @return
|
||||
*/
|
||||
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, F extends Comparable<? super F>> GroupExpression<E, SortedSet<F>> sortedSet(GroupExpression<E, F> groupExpression) {
|
||||
return new MixinGroupExpression<E, F, SortedSet<F>>(groupExpression, GSet.createSorted(groupExpression));
|
||||
}
|
||||
|
||||
|
||||
@ -147,7 +144,7 @@ public final class GroupBy {
|
||||
* @param comparator
|
||||
* @return
|
||||
*/
|
||||
public static <E> AbstractGroupExpression<E, Set<E>> sortedSet(Expression<E> expression, Comparator<? super E> comparator) {
|
||||
public static <E> AbstractGroupExpression<E, SortedSet<E>> sortedSet(Expression<E> expression, Comparator<? super E> comparator) {
|
||||
return GSet.createSorted(expression, comparator);
|
||||
}
|
||||
|
||||
@ -158,8 +155,8 @@ public final class GroupBy {
|
||||
* @param comparator
|
||||
* @return
|
||||
*/
|
||||
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));
|
||||
public static <E, F> GroupExpression<E, SortedSet<F>> sortedSet(GroupExpression<E, F> groupExpression, Comparator<? super F> comparator) {
|
||||
return new MixinGroupExpression<E, F, SortedSet<F>>(groupExpression, GSet.createSorted(groupExpression, comparator));
|
||||
}
|
||||
|
||||
|
||||
@ -214,7 +211,7 @@ public final class GroupBy {
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static <K extends Comparable<? super 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>, SortedMap<K, V>> sortedMap(Expression<K> key, Expression<V> value) {
|
||||
return GMap.createSorted(QPair.create(key, value));
|
||||
}
|
||||
|
||||
@ -225,7 +222,7 @@ public final class GroupBy {
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
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) {
|
||||
public static <K extends Comparable<? super 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));
|
||||
}
|
||||
|
||||
@ -236,7 +233,7 @@ public final class GroupBy {
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static <K extends Comparable<? super 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>, SortedMap<K, U>> sortedMap(Expression<K> key, GroupExpression<V, U> value) {
|
||||
return sortedMap(new GOne<K>(key), value);
|
||||
}
|
||||
|
||||
@ -247,8 +244,8 @@ public final class GroupBy {
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
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 extends Comparable<? super K>, V, T extends Comparable<? super T>, U> AbstractGroupExpression<Pair<K, V>, SortedMap<T, U>> sortedMap(GroupExpression<K, T> key, GroupExpression<V, U> value) {
|
||||
return new GMap.Mixin<K, V, T, U, SortedMap<T, U>>(key, value, GMap.createSorted(QPair.create(key, value)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -259,7 +256,7 @@ public final class GroupBy {
|
||||
* @param comparator
|
||||
* @return
|
||||
*/
|
||||
public static <K, V> AbstractGroupExpression<Pair<K, V>,Map<K, V>> sortedMap(Expression<K> key, Expression<V> value, Comparator<? super K> comparator) {
|
||||
public static <K, V> AbstractGroupExpression<Pair<K, V>, SortedMap<K, V>> sortedMap(Expression<K> key, Expression<V> value, Comparator<? super K> comparator) {
|
||||
return GMap.createSorted(QPair.create(key, value), comparator);
|
||||
}
|
||||
|
||||
@ -271,7 +268,7 @@ public final class GroupBy {
|
||||
* @param comparator
|
||||
* @return
|
||||
*/
|
||||
public static <K, V, T> AbstractGroupExpression<Pair<K, V>, Map<T, V>> sortedMap(GroupExpression<K, T> key, Expression<V> value, Comparator<? super K> comparator) {
|
||||
public static <K, V, T> AbstractGroupExpression<Pair<K, V>, SortedMap<T, V>> sortedMap(GroupExpression<K, T> key, Expression<V> value, Comparator<? super K> comparator) {
|
||||
return sortedMap(key, new GOne<V>(value), comparator);
|
||||
}
|
||||
|
||||
@ -283,7 +280,7 @@ public final class GroupBy {
|
||||
* @param comparator
|
||||
* @return
|
||||
*/
|
||||
public static <K, V, U> AbstractGroupExpression<Pair<K, V>, Map<K, U>> sortedMap(Expression<K> key, GroupExpression<V, U> value, Comparator<? super U> comparator) {
|
||||
public static <K, V, U> AbstractGroupExpression<Pair<K, V>, SortedMap<K, U>> sortedMap(Expression<K> key, GroupExpression<V, U> value, Comparator<? super U> comparator) {
|
||||
return sortedMap(new GOne<K>(key), value, comparator);
|
||||
}
|
||||
|
||||
@ -295,8 +292,8 @@ public final class GroupBy {
|
||||
* @param comparator
|
||||
* @return
|
||||
*/
|
||||
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));
|
||||
public static <K, V, T, U> AbstractGroupExpression<Pair<K, V>, SortedMap<T, U>> sortedMap(GroupExpression<K, T> key, GroupExpression<V, U> value, Comparator<? super T> comparator) {
|
||||
return new GMap.Mixin<K, V, T, U, SortedMap<T, U>>(key, value, GMap.createSorted(QPair.create(key, value), comparator));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user