org.apache.tinkerpop.gremlin.util.NumberHelper Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.util.NumberHelper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Aggregate.java From hugegraph with Apache License 2.0 | 6 votes |
public Number reduce(Iterator<Number> results) { Number number; long count = 0L; if (results.hasNext()) { number = results.next(); count++; } else { return null; } while (results.hasNext()) { number = this.merger.apply(number, results.next()); count++; } if (this == AVG) { number = NumberHelper.div(number, count); } return number; }
Example #2
Source File: ShortestPathVertexProgram.java From tinkerpop with Apache License 2.0 | 6 votes |
private void processEdges(final Vertex vertex, final Path currentPath, final Number currentDistance, final Messenger<Triplet<Path, Edge, Number>> messenger) { final Traversal.Admin<Vertex, Edge> edgeTraversal = this.edgeTraversal.getPure(); edgeTraversal.addStart(edgeTraversal.getTraverserGenerator().generate(vertex, edgeTraversal.getStartStep(), 1)); while (edgeTraversal.hasNext()) { final Edge edge = edgeTraversal.next(); final Number distance = getDistance(edge); Vertex otherV = edge.inVertex(); if (otherV.equals(vertex)) otherV = edge.outVertex(); // only send message if the adjacent vertex is not yet part of the current path if (!currentPath.objects().contains(otherV)) { messenger.sendMessage(MessageScope.Global.of(otherV), Triplet.with(currentPath, this.includeEdges ? edge : null, NumberHelper.add(currentDistance, distance))); } } }
Example #3
Source File: SumLocalStep.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override protected E map(final Traverser.Admin<S> traverser) { final Iterator<E> iterator = traverser.get().iterator(); if (iterator.hasNext()) { Number result = iterator.next(); while (iterator.hasNext()) { result = NumberHelper.add(result, iterator.next()); } return (E) result; } throw FastNoSuchElementException.instance(); }
Example #4
Source File: MeanLocalStep.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override protected Number map(final Traverser.Admin<S> traverser) { final Iterator<E> iterator = traverser.get().iterator(); if (iterator.hasNext()) { Long counter = 1L; E result = iterator.next(); while (iterator.hasNext()) { result = (E) NumberHelper.add(result, iterator.next()); counter++; } return NumberHelper.div(result, counter, true); } throw FastNoSuchElementException.instance(); }
Example #5
Source File: ShortestPathVertexProgram.java From tinkerpop with Apache License 2.0 | 5 votes |
private boolean exceedsMaxDistance(final Number distance) { // This method is used to stop the message sending for paths that exceed the specified maximum distance. Since // custom distances can be negative, this method should only return true if the distance is calculated based on // the number of hops. return this.distanceEqualsNumberOfHops && this.maxDistance != null && NumberHelper.compare(distance, this.maxDistance) > 0; }
Example #6
Source File: ShortestPathVertexProgram.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * Move any valid path into the VP's memory. * @param vertex The current vertex. * @param memory The VertexProgram's memory. */ private void collectShortestPaths(final Vertex vertex, final Memory memory) { final VertexProperty<Map<Vertex, Pair<Number, Set<Path>>>> pathProperty = vertex.property(PATHS); if (pathProperty.isPresent()) { final Map<Vertex, Pair<Number, Set<Path>>> paths = pathProperty.value(); final List<Path> result = new ArrayList<>(); for (final Pair<Number, Set<Path>> pair : paths.values()) { for (final Path path : pair.getValue1()) { if (isEndVertex(vertex)) { if (this.distanceEqualsNumberOfHops || this.maxDistance == null || NumberHelper.compare(pair.getValue0(), this.maxDistance) <= 0) { result.add(path); } } } } pathProperty.remove(); memory.add(SHORTEST_PATHS, result); } }
Example #7
Source File: SqlgBranchStepBarrier.java From sqlg with MIT License | 5 votes |
@Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final PickTokenKey other = (PickTokenKey) o; return 0 == NumberHelper.compare(number, other.number); }
Example #8
Source File: MeanGlobalStep.java From tinkerpop with Apache License 2.0 | 4 votes |
public MeanNumber add(final Number amount, final long count) { this.count += count; this.sum = NumberHelper.add(sum, mul(amount, count)); return this; }
Example #9
Source File: MeanGlobalStep.java From tinkerpop with Apache License 2.0 | 4 votes |
public MeanNumber add(final MeanNumber other) { this.count += other.count; this.sum = NumberHelper.add(sum, other.sum); return this; }