Skip to content

Instantly share code, notes, and snippets.

@okram
Created Nov 11, 2011
Embed
What would you like to do?
public Iterator<Long> evaluateQuery2(final Long shareId, int level, final Long startDate, final Long endDate) {
final Vertex root = g.idx(T.v)[[share_id: 2l]] >> 1;
int subLevel = Integer.MAX_VALUE;
final Vertex secondRoot = root.out('contains').loop(1) {def x = it.object.getProperty('share_id').equals(shareId); if (x) {subLevel = it.loops}; !x}.next();
if (level == 0) {
return secondRoot.out('contains').loopEmit(1) {true} {true}.
filter {it.getProperty('_startDate') <= startDate && (it.getProperty('_endDate').equals(-1l) || it.getProperty('_endDate') >= endDate)}.share_id
} else {
if (subLevel >= level) {
throw new IllegalArgumentException("The share node with provided id is greater than or equal to the desired level: !" + subLevel + " < " + level);
}
return secondRoot.out('contains').loop(1) {it.loops <= (level - subLevel)}.
filter {it.getProperty('_startDate') <= startDate && (it.getProperty('_endDate').equals(-1l) || it.getProperty('_endDate') >= endDate)}.share_id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment