use of io.americanexpress.synapse.service.graphql.model.UniversallyUniqueIdentifiable in project synapse by americanexpress.
the class ConnectionUtil method create.
/**
* Create the {@link Connection}.
* @param <T> type of {@link UniversallyUniqueIdentifiable} element
* @param elements used to create the edges of the connection
* @param first number of elements
* @param after the opaque cursor
* @return the {@link Connection}
*/
public static final <T extends UniversallyUniqueIdentifiable> Connection<T> create(List<T> elements, long first, String after) {
// Get the limit of this stream which is either the number of elements
// specified by "first"; otherwise the full elements size
long limit = first > 0 ? first : elements.size();
// Create the edges for the connection
List<Edge<T>> edges = elements.stream().limit(limit).map(element -> new DefaultEdge<>(element, ConnectionCursorUtil.from(element.getId()))).collect(Collectors.toList());
// Create the page information for the connection
ConnectionCursor startCursor = ConnectionCursorUtil.getStartCursor(edges);
ConnectionCursor endCursor = ConnectionCursorUtil.getEndCursor(edges);
boolean hasPreviousPage = after != null;
boolean hasNextPage = edges.size() >= first;
PageInfo pageInfo = new DefaultPageInfo(startCursor, endCursor, hasPreviousPage, hasNextPage);
return new DefaultConnection<>(edges, pageInfo);
}
Aggregations