List of usage examples for java.util Deque pop
E pop();
From source file:hudson.plugins.nested_view.NestedView.java
/** * Returns the health of this nested view. * <p/>//from ww w.j av a 2s. c om * <p>Notice that, if a job is contained in several sub-views of the current * view, then it is taken into account only once to get accurate stats.</p> * <p>This algorithm has been derecursified, hence the stack stuff.</p> */ public HealthReportContainer getHealth() { // we use a set to avoid taking into account several times the same job // when computing the health Set<TopLevelItem> items = new LinkedHashSet<TopLevelItem>(100); // retrieve all jobs to analyze (using DFS) Deque<View> viewsStack = new ArrayDeque<View>(20); viewsStack.push(this); do { View currentView = viewsStack.pop(); if (currentView instanceof NestedView) { for (View v : ((NestedView) currentView).views) { viewsStack.push(v); } } else { items.addAll(currentView.getItems()); } } while (!viewsStack.isEmpty()); HealthReportContainer hrc = new HealthReportContainer(); for (TopLevelItem item : items) { if (item instanceof Job) { hrc.sum += ((Job) item).getBuildHealth().getScore(); hrc.count++; } } hrc.report = hrc.count > 0 ? new HealthReport(hrc.sum / hrc.count, Messages._ViewHealth(hrc.count)) : new HealthReport(100, Messages._NoJobs()); return hrc; }
From source file:com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck.java
/** * Checks to see if there are any unclosed tags on the stack. The token * represents a html tag that has been closed and has a corresponding open * tag on the stack. Any tags, except single tags, that were opened * (pushed on the stack) after the token are missing a close. * * @param htmlStack the stack of opened HTML tags. * @param token the current HTML tag name that has been closed. *//*from ww w. j a v a2s . c o m*/ private void checkUnclosedTags(Deque<HtmlTag> htmlStack, String token) { final Deque<HtmlTag> unclosedTags = new ArrayDeque<>(); HtmlTag lastOpenTag = htmlStack.pop(); while (!token.equalsIgnoreCase(lastOpenTag.getId())) { // Find unclosed elements. Put them on a stack so the // output order won't be back-to-front. if (isSingleTag(lastOpenTag)) { lastOpenTag = htmlStack.pop(); } else { unclosedTags.push(lastOpenTag); lastOpenTag = htmlStack.pop(); } } // Output the unterminated tags, if any // Skip multiples, like <b>..<b> String lastFound = ""; for (final HtmlTag htag : unclosedTags) { lastOpenTag = htag; if (lastOpenTag.getId().equals(lastFound)) { continue; } lastFound = lastOpenTag.getId(); log(lastOpenTag.getLineNo(), lastOpenTag.getPosition(), UNCLOSED_HTML, lastOpenTag); } }
From source file:edu.stanford.cfuller.imageanalysistools.filter.VariableSizeMeanFilter.java
@Override public void apply(WritableImage im) { //calculate Laplacian of Image, calculate pseudo-residual (as in Boulanger, 2010) WritableImage residual = ImageFactory.createWritable(im); LaplacianFilterND LF = new LaplacianFilterND(); LF.apply(residual);//from w w w. java 2s . c om //for 3D, residual is Laplacian divided by sqrt(56) float norm = (float) Math.sqrt(56); //for 2D, residual is sqrt(30) //norm = Math.sqrt(30); for (ImageCoordinate ic : residual) { residual.setValue(ic, residual.getValue(ic) / norm); } //perform an octtree segmentation of the Image, using a criterion based on relative variance of image and noise (as in Boulanger, 2010) OcttreeNode root = new OcttreeNode(ImageCoordinate.createCoordXYZCT(0, 0, 0, 0, 0), ImageCoordinate.cloneCoord(im.getDimensionSizes())); if (this.shouldSubDivide(root, im, residual)) { root.subDivide(); } Deque<OcttreeNode> queue = new java.util.ArrayDeque<OcttreeNode>(); queue.addAll(root.getChildren()); List<OcttreeNode> leaves = new java.util.ArrayList<OcttreeNode>(); while (!queue.isEmpty()) { OcttreeNode current = queue.pop(); if (this.shouldSubDivide(current, im, residual) && current.subDivide()) { queue.addAll(current.getChildren()); } else { leaves.add(current); } } for (OcttreeNode node : leaves) { double count = 0; float mean = 0; im.setBoxOfInterest(node.getBoxMin(), node.getBoxMax()); for (ImageCoordinate ic : im) { mean += im.getValue(ic); count++; } mean /= count; for (ImageCoordinate ic : im) { im.setValue(ic, mean); } im.clearBoxOfInterest(); } }
From source file:de.nrw.hbz.regal.sync.ingest.Downloader.java
/** * @param directory// www.jav a 2 s.c o m * the directory will be zipped * @param zipfile * the Outputfile */ @SuppressWarnings("resource") protected void zip(File directory, File zipfile) { try (ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(zipfile))) { URI base = directory.toURI(); Deque<File> queue = new LinkedList<File>(); queue.push(directory); while (!queue.isEmpty()) { directory = queue.pop(); for (File kid : directory.listFiles()) { String name = base.relativize(kid.toURI()).getPath(); if (kid.isDirectory()) { queue.push(kid); name = name.endsWith("/") ? name : name + "/"; zout.putNextEntry(new ZipEntry(name)); } else { zout.putNextEntry(new ZipEntry(name)); copy(kid, zout); zout.closeEntry(); } } } } catch (IOException e) { throw new ZipDownloaderException(e); } }
From source file:edu.byu.nlp.al.EmpiricalAnnotationInstanceManager.java
@VisibleForTesting EmpiricalAnnotationInstanceManager(Iterable<FlatInstance<D, L>> instances, EmpiricalAnnotations<D, L> annotations, AnnotationRecorder<D, L> annotationRecorder, int maxNumAnnotations, int maxNumMeasurements, boolean prioritizeLabelProportions, RandomGenerator rnd) {//w w w. j a va 2 s. com super(annotationRecorder); List<FlatInstance<D, L>> sortedAnnotations = Lists.newArrayList(); for (FlatInstance<D, L> inst : instances) { // add each annotation associated with this item to the queue sortedAnnotations.addAll(annotations.getAnnotationsFor(inst.getSource(), inst.getData()).values()); } // sort the annotation queue based on annotation order Datasets.sortAnnotationsInPlace(sortedAnnotations); // interleave measurements and annotations Deque<FlatInstance<D, L>> measurementDeque = Deques.randomizedDeque(annotations.getMeasurements(), rnd); prioritizeMeasurements(measurementDeque, prioritizeLabelProportions); Deque<FlatInstance<D, L>> annotationDeque = new ArrayDeque<FlatInstance<D, L>>(sortedAnnotations); queue = Lists.newLinkedList(); // better queueing behavior // add measurements int numMeasurements = 0; while (measurementDeque.size() > 0 && numMeasurements < maxNumMeasurements) { numMeasurements += 1; queue.add(measurementDeque.pop()); } // add annotations int numAnnotations = 0; while (annotationDeque.size() > 0 && numAnnotations < maxNumAnnotations) { numAnnotations += 1; queue.add(annotationDeque.pop()); } }
From source file:edu.byu.nlp.al.EmpiricalAnnotationLayersInstanceManager.java
@VisibleForTesting EmpiricalAnnotationLayersInstanceManager(Iterable<FlatInstance<D, L>> instances, EmpiricalAnnotations<D, L> annotations, AnnotationRecorder<D, L> annotationRecorder, int maxNumAnnotations, int maxNumMeasurements, boolean prioritizeLabelProportions, RandomGenerator rnd) {//from w ww.j ava2 s.com super(annotationRecorder); // make a mutable collection of all annotations for each instance List<FlatInstance<D, L>> sortedAnnotations = Lists.newArrayList(); Map<String, Deque<FlatInstance<D, L>>> perInstanceAnnotationLists = Maps.newIdentityHashMap(); for (FlatInstance<D, L> inst : instances) { // find all annotations associated with this item Collection<FlatInstance<D, L>> anns = annotations.getAnnotationsFor(inst.getSource(), inst.getData()) .values(); perInstanceAnnotationLists.put(inst.getSource(), Deques.randomizedDeque(anns, rnd)); } // grab one annotation for each instance until they are gone // (annotate the whole corpus 1-deep before starting on 2-deep, and so on) while (perInstanceAnnotationLists.size() > 0) { Set<String> toRemove = Sets.newHashSet(); for (String src : Iterables2.shuffled(perInstanceAnnotationLists.keySet(), rnd)) { Deque<FlatInstance<D, L>> anns = perInstanceAnnotationLists.get(src); if (anns.size() > 0) { // add 1 to the queue for this instance sortedAnnotations.add(anns.pop()); } if (anns.size() == 0) { toRemove.add(src); } } for (String src : toRemove) { perInstanceAnnotationLists.remove(src); } } // interleave measurements and annotations in the final queue Deque<FlatInstance<D, L>> measurementDeque = Deques.randomizedDeque(annotations.getMeasurements(), rnd); prioritizeMeasurements(measurementDeque, prioritizeLabelProportions); Deque<FlatInstance<D, L>> annotationDeque = new ArrayDeque<FlatInstance<D, L>>(sortedAnnotations); queue = Lists.newLinkedList(); // better queueing behavior // add measurements int numMeasurements = 0; while (measurementDeque.size() > 0 && numMeasurements < maxNumMeasurements) { numMeasurements += 1; queue.add(measurementDeque.pop()); } // add annotations int numAnnotations = 0; while (annotationDeque.size() > 0 && numAnnotations < maxNumAnnotations) { numAnnotations += 1; queue.add(annotationDeque.pop()); } }
From source file:com.grepcurl.random.ObjectGenerator.java
public <T> T generate(Class<T> klass, SetterOverrides setterOverrides, String[] constructorArgTypes, Object... constructorArgs) { Validate.notNull(klass);/*w w w .ja v a 2 s.c o m*/ Validate.notNull(constructorArgs); if (verbose) { log(String.format("generating object of type: %s, with args: %s, of types: %s, with overrides: %s", klass, Arrays.toString(constructorArgs), Arrays.toString(constructorArgTypes), setterOverrides)); } try { Deque<Object> objectStack = new ArrayDeque<>(); Class[] constructorTypes = _toClasses(constructorArgTypes, constructorArgs); T t = klass.getConstructor(constructorTypes).newInstance(constructorArgs); objectStack.push(t); Method[] methods = klass.getMethods(); for (Method method : methods) { _processMethod(method, setterOverrides, t, objectStack); } objectStack.pop(); return t; } catch (Exception e) { throw new FailedRandomObjectGenerationException(e); } }
From source file:io.jmnarloch.spring.cloud.zuul.trie.AbstractTrie.java
protected T remove(N root, String key) { int index = 0; N node = root;// w ww. j a v a2 s .c om N next; final Deque<N> stack = new LinkedList<N>(); while (index < key.length()) { stack.push(node); next = node.getNext(getChar(key, index)); if (next == null) { return null; } node = next; index++; } if (!node.hasValue()) { return null; } final T value = node.getValue(); node.setSize(node.getSize() - 1); node.removeValue(); index = key.length() - 1; while (!stack.isEmpty()) { final char c = getChar(key, index); node = stack.pop(); if (node.getNext(c).isEmpty()) { node.removeNext(c); } node.setSize(node.getSize() - 1); index--; } return value; }
From source file:net.sf.jasperreports.engine.json.expression.member.evaluation.ObjectKeyExpressionEvaluator.java
private List<JRJsonNode> goAnywhereDown(JRJsonNode jrJsonNode) { if (log.isDebugEnabled()) { log.debug("going " + MemberExpression.DIRECTION.ANYWHERE_DOWN + " by " + (expression.isWildcard() ? "wildcard" : "key: [" + expression.getObjectKey() + "]") + " on " + jrJsonNode.getDataNode()); }//from www. j a va 2 s . co m List<JRJsonNode> result = new ArrayList<>(); Deque<JRJsonNode> stack = new ArrayDeque<>(); JsonNode initialDataNode = jrJsonNode.getDataNode(); if (log.isDebugEnabled()) { log.debug("initial stack population with: " + initialDataNode); } // populate the stack initially if (initialDataNode.isArray()) { for (JsonNode deeper : initialDataNode) { stack.addLast(jrJsonNode.createChild(deeper)); } } else { stack.push(jrJsonNode); } while (!stack.isEmpty()) { JRJsonNode stackNode = stack.pop(); JsonNode stackDataNode = stackNode.getDataNode(); addChildrenToStack(stackNode, stack); if (log.isDebugEnabled()) { log.debug("processing stack element: " + stackDataNode); } // process the current stack item if (stackDataNode.isObject()) { if (log.isDebugEnabled()) { log.debug("stack element is object; wildcard: " + expression.isWildcard()); } // if wildcard => only filter the parent; we already added the object keys to the stack if (expression.isWildcard()) { if (applyFilter(stackNode)) { result.add(stackNode); } } // else go down and filter else { JRJsonNode deeperNode = goDeeperIntoObjectNode(stackNode, false); if (deeperNode != null) { result.add(deeperNode); } } } else if (stackDataNode.isValueNode() || stackDataNode.isArray()) { if (log.isDebugEnabled()) { log.debug("stack element is " + (stackDataNode.isValueNode() ? "value node" : "array") + "; wildcard: " + expression.isWildcard()); } if (expression.isWildcard()) { if (applyFilter(stackNode)) { result.add(stackNode); } } } } return result; }
From source file:com.grepcurl.random.ObjectGenerator.java
public <T> T generate(Class<T> klass) { Validate.notNull(klass);/* w w w. j a v a 2 s . co m*/ if (verbose) { log(String.format("generating object of type: %s", klass)); } try { Deque<Object> objectStack = new ArrayDeque<>(); T t; if (klass.isEnum()) { int randomOrdinal = randomInt(0, klass.getEnumConstants().length - 1); t = klass.getEnumConstants()[randomOrdinal]; } else { t = klass.getConstructor().newInstance(); } objectStack.push(t); Method[] methods = klass.getMethods(); for (Method method : methods) { _processMethod(method, null, t, objectStack); } objectStack.pop(); return t; } catch (Exception e) { throw new FailedRandomObjectGenerationException(e); } }