Refine search
private boolean inParentResult() { FieldRef thisField = stack.pop(); try { FieldRef parentField = stack.pop(); boolean inResult = parentField.haveSeenSeparate(); // restore stack stack.push(parentField); stack.push(thisField); return inResult; } catch (NoSuchElementException e) { // No parent // restore stack stack.push(thisField); return false; } }
/** Convert an arbitrary-dimensional rectangular double array to flat vector.<br> * Can pass double[], double[][], double[][][], etc. */ public static double[] flattenDoubleArray(Object doubleArray) { if (doubleArray instanceof double[]) return (double[]) doubleArray; LinkedList<Object> stack = new LinkedList<>(); stack.push(doubleArray); int[] shape = arrayShape(doubleArray); int length = ArrayUtil.prod(shape); double[] flat = new double[length]; int count = 0; while (!stack.isEmpty()) { Object current = stack.pop(); if (current instanceof double[]) { double[] arr = (double[]) current; for (int i = 0; i < arr.length; i++) flat[count++] = arr[i]; } else if (current instanceof Object[]) { Object[] o = (Object[]) current; for (int i = o.length - 1; i >= 0; i--) stack.push(o[i]); } else throw new IllegalArgumentException("Base array is not double[]"); } if (count != flat.length) throw new IllegalArgumentException("Fewer elements than expected. Array is ragged?"); return flat; }
/** Convert an arbitrary-dimensional rectangular float array to flat vector.<br> * Can pass float[], float[][], float[][][], etc. */ public static float[] flattenFloatArray(Object floatArray) { if (floatArray instanceof float[]) return (float[]) floatArray; LinkedList<Object> stack = new LinkedList<>(); stack.push(floatArray); int[] shape = arrayShape(floatArray); int length = ArrayUtil.prod(shape); float[] flat = new float[length]; int count = 0; while (!stack.isEmpty()) { Object current = stack.pop(); if (current instanceof float[]) { float[] arr = (float[]) current; for (int i = 0; i < arr.length; i++) flat[count++] = arr[i]; } else if (current instanceof Object[]) { Object[] o = (Object[]) current; for (int i = o.length - 1; i >= 0; i--) stack.push(o[i]); } else throw new IllegalArgumentException("Base array is not float[]"); } if (count != flat.length) throw new IllegalArgumentException("Fewer elements than expected. Array is ragged?"); return flat; }
cuboidSet.add(baseCuboid); LinkedList<Long> cuboidQueue = new LinkedList<Long>(); cuboidQueue.push(baseCuboid); while (!cuboidQueue.isEmpty()) { long cuboid = cuboidQueue.pop(); Collection<Long> spnanningCuboids = scheduler.getSpanningCuboid(cuboid); for (Long sc : spnanningCuboids) { cuboidQueue.push(sc);
private static FieldNode buildTreeByExpr(String expr) { int index = 0; LinkedList<FieldNode> fieldStack = new LinkedList<>(); while (index < expr.length()) { int i = index; if (isSpecialChar(expr.charAt(i))) { if ((expr.charAt(index) == ',') || (expr.charAt(index) == ']')) { FieldNode node = fieldStack.pop(); FieldNode pre = fieldStack.peek(); pre.addFieldNodes(node); } index++; } else { while (i < expr.length() && !isSpecialChar(expr.charAt(i))) { i++; } FieldNode current = new FieldNode(expr.substring(index, i)); fieldStack.push(current); index = i; } } return fieldStack.pop(); } }
@Override public <A, B> Optional<Meta<A, B>> transform(Transform<A, B> transform, A model, TransformFactory factory) { requireNonNulls(transform, model, factory); final RenderTree.Builder parent = renderTreeBuilder.peek(); final RenderTree.Builder branch = RenderTree.builder(); renderTreeBuilder.push(branch); renderStack.push(model); final Optional<Meta<A, B>> meta = transform .transform(this, model) .map(s -> Meta.builder(model, s) .withTransform(transform) .withFactory(factory) .withRenderTree(branch.build()) .withRenderStack(new DefaultRenderStack(renderStack)) .build() ); meta.ifPresent(parent::withBranch); renderStack.pop(); renderTreeBuilder.pop(); return meta; } }