use of com.mysema.commons.lang.Pair in project querydsl by querydsl.
the class GroupByIterateTest method map22.
@Test
public void map22() {
CloseableIterator<Map<Integer, String>> results = MAP2_RESULTS.transform(groupBy(postId).iterate(map(commentId, commentText)));
List<Map<Integer, String>> actual = IteratorAdapter.asList(results);
Object commentId = null;
Map<Integer, String> comments = null;
List<Map<Integer, String>> expected = new LinkedList<Map<Integer, String>>();
for (Iterator<Tuple> iterator = MAP2_RESULTS.iterate(); iterator.hasNext(); ) {
Tuple tuple = iterator.next();
Object[] array = tuple.toArray();
if (comments == null || !(commentId == array[0] || commentId != null && commentId.equals(array[0]))) {
comments = new LinkedHashMap<Integer, String>();
expected.add(comments);
}
commentId = array[0];
@SuppressWarnings("unchecked") Pair<Integer, String> pair = (Pair<Integer, String>) array[1];
comments.put(pair.getFirst(), pair.getSecond());
}
assertEquals(expected.toString(), actual.toString());
}
use of com.mysema.commons.lang.Pair in project querydsl by querydsl.
the class GroupByIterateTest method map4.
@Test
public void map4() {
CloseableIterator<Map<Map<Integer, String>, String>> results = MAP4_RESULTS.transform(groupBy(postId).iterate(map(map(postId, commentText), postName)));
List<Map<Map<Integer, String>, String>> actual = IteratorAdapter.asList(results);
Object commentId = null;
Map<Map<Integer, String>, String> comments = null;
List<Map<Map<Integer, String>, String>> expected = new LinkedList<Map<Map<Integer, String>, String>>();
for (Iterator<Tuple> iterator = MAP4_RESULTS.iterate(); iterator.hasNext(); ) {
Tuple tuple = iterator.next();
Object[] array = tuple.toArray();
if (comments == null || !(commentId == array[0] || commentId != null && commentId.equals(array[0]))) {
comments = new LinkedHashMap<Map<Integer, String>, String>();
expected.add(comments);
}
commentId = array[0];
@SuppressWarnings("unchecked") Pair<Pair<Integer, String>, String> pair = (Pair<Pair<Integer, String>, String>) array[1];
Pair<Integer, String> first = pair.getFirst();
Map<Integer, String> posts = Collections.singletonMap(first.getFirst(), first.getSecond());
comments.put(posts, pair.getSecond());
}
assertEquals(expected.toString(), actual.toString());
}
use of com.mysema.commons.lang.Pair in project querydsl by querydsl.
the class GroupByMapTest method map3.
@Test
public void map3() {
Map<Integer, Map<Integer, Map<Integer, String>>> actual = MAP3_RESULTS.transform(groupBy(postId).as(map(postId, map(commentId, commentText))));
Map<Integer, Map<Integer, Map<Integer, String>>> expected = new LinkedHashMap<Integer, Map<Integer, Map<Integer, String>>>();
for (Iterator<Tuple> iterator = MAP3_RESULTS.iterate(); iterator.hasNext(); ) {
Tuple tuple = iterator.next();
Object[] array = tuple.toArray();
Map<Integer, Map<Integer, String>> posts = expected.get(array[0]);
if (posts == null) {
posts = new LinkedHashMap<Integer, Map<Integer, String>>();
expected.put((Integer) array[0], posts);
}
@SuppressWarnings("unchecked") Pair<Integer, Pair<Integer, String>> pair = (Pair<Integer, Pair<Integer, String>>) array[1];
Integer first = pair.getFirst();
Map<Integer, String> comments = posts.computeIfAbsent(first, k -> new LinkedHashMap<Integer, String>());
Pair<Integer, String> second = pair.getSecond();
comments.put(second.getFirst(), second.getSecond());
}
assertEquals(expected.toString(), actual.toString());
}
use of com.mysema.commons.lang.Pair in project querydsl by querydsl.
the class GroupByMapTest method map4.
@Test
public void map4() {
Map<Integer, Map<Map<Integer, String>, String>> actual = MAP4_RESULTS.transform(groupBy(postId).as(map(map(postId, commentText), postName)));
Map<Integer, Map<Map<Integer, String>, String>> expected = new LinkedHashMap<Integer, Map<Map<Integer, String>, String>>();
for (Iterator<Tuple> iterator = MAP4_RESULTS.iterate(); iterator.hasNext(); ) {
Tuple tuple = iterator.next();
Object[] array = tuple.toArray();
Map<Map<Integer, String>, String> comments = expected.get(array[0]);
if (comments == null) {
comments = new LinkedHashMap<Map<Integer, String>, String>();
expected.put((Integer) array[0], comments);
}
@SuppressWarnings("unchecked") Pair<Pair<Integer, String>, String> pair = (Pair<Pair<Integer, String>, String>) array[1];
Pair<Integer, String> first = pair.getFirst();
Map<Integer, String> posts = Collections.singletonMap(first.getFirst(), first.getSecond());
comments.put(posts, pair.getSecond());
}
assertEquals(expected.toString(), actual.toString());
}
use of com.mysema.commons.lang.Pair in project querydsl by querydsl.
the class GroupByListTest method map3.
@Test
public void map3() {
List<Map<Integer, Map<Integer, String>>> actual = MAP3_RESULTS.transform(groupBy(postId).list(map(postId, map(commentId, commentText))));
Object postId = null;
Map<Integer, Map<Integer, String>> posts = null;
List<Map<Integer, Map<Integer, String>>> expected = new LinkedList<Map<Integer, Map<Integer, String>>>();
for (Iterator<Tuple> iterator = MAP3_RESULTS.iterate(); iterator.hasNext(); ) {
Tuple tuple = iterator.next();
Object[] array = tuple.toArray();
if (posts == null || !(postId == array[0] || postId != null && postId.equals(array[0]))) {
posts = new LinkedHashMap<Integer, Map<Integer, String>>();
expected.add(posts);
}
postId = array[0];
@SuppressWarnings("unchecked") Pair<Integer, Pair<Integer, String>> pair = (Pair<Integer, Pair<Integer, String>>) array[1];
Integer first = pair.getFirst();
Map<Integer, String> comments = posts.computeIfAbsent(first, k -> new LinkedHashMap<Integer, String>());
Pair<Integer, String> second = pair.getSecond();
comments.put(second.getFirst(), second.getSecond());
}
assertEquals(expected.toString(), actual.toString());
}
Aggregations