Skip to content

Instantly share code, notes, and snippets.

@jukka
Created February 28, 2012 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jukka/1935626 to your computer and use it in GitHub Desktop.
Save jukka/1935626 to your computer and use it in GitHub Desktop.
jr3 MicroKernel read operations based on the Tree interface
public class MicroKernelImpl implements MicroKernel {
public boolean nodeExists(String path, String revisionId)
throws MicroKernelException {
Tree tree = getTree(revisionId);
for (String name : splitPathToElements(path)) {
if (tree == null) {
return false;
}
tree = tree.get(name);
}
return tree != null && !tree.isLeaf();
}
public String getNodes(String path, String revisionId)
throws MicroKernelException {
return getNodes(path, revisionId, 1, 0, -1);
}
public String getNodes(
String path, String revisionId, int depth, long offset, int count)
throws MicroKernelException {
Tree tree = getTree(revisionId);
for (String name : splitPathToElements(path)) {
if (tree == null) {
throw new MicroKernelException("Path not found: " + path);
}
tree = tree.get(name);
}
if (tree != null && !tree.isLeaf()) {
return serializeToJson(tree, depth, offset, count);
} else {
throw new MicroKernelException("Path not found: " + path);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment