mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Refactored group definitions set->withSet, first->withOne etc. and group getters set->getSet, first->getOne etc.
This commit is contained in:
parent
96c3b78994
commit
ae3cd8da3f
@ -149,7 +149,7 @@ public class RelationTest extends AbstractTest{
|
||||
public void List_Usage(){
|
||||
String expected = "relationType.list.get(0).set";
|
||||
assertEquals(expected, QRelationTest_RelationType.relationType.list.get(0).set.toString());
|
||||
assertEquals(expected, QRelationTest_RelationType.relationType.list(0).set.toString());
|
||||
assertEquals(expected, QRelationTest_RelationType.relationType.getList(0).set.toString());
|
||||
|
||||
assertEquals(List.class, QRelationTest_RelationType.relationType.list.getType());
|
||||
assertEquals(Set.class, QRelationTest_RelationType.relationType.set.getType());
|
||||
|
||||
@ -125,13 +125,13 @@ public class GroupBy2<S> implements ResultTransformer<Map<S, Group2>> {
|
||||
|
||||
Object[] toArray();
|
||||
|
||||
<T> T first(Expression<T> expr);
|
||||
<T> T getOne(Expression<T> expr);
|
||||
|
||||
<T> Set<T> set(Expression<T> expr);
|
||||
<T> Set<T> getSet(Expression<T> expr);
|
||||
|
||||
<T> List<T> list(Expression<T> expr);
|
||||
<T> List<T> getList(Expression<T> expr);
|
||||
|
||||
<K, V> Map<K, V> map(Expression<K> key, Expression<V> value);
|
||||
<K, V> Map<K, V> getMap(Expression<K> key, Expression<V> value);
|
||||
|
||||
}
|
||||
|
||||
@ -229,9 +229,9 @@ public class GroupBy2<S> implements ResultTransformer<Map<S, Group2>> {
|
||||
}
|
||||
|
||||
|
||||
public static class GFirst<T> extends AbstractGroupColumnDefinition<T, T>{
|
||||
public static class GOne<T> extends AbstractGroupColumnDefinition<T, T>{
|
||||
|
||||
public GFirst(Expression<T> expr) {
|
||||
public GOne(Expression<T> expr) {
|
||||
super(expr);
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ public class GroupBy2<S> implements ResultTransformer<Map<S, Group2>> {
|
||||
}
|
||||
|
||||
public GroupBy2(Expression<S> groupBy) {
|
||||
columns.add(new GFirst<S>(groupBy));
|
||||
columns.add(new GOne<S>(groupBy));
|
||||
}
|
||||
|
||||
public <T> GroupBy2(Expression<S> groupBy, GroupColumnDefinition<?, ?> group, GroupColumnDefinition<?, ?>... groups) {
|
||||
@ -276,29 +276,25 @@ public class GroupBy2<S> implements ResultTransformer<Map<S, Group2>> {
|
||||
}
|
||||
}
|
||||
|
||||
public GroupBy2<S> group(GroupColumnDefinition<?, ?> g) {
|
||||
public GroupBy2<S> withGroup(GroupColumnDefinition<?, ?> g) {
|
||||
columns.add(g);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> GroupBy2<S> set(Expression<T> expr) {
|
||||
columns.add(new GSet<T>(expr));
|
||||
return this;
|
||||
public <T> GroupBy2<S> withSet(Expression<T> expr) {
|
||||
return withGroup(new GSet<T>(expr));
|
||||
}
|
||||
|
||||
public <T> GroupBy2<S> list(Expression<T> expr) {
|
||||
columns.add(new GList<T>(expr));
|
||||
return this;
|
||||
public <T> GroupBy2<S> withList(Expression<T> expr) {
|
||||
return withGroup(new GList<T>(expr));
|
||||
}
|
||||
|
||||
public <T> GroupBy2<S> first(Expression<T> expr) {
|
||||
columns.add(new GFirst<T>(expr));
|
||||
return this;
|
||||
public <T> GroupBy2<S> withOne(Expression<T> expr) {
|
||||
return withGroup(new GOne<T>(expr));
|
||||
}
|
||||
|
||||
public <K, V> GroupBy2<S> map(Expression<K> key, Expression<V> value) {
|
||||
columns.add(new GMap<K, V>(key, value));
|
||||
return this;
|
||||
public <K, V> GroupBy2<S> withMap(Expression<K> key, Expression<V> value) {
|
||||
return withGroup(new GMap<K, V>(key, value));
|
||||
}
|
||||
|
||||
private class GroupImpl implements Group2 {
|
||||
@ -314,21 +310,21 @@ public class GroupBy2<S> implements ResultTransformer<Map<S, Group2>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T first(Expression<T> expr) {
|
||||
public <T> T getOne(Expression<T> expr) {
|
||||
return (T) groupColumns.get(expr).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Set<T> set(Expression<T> expr) {
|
||||
public <T> Set<T> getSet(Expression<T> expr) {
|
||||
return (Set<T>) groupColumns.get(expr).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> list(Expression<T> expr) {
|
||||
public <T> List<T> getList(Expression<T> expr) {
|
||||
return (List<T>) groupColumns.get(expr).get();
|
||||
}
|
||||
|
||||
public <K, V> Map<K, V> map(Expression<K> key, Expression<V> value) {
|
||||
public <K, V> Map<K, V> getMap(Expression<K> key, Expression<V> value) {
|
||||
return (Map<K, V>) groupColumns.get(new QPair<K, V>(key, value)).get();
|
||||
}
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ public class GroupBy2Test {
|
||||
@Test
|
||||
public void Group_Order() {
|
||||
Map<Integer, Group2> results =
|
||||
GroupBy2.groupBy(postId).first(postName).set(commentId).transform(BASIC_RESULTS);
|
||||
GroupBy2.groupBy(postId).withOne(postName).withSet(commentId).transform(BASIC_RESULTS);
|
||||
|
||||
assertEquals(4, results.size());
|
||||
}
|
||||
@ -78,23 +78,23 @@ public class GroupBy2Test {
|
||||
@Test
|
||||
public void First_Set_And_List() {
|
||||
Map<Integer, Group2> results =
|
||||
GroupBy2.groupBy(postId).first(postName).set(commentId).list(commentText).transform(BASIC_RESULTS);
|
||||
GroupBy2.groupBy(postId).withOne(postName).withSet(commentId).withList(commentText).transform(BASIC_RESULTS);
|
||||
|
||||
Group2 group = results.get(1);
|
||||
assertEquals(toInt(1), group.first(postId));
|
||||
assertEquals("post 1", group.first(postName));
|
||||
assertEquals(toSet(1, 2, 3), group.set(commentId));
|
||||
assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), group.list(commentText));
|
||||
assertEquals(toInt(1), group.getOne(postId));
|
||||
assertEquals("post 1", group.getOne(postName));
|
||||
assertEquals(toSet(1, 2, 3), group.getSet(commentId));
|
||||
assertEquals(Arrays.asList("comment 1", "comment 2", "comment 3"), group.getList(commentText));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Map() {
|
||||
Map<Integer, Group2> results =
|
||||
GroupBy2.groupBy(postId).first(postName).map(commentId, commentText).transform(MAP_RESULTS);
|
||||
GroupBy2.groupBy(postId).withOne(postName).withMap(commentId, commentText).transform(MAP_RESULTS);
|
||||
|
||||
Group2 group = results.get(1);
|
||||
|
||||
Map<Integer, String> comments = group.map(commentId, commentText);
|
||||
Map<Integer, String> comments = group.getMap(commentId, commentText);
|
||||
assertEquals(3, comments.size());
|
||||
assertEquals("comment 2", comments.get(2));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user