new UserComparator());
Lock readLock = systemGraph.getLock().readLock();
readLock.lock();
try {
while (users.hasNext()) {
sortedSet.add(new GraphNode(users.next(), systemGraph));
}
} finally {
readLock.unlock();
}
List<GraphNode> userList = new ArrayList<GraphNode>();
userList.addAll(sortedSet);
if (from == null || from < 0) {
logger.debug("Query parameter from is null or negative, set to 1");
from = 0;
}
if (to == null || to < 0) {
logger.debug("Query parameter to is null or negative, set to 10");
to = 10;
}
if (to > userList.size()) {
to = userList.size();
}
int prevFrom = from - 10;
int nextTo = to + 10;
if (prevFrom < 0) {
prevFrom = 0;
}
if (nextTo > userList.size()) {
nextTo = userList.size();
}
NonLiteral userOverviewPage = new BNode();
List<Resource> resultList = new RdfList(userOverviewPage, resultGraph);
for (int i = from; i < to; i++) {
resultList.add(userList.get(i).getNode());
}
UnionMGraph unionGraph = new UnionMGraph(resultGraph, systemGraph);
GraphNode result = new GraphNode(userOverviewPage, unionGraph);
result.addProperty(RDF.type, USERMANAGER.UserOverviewPage);
result.addProperty(RDF.type, PLATFORM.HeadedPage);
result.addProperty(LIST.predecessor, new UriRef(uriInfo
.getAbsolutePath().toString()
+ "?from=" + prevFrom + "&to=" + from));
result.addProperty(LIST.successor, new UriRef(uriInfo.getAbsolutePath()
.toString()
+ "?from=" + to + "&to=" + nextTo));
result.addProperty(LIST.indexFrom, LiteralFactory.getInstance()
.createTypedLiteral(from));
result.addProperty(LIST.indexTo, LiteralFactory.getInstance()
.createTypedLiteral(to));
result.addProperty(LIST.length, LiteralFactory.getInstance()
.createTypedLiteral(sortedSet.size()));
return result;
}