/** * Returns the sum of all elements in this memory. * * @return the sum of all elements in this memory. */ public double getSum() { double sum = 0d; for (N value : list) { sum += value.doubleValue(); } return sum; }
protected <N extends Number> NumericRangeQuery<?> numericRange( Class<N> clazz, String field, @Nullable N min, @Nullable N max, boolean minInc, boolean maxInc) { if (clazz.equals(Integer.class)) { return NumericRangeQuery.newIntRange(field, (Integer) min, (Integer) max, minInc, maxInc); } else if (clazz.equals(Double.class)) { return NumericRangeQuery.newDoubleRange(field, (Double) min, (Double) max, minInc, minInc); } else if (clazz.equals(Float.class)) { return NumericRangeQuery.newFloatRange(field, (Float) min, (Float) max, minInc, minInc); } else if (clazz.equals(Long.class)) { return NumericRangeQuery.newLongRange(field, (Long) min, (Long) max, minInc, minInc); } else if (clazz.equals(Byte.class) || clazz.equals(Short.class)) { return NumericRangeQuery.newIntRange( field, min != null ? min.intValue() : null, max != null ? max.intValue() : null, minInc, maxInc); } else { throw new IllegalArgumentException("Unsupported numeric type " + clazz.getName()); } }
@SuppressWarnings("unchecked") private P run(AStarStorage storage, AStarGoal<N> goal, N start, int maxIterations) { Preconditions.checkNotNull(goal); Preconditions.checkNotNull(start); Preconditions.checkNotNull(storage); N node; int iterations = 0; while (true) { node = (N) storage.removeBestNode(); if (node == null) { return null; } if (goal.isFinished(node)) { return (P) node.buildPlan(); } storage.close(node); for (AStarNode neighbour : node.getNeighbours()) { f(goal, node, (N) neighbour); if (!storage.shouldExamine(neighbour)) continue; storage.open(neighbour); neighbour.parent = node; } if (maxIterations >= 0 && iterations++ >= maxIterations) { return null; } } }
/** * Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed * to work. * * @param depth The depth to indent the sub-nodes */ public void printSubNodes(int depth) { for (int index = 0; index < size(); index++) { debugPrint(formatNodeString("[" + index + "]:", depth)); N elt = get(index); elt.treePrint(depth); } }
public DOMHeader(N node) { assert node != null; this.node = node; this.nsUri = fixNull(node.getNamespaceURI()); this.localName = node.getLocalName(); }
@Override protected <N, T> void notNeighbor( final TypedModelAdapter<N, T> adapter, final T type, final N source, final N target) { super.notNeighbor( neo4jAdapter, type.toString(), nodeMapping.get(source.toString()), nodeMapping.get(target.toString())); }
private void f(AStarGoal<N> goal, N node, N neighbour) { float g = node.g + goal.g(node, neighbour); // estimate the cost from // the start additively float h = goal.h(neighbour); neighbour.f = g + h; neighbour.g = g; neighbour.h = h; }
protected static <N extends Node> Integer indexInList(N search, List<N> nodes) { Preconditions.checkNotNull(search); Preconditions.checkNotNull(nodes); for (int i = 0; i < nodes.size(); i++) { N node = nodes.get(i); if (node.equals(search)) return i; } return null; }
/** * @param bottom Lowest value to be included * @param top Highest value to be included * @param spacing How far apart should the contours be placed? * @return List of the contour step values */ public static <N extends Number> List<N> steps(N bottom, N top, double spacing) { int stepCount = (int) Math.ceil((top.doubleValue() - bottom.doubleValue()) / spacing); ArrayList<N> steps = new ArrayList<>(stepCount); for (int i = 0; i < stepCount; i++) { steps.add(LocalUtils.addTo(bottom, (i * spacing))); } return steps; }
/** * @param map1 * @param map2 * @return */ public static < K1, V1, K2, V2, L extends Map<? super K1, ? super V1>, R extends Map<? super K2, ? super V2>, D extends Map<?, Pair0<V1, V2>>> MapDifference<L, R, D> of(Map<K1, V1> map1, Map<K2, V2> map2) { final L common = (L) new LinkedHashMap<>(); final L leftOnly = (L) new LinkedHashMap<>(); final R rightOnly = (R) new LinkedHashMap<>(); final Map<Object, Pair0<V1, V2>> diff = new LinkedHashMap<>(); if (N.isNullOrEmpty(map1)) { if (N.isNullOrEmpty(map2)) { // Do nothing. All empty. } else { rightOnly.putAll(map2); } } else if (N.isNullOrEmpty(map2)) { leftOnly.putAll(map1); } else { V2 val2 = null; for (Entry<K1, V1> entry1 : map1.entrySet()) { val2 = map2.get(entry1.getKey()); if (val2 == null) { if (map2.containsKey(entry1.getKey())) { if (entry1.getValue() == null) { common.put(entry1.getKey(), entry1.getValue()); } else { diff.put(entry1.getKey(), Pair0.of(entry1.getValue(), val2)); } } else { leftOnly.put(entry1.getKey(), entry1.getValue()); } } else if (N.equals(entry1.getValue(), val2)) { common.put(entry1.getKey(), entry1.getValue()); } else { diff.put(entry1.getKey(), Pair0.of(entry1.getValue(), val2)); } } for (Entry<K2, V2> entry2 : map2.entrySet()) { if (common.containsKey(entry2.getKey()) || diff.containsKey(entry2.getKey())) { continue; } rightOnly.put(entry2.getKey(), entry2.getValue()); } } return new MapDifference<L, R, D>(common, leftOnly, rightOnly, (D) diff); }
@Override public boolean include(final N namedObject) { if (namedObject == null) { return false; } // Schema names may be null if (namedObject.getFullName() == null) { return false; } return inclusionRule.include(namedObject.getFullName()); }
@Override public N getNode(String id) { N result = null; for (N node : this.getNodes()) { if (node.getId().equals(id)) { result = node; break; } } return result; }
/** * @param entity1 * @param entity2 * @return */ public static MapDifference< Map<String, Object>, Map<String, Object>, Map<String, Pair0<Object, Object>>> of(Object entity1, Object entity2) { if (N.isEntity(entity1.getClass()) == false || N.isEntity(entity2.getClass()) == false) { throw new IllegalArgumentException( entity1.getClass().getCanonicalName() + " or " + entity2.getClass().getCanonicalName() + " is not an entity class"); } return of(N.entity2Map(entity1), N.entity2Map(entity2)); }
/** * Updates the particle view. This should be called on each draw cycle in order to update the * positions of all nodes and edges in the viewer. If you need to update the positions of * particles without drawing it (e.g. to speed up movement, call updateParticles() instead. */ public void draw() { parent.pushStyle(); parent.pushMatrix(); zoomer.transform(); updateCentroid(); centroid.tick(); parent.translate(width / 2, height / 2); parent.scale(centroid.getZ()); parent.translate(-centroid.getX(), -centroid.getY()); if (!isPaused) { updateParticles(); } // Ensure that any selected element is positioned at the mouse location. if (selectedNode != null) { Particle p = nodes.get(selectedNode); p.makeFixed(); float mX = (zoomer.getMouseCoord().x - (width / 2)) / centroid.getZ() + centroid.getX(); float mY = (zoomer.getMouseCoord().y - (height / 2)) / centroid.getZ() + centroid.getY(); p.position().set(mX, mY, 0); } // Draw edges if we have positive stroke weight. if (parent.g.strokeWeight > 0) { parent.stroke(0, 180); parent.noFill(); for (Map.Entry<E, Spring> row : edges.entrySet()) { E edge = row.getKey(); Spring spring = row.getValue(); Vector3D p1 = spring.getOneEnd().position(); Vector3D p2 = spring.getTheOtherEnd().position(); edge.draw(parent, p1.x(), p1.y(), p2.x(), p2.y()); } } // Draw nodes. parent.noStroke(); parent.fill(120, 50, 50, 180); for (Map.Entry<N, Particle> row : nodes.entrySet()) { N node = row.getKey(); Vector3D p = row.getValue().position(); node.draw(parent, p.x(), p.y()); } parent.popMatrix(); parent.popStyle(); }
public <A, N extends DynamicNetwork<A, N>> DynamicNetwork<A, N> getNetworkFromOrphan( IGridTransmitter<A, N> startOrphan) { if (startOrphan.isValid() && startOrphan.isOrphan()) { OrphanPathFinder<A, N> finder = new OrphanPathFinder<A, N>(startOrphan); finder.start(); N network; switch (finder.networksFound.size()) { case 0: if (MekanismAPI.debug) { logger.info( "No networks found. Creating new network for " + finder.connectedTransmitters.size() + " transmitters"); } network = startOrphan.createEmptyNetwork(); break; case 1: if (MekanismAPI.debug) { logger.info( "Adding " + finder.connectedTransmitters.size() + " transmitters to single found network"); } network = finder.networksFound.iterator().next(); break; default: if (MekanismAPI.debug) { logger.info( "Merging " + finder.networksFound.size() + " networks with " + finder.connectedTransmitters.size() + " new transmitters"); } network = startOrphan.mergeNetworks(finder.networksFound); } network.addNewTransmitters(finder.connectedTransmitters); return network; } return null; }
@Override public boolean accept(ASTVisitor action) { N stack = null; ICPPASTIfStatement stmt = this; loop: for (; ; ) { if (action.shouldVisitStatements) { switch (action.visit(stmt)) { case ASTVisitor.PROCESS_ABORT: return false; case ASTVisitor.PROCESS_SKIP: stmt = null; break loop; default: break; } } if (!((CPPASTIfStatement) stmt).acceptByAttributeSpecifiers(action)) return false; IASTNode child = stmt.getConditionExpression(); if (child != null && !child.accept(action)) return false; child = stmt.getConditionDeclaration(); if (child != null && !child.accept(action)) return false; child = stmt.getThenClause(); if (child != null && !child.accept(action)) return false; child = stmt.getElseClause(); if (child instanceof ICPPASTIfStatement) { if (action.shouldVisitStatements) { N n = new N(stmt); n.fNext = stack; stack = n; } stmt = (ICPPASTIfStatement) child; } else { if (child != null && !child.accept(action)) return false; break loop; } } if (action.shouldVisitStatements) { if (stmt != null && action.leave(stmt) == ASTVisitor.PROCESS_ABORT) return false; while (stack != null) { if (action.leave(stack.fIfStatement) == ASTVisitor.PROCESS_ABORT) return false; stack = stack.fNext; } } return true; }
private <N extends InternalTitanVertex> void persist( ListMultimap<N, InternalRelation> mutatedEdges, Map<TitanType, TypeSignature> signatures, InternalTitanTransaction tx, StoreMutator mutator) throws StorageException { assert mutatedEdges != null && !mutatedEdges.isEmpty(); Collection<N> vertices = mutatedEdges.keySet(); // if (sortNodes) { // List<N> sortedvertices = new ArrayList<N>(vertices); // Collections.sort(sortedvertices, new Comparator<N>(){ // // @Override // public int compare(N o1, N o2) { // assert o1.getID()!=o2.getID(); // if (o1.getID()<o2.getID()) return -1; // else return 1; // } // // }); // vertices=sortedvertices; // } for (N node : vertices) { List<InternalRelation> edges = mutatedEdges.get(node); List<Entry> additions = new ArrayList<Entry>(edges.size()); List<ByteBuffer> deletions = new ArrayList<ByteBuffer>(Math.max(10, edges.size() / 10)); List<TitanProperty> properties = new ArrayList<TitanProperty>(); for (InternalRelation edge : edges) { if (edge.isRemoved()) { if (edge.isProperty()) { deleteIndexEntry((TitanProperty) edge, mutator); } deletions.add(getEntry(tx, edge, node, signatures, true).getColumn()); } else { assert edge.isNew(); if (edge.isProperty()) properties.add((TitanProperty) edge); additions.add(getEntry(tx, edge, node, signatures)); } } mutator.mutateEdges(IDHandler.getKey(node.getID()), additions, deletions); // Persist property index for retrieval for (TitanProperty prop : properties) { addIndexEntry(prop, mutator); } } }
public N<Boolean> then(N<Boolean> paramN) { if (!((Boolean)paramN.e()).booleanValue()) { return paramN; } return val$matcher.matchesAsync(val$object, val$db); }
private Entry _sibling(Entry current, N name) throws StaxNavException { if (current != null) { Entry element = current; while (true) { Entry next = element.next(); if (next != null && next.getElement().getDepth() >= current.getElement().getDepth()) { if (next.getElement().getDepth() == current.getElement().getDepth()) { if (name == null) { current = next; return current; } else { N siblingName = naming.getName(next.getElement().getName()); if (name.equals(siblingName)) { current = next; return current; } else { element = next; } } } else { element = next; } } else { break; } } } return null; }
private Entry _current(Entry current, N name) throws StaxNavException { if (current != null) { if (name == null || name.equals(naming.getName(current.getElement().getName()))) { return current; } } return null; }
@Override public N getNode(T elkEntity) { if (node.contains(elkEntity)) { return node; } else { return null; } }
/** {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public <N extends Number> Expression<N> sum(N x, Expression<? extends N> y) { final TypeImpl<N> type = (TypeImpl<N>) this.metamodel.type(x.getClass()); return new ArithmeticExression<N>( ArithmeticOperation.ADD, new EntityConstantExpression<N>(type, x), y); }
public int lastIndexOfFifth(N m, int index) { try { for (int i = index; i >= 0; i--) { if ((m == null ? get(i).fifth == null : m.equals(get(i).fifth))) return i; } } catch (final Exception e) { } return -1; }
static <T> N<T> callbackOnMainThreadAsync(N<T> paramN, ParseCallback<T> paramParseCallback, boolean paramBoolean) { if (paramParseCallback == null) { return paramN; } Z localZ = N.a(); paramN.a(new Parse.6(paramBoolean, localZ, paramParseCallback)); return localZ.a(); }
public void addNode(N node) { String namespace = getNamespace(node); List<String> pathElements = new ArrayList<String>(Arrays.asList(namespace.split("\\."))); if (pathElements.size() == 1 && pathElements.get(0).equals("")) { pathElements.remove(0); } addNode(node, getSubnamespace(myRootNamespace, pathElements, node.getOperationContext())); }
public boolean find(N name) throws StaxNavException { if (name == null) { throw new NullPointerException("No null name accepted"); } if (name.equals(naming.getName(current.getElement().getName()))) { return true; } else { return navigate(Axis.FOLLOWING, name); } }
@Override public Float64 apply(final N value) { final double x = value.doubleValue(); Float64 result = Float64.ZERO; if (x >= _min && x <= _max) { result = Float64.valueOf(_k * x + _d); } return result; }
private Entry _next(Entry current, N name) throws StaxNavException { if (current != null) { Entry next = current.next(depth); if (next != null && (name == null || name.equals(naming.getName(next.getElement().getName())))) { current = next; return current; } } return null; }
/** * Returns the next element of this enumeration if this enumeration object has at least one more * element to provide. * * @return the next element of this enumeration. * @throws java.util.NoSuchElementException if no more elements exist. */ @Override public IndexTreePath<E> nextElement() { Enumeration<IndexTreePath<E>> enumeration = queue.peek(); IndexTreePath<E> nextPath = enumeration.nextElement(); Enumeration<IndexTreePath<E>> children; if (nextPath.getEntry().isLeafEntry()) { children = EMPTY_ENUMERATION; } else { N node = index.getNode(nextPath.getEntry()); children = node.children(nextPath); } if (!enumeration.hasMoreElements()) { queue.remove(); } if (children.hasMoreElements()) { queue.offer(children); } return nextPath; }
@Override @SuppressWarnings({"unchecked"}) public <N extends Number> Expression<N> diff(N n, Expression<? extends N> expression) { if (n == null || expression == null) { throw new IllegalArgumentException("arguments to diff() cannot be null"); } final Class resultType = BinaryArithmeticOperation.determineResultType(n.getClass(), expression.getJavaType()); return new BinaryArithmeticOperation<N>( this, resultType, BinaryArithmeticOperation.Operation.SUBTRACT, n, expression); }