@Test public void set_by_sorted_reverse() { Map<Integer, Group> results = BASIC_RESULTS_UNORDERED .transform(groupBy(postId).as(postName, sortedSet(commentId, Ordering.natural().reverse()))); Group group = results.get(1); Iterator<Integer> it = group.getSet(commentId).iterator(); assertEquals(3, it.next().intValue()); assertEquals(2, it.next().intValue()); assertEquals(1, it.next().intValue()); }
@Test public void set_by_sorted() { Map<Integer, Group> results = BASIC_RESULTS_UNORDERED .transform(groupBy(postId).as(postName, sortedSet(commentId))); Group group = results.get(1); Iterator<Integer> it = group.getSet(commentId).iterator(); assertEquals(1, it.next().intValue()); assertEquals(2, it.next().intValue()); assertEquals(3, it.next().intValue()); }
@Override protected Post transform(Group group) { return new Post( group.getOne(postId), group.getOne(postName), group.getSet(qComment)); } });
@Test(expected = NoSuchElementException.class) public void noSuchElementException() { Map<Integer, Group> results = BASIC_RESULTS.transform( groupBy(postId).as(postName, set(commentId), list(commentText))); Group group = results.get(1); group.getSet(qComment); }
@Test(expected = NoSuchElementException.class) public void noSuchElementException() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(1); group.getSet(qComment); }
@Test(expected = NoSuchElementException.class) public void noSuchElementException() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(1); group.getSet(qComment); }
@Test public void first_set_and_list() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(1); 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 group_by_null() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(0); assertNull(group.getOne(postId)); assertEquals("null post", group.getOne(postName)); assertEquals(toSet(7, 8), group.getSet(commentId)); assertEquals(Arrays.asList("comment 7", "comment 8"), group.getList(commentText)); }
@Test public void group_by_null() { List<Group> results = BASIC_RESULTS.transform( groupBy(postId).list(postName, set(commentId), list(commentText))); assertEquals(4, results.size()); Group group = results.get(0); assertNull(group.getOne(postId)); assertEquals("null post", group.getOne(postName)); assertEquals(toSet(7, 8), group.getSet(commentId)); assertEquals(Arrays.asList("comment 7", "comment 8"), group.getList(commentText)); }
@Test public void first_set_and_list() { CloseableIterator<Group> resultsIt = BASIC_RESULTS.transform( groupBy(postId).iterate(postName, set(commentId), list(commentText))); List<Group> results = IteratorAdapter.asList(resultsIt); assertEquals(4, results.size()); Group group = results.get(1); 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 group_by_null() { Map<Integer, Group> results = BASIC_RESULTS.transform( groupBy(postId).as(postName, set(commentId), list(commentText))); Group group = results.get(null); assertNull(group.getOne(postId)); assertEquals("null post", group.getOne(postName)); assertEquals(toSet(7, 8), group.getSet(commentId)); assertEquals(Arrays.asList("comment 7", "comment 8"), group.getList(commentText)); }
@Test public void first_set_and_list() { Map<Integer, Group> results = BASIC_RESULTS.transform( groupBy(postId).as(postName, set(commentId), list(commentText))); Group group = results.get(1); 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)); }
protected ObjectVersion<M> buildVersion(Revision rev, Group versionAndParents, Map<PropertyPath, Object> changeset) { if (!options.versionTableProperties.isEmpty()) { if (changeset == null) { changeset = new HashMap<>(); } for (Map.Entry<PropertyPath, Path<?>> entry : options.versionTableProperties.entrySet()) { PropertyPath path = entry.getKey(); @SuppressWarnings("unchecked") Path<Object> column = (Path<Object>) entry.getValue(); changeset.put(path, versionAndParents.getOne(column)); } } return new ObjectVersion.Builder<M>(rev) .branch(versionAndParents.getOne(options.version.branch)) .type(versionAndParents.getOne(options.version.type)) .parents(versionAndParents.getSet(options.parent.parentRevision)) .changeset(changeset) .meta(getMeta(versionAndParents)) .build(); }