List of usage examples for java.util Deque getLast
E getLast();
From source file:Main.java
public static void main(String[] args) { Deque<Integer> deque = new ArrayDeque<Integer>(8); deque.add(25);// w w w. j ava 2s . c o m deque.add(30); deque.add(20); deque.add(18); System.out.println(deque); // getLast() will retrieve element at last position int retval = deque.getLast(); System.out.println("Retrieved Element is = " + retval); }
From source file:org.apache.sling.etcd.testing.tree.Node.java
@Nonnull public static String name(@Nonnull String path) { Deque<String> names = names(path); return names.isEmpty() ? "/" : names.getLast(); }
From source file:com.ebay.pulsar.metric.processor.MetricProcessor.java
private void broadcastEventsByType(String eventType, Deque<DataPoint> dataByType) { List<Queue<JetstreamEvent>> eventsList = new ArrayList<Queue<JetstreamEvent>>(); if (eventType.equalsIgnoreCase("MC_Metric") || eventType.equalsIgnoreCase("TwitterEventCount")) { for (DataPoint dataPoint : dataByType) { eventsList.add(dataPoint.getEvents()); }/*from w w w . ja v a2s .c o m*/ } else { eventsList.add(dataByType.getLast().getEvents()); } if (wsConnectionManager != null) wsConnectionManager.broadcast(eventType, eventsList); }
From source file:org.onehippo.cms7.essentials.dashboard.instruction.FileInstruction.java
private void processDirectories(final Deque<String> directories) throws IOException { if (!directories.isEmpty()) { folderMessage = directories.size() > 1 ? directories.size() - 1 + " directories" : "directory"; createdFolders = directories.getLast().substring(directories.getFirst().length()); createdFoldersTarget = directories.getLast(); Files.createDirectories(new File(directories.getLast()).toPath()); eventBus.post(new InstructionEvent(messageFolderCreate)); }//from w w w . j a v a 2s . c o m }
From source file:com.ebay.pulsar.metric.processor.MetricProcessor.java
@Override public void sendEvent(JetstreamEvent event) throws EventException { incrementEventRecievedCounter();/*from w w w . j a v a 2s . c o m*/ String eventType = event.getEventType(); Deque<DataPoint> dataByType = dataBuffer.get(eventType); if (dataByType == null) { dataByType = new ConcurrentLinkedDeque<DataPoint>(); dataBuffer.put(eventType, dataByType); } Long currentTimestamp = System.currentTimeMillis(); boolean isNewBatchOfEvents = false; if (dataByType.size() > 0 && event.get("context_id") != dataByType.getLast().getEvents().peek().get("context_id")) isNewBatchOfEvents = true; //Flush old batchs if (isNewBatchOfEvents) { broadcastEventsByType(eventType, dataByType); incrementEventSentCounter(); } if (dataByType.size() == 0 || isNewBatchOfEvents) { DataPoint dataPoint = new DataPoint(currentTimestamp); dataByType.add(dataPoint); } dataByType.getLast().addEvent(event); int maxLength = GENERIC_MAX_POINT; if (eventType.equalsIgnoreCase("MC_Metric") || eventType.equalsIgnoreCase("TwitterEventCount")) { maxLength = PAGE_VIEWS_POINT; } if (dataByType.size() > maxLength) { dataByType.removeFirst(); } }
From source file:ocr.sapphire.image.EdgeBasedImagePreprocessor.java
private Point[][] findEdgePoints(int[] edgeData) { List<Deque<Point>> components = new ArrayList<Deque<Point>>(); // find close paths for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (edgeData[x + y * width] == BLACK && isBridge(edgeData, x, y)) { edgeData[x + y * width] = WHITE; Deque<Point> firstPart = null, secondPart = null; for (int k = 0; k < DX.length; k++) { int x2 = x + DX[k]; int y2 = y + DY[k]; if (x2 < 0 || x2 >= width || y2 < 0 || y2 >= height) { continue; }/*w w w .j av a 2 s . c o m*/ if (edgeData[x2 + y2 * width] == BLACK) { Deque<Point> points = findConnectedComponent(edgeData, x2, y2); if (firstPart == null) { firstPart = points; } else { secondPart = points; } } } firstPart.addFirst(new Point(x, y)); if (secondPart != null) { // the path is not closed join(firstPart, true, secondPart, true); } components.add(firstPart); } } } // remove contained components for (int i = 0; i < components.size() - 1; i++) { Rectangle r1 = getBounds(components.get(i)); for (int j = i + 1; j < components.size();) { Rectangle r2 = getBounds(components.get(j)); if (r1.contains(r2)) { components.remove(j); } else if (r2.contains(r1)) { components.set(i, components.get(j)); components.remove(j); } else { j++; } } } // try to connect some paths int connectedCount; do { connectedCount = 0; for (int i = 0; i < components.size() - 1; i++) { for (int j = i + 1; j < components.size(); j++) { Deque<Point> a = components.get(i); Deque<Point> b = components.get(j); double d0 = d(a.getFirst(), a.getLast()) + d(b.getFirst(), b.getLast()); double d1 = d(a.getFirst(), b.getFirst()) + d(a.getLast(), b.getLast()); double d2 = d(a.getFirst(), b.getLast()) + d(a.getLast(), b.getFirst()); double d3 = d(a.getFirst(), b.getFirst()); double d4 = d(a.getFirst(), b.getLast()); double d5 = d(a.getLast(), b.getFirst()); double d6 = d(a.getLast(), b.getLast()); if (d3 <= CLOSE_THRESHOLD && d3 <= d4) { join(a, true, b, true); components.remove(j); connectedCount++; } else if (d4 <= CLOSE_THRESHOLD && d4 <= d3) { join(a, true, b, false); components.remove(j); connectedCount++; } else if (d5 <= CLOSE_THRESHOLD && d5 <= d6) { join(a, false, b, true); components.remove(j); connectedCount++; } else if (d6 <= CLOSE_THRESHOLD && d6 <= d5) { join(a, false, b, false); components.remove(j); connectedCount++; } else if (d1 <= d0 && d1 <= d2) { if (d3 < d6) { join(a, true, b, true); } else { join(a, false, b, false); } components.remove(j); connectedCount++; } else if (d2 <= d0 && d2 <= d1) { if (d4 < d5) { join(a, true, b, false); } else { join(a, false, b, true); } components.remove(j); connectedCount++; } } // end of for j } // end of for i } while (connectedCount > 0); // choose (componentCount) biggest components SortedMap<Integer, Deque<Point>> componentMap = new TreeMap<Integer, Deque<Point>>(); for (Deque<Point> c : components) { componentMap.put(-c.size(), c); } // remove noise boolean firstPoint = true; for (Iterator<Entry<Integer, Deque<Point>>> iterator = componentMap.entrySet().iterator(); iterator .hasNext();) { Entry<Integer, Deque<Point>> entry = iterator.next(); Rectangle r = getBounds(entry.getValue()); if (r.width <= 10 && r.height <= 10) { if (firstPoint) { firstPoint = false; } else { iterator.remove(); } } } // convert components: normalize points, to array int foundComponentCount = Math.min(componentCount, componentMap.size()); componentArr = new Point[foundComponentCount][]; Rectangle r = getBounds(componentMap.get(componentMap.firstKey())); for (int c = 0; c < foundComponentCount; c++) { int key = componentMap.firstKey(); componentArr[c] = new Point[componentMap.get(key).size()]; normalize(componentMap.get(key)).toArray(componentArr[c]); componentMap.remove(key); for (int i = 0; i < componentArr[c].length; i++) { componentArr[c][i].x = (componentArr[c][i].x - r.x) / r.width; componentArr[c][i].y = (componentArr[c][i].y - r.y) / r.height; } } return componentArr; }
From source file:gov.nih.nci.cacis.common.util.ExtractSchematron.java
private void processElement(Deque<XSElementDeclaration> eltStack) { final XSElementDeclaration elementDecl = eltStack.getLast(); if (elementDecl.getTypeDefinition().getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { // not an ISO complex type and no subelements, no further work necessary return;/*from w w w .java 2 s . c o m*/ } final XSComplexTypeDefinition elementType = (XSComplexTypeDefinition) elementDecl.getTypeDefinition(); final QName type = typeQName(elementType); if (this.datatypeUsages.containsKey(type)) { this.datatypeUsages.get(type).contexts.add(toXPath(eltStack)); // we support paths to datatype children of datatype elements, but no further if (isPreviousElementDatatype(eltStack)) { return; } } // If there is recursive nature upto 2 levels // like, Type1/Type2/Type1/Type2 // it is stopped from adding to the stack if (isSameElementDatatypePresentInPreviousLevels(eltStack, 2)) { // LOG.warn("************* " + toXPath(eltStack)+ " *****************"); return; } // recurse into subelements, if any if (elementType.getParticle() == null) { return; } else { processParticle(eltStack, elementType.getParticle()); } }
From source file:uniol.apt.analysis.isomorphism.IsomorphismLogicComplex.java
/** * Isomorphism-check for current state/*ww w . ja v a2s . c om*/ * * @param state current state * @return true if node-pair m, n in state s is isomorphic. */ private boolean doMatch(ExtendedState state) { // Statal-tree, that stores all states Deque<ExtendedState> states = new LinkedList<>(); // Add current state to list of states states.addLast(state); int depth = 0; while (!states.isEmpty()) { ExtendedState s = states.getLast(); depth = s.depth; if (depth > 0) { core1.put(s.n, s.m); core2.put(s.m, s.n); } if (depth == numNodes) { break; } if (!s.active) { computeTerminalSets(depth, s); } Pair<State, State> node = computeP(depth, s); State n, m; //boolean that is true, if (m, n) is an isomorphic pair boolean goodState = false; s.active = true; for (; node != null; node = computeP(depth, s)) { InterrupterRegistry.throwIfInterruptRequestedForCurrentThread(); n = node.getFirst(); m = node.getSecond(); //if (m,n) is an isomorphic pair if (isFeasible(n, m)) { goodState = true; //increment depth because of new isomorphic pair and //set new pair (n,m) as current pair in new state ExtendedState news = new ExtendedState(s, depth + 1, n, m); if (!in1.containsKey(n)) { in1.put(n, depth + 1); news.numin1++; } if (!out1.containsKey(n)) { out1.put(n, depth + 1); news.numout1++; } if (!in2.containsKey(m)) { in2.put(m, depth + 1); news.numin2++; } if (!out2.containsKey(m)) { out2.put(m, depth + 1); news.numout2++; } //Add new state to state-tree states.addLast(news); break; } } //Discard current state if no isomorphic pair has been found if (!goodState) { rollback(depth, s.n, s.m); ExtendedState last = states.removeLast(); assert last == s; } } //Set final state, to get pairs of isomorphic nodes. this.finalState = states; for (ExtendedState ext : states) { if (ext.depth > 0) isomorphism.put(ext.n, ext.m); } return (depth == numNodes); }
From source file:ro.hasna.ts.math.ml.distance.DynamicTimeWarpingDistance.java
/** * <p>//w ww. ja v a 2 s. c om * Reference: * Daniel Lemire (2008) * <i>Faster Sequential Search with a Two-Pass Dynamic-Time-Warping Lower Bound</i> * </p> * * @param v the vector * @param n the length of the vector * @param radius the Sakoe-Chiba band radius * @return time series envelope */ protected Envelope computeLemireEnvelope(double[] v, int n, int radius) { int w = 2 * radius + 1; double[] upper = new double[n]; double[] lower = new double[n]; int i; Deque<Integer> upperList = new LinkedList<>(); Deque<Integer> lowerList = new LinkedList<>(); upperList.addLast(0); lowerList.addLast(0); for (i = 1; i < n; i++) { if (i >= w) { upper[i - w] = v[upperList.getFirst()]; lower[i - w] = v[lowerList.getFirst()]; } if (v[i] > v[i - 1]) { upperList.removeLast(); while (!upperList.isEmpty() && v[i] > v[upperList.getLast()]) { upperList.removeLast(); } } else { lowerList.removeLast(); while (!lowerList.isEmpty() && v[i] < v[lowerList.getLast()]) { lowerList.removeLast(); } } upperList.addLast(i); lowerList.addLast(i); if (i == 2 * w + upperList.getFirst()) { upperList.removeFirst(); } else if (i == 2 * w + lowerList.getFirst()) { lowerList.removeFirst(); } } for (i = n; i < n + w; i++) { upper[i - w] = v[upperList.getFirst()]; lower[i - w] = v[lowerList.getFirst()]; if (i - upperList.getFirst() >= 2 * w) { upperList.removeFirst(); } if (i - lowerList.getFirst() >= 2 * w) { lowerList.removeFirst(); } } return new Envelope(lower, upper); }
From source file:edu.berkeley.compbio.phyloutils.HugenholtzTaxonomyService.java
private synchronized Integer commonAncestor(Set<Deque<Integer>> paths) throws NoSuchNodeException { if (paths.size() == 1) { final Deque<Integer> path = paths.iterator().next(); return path.getLast(); } else {//from w w w . j a va2 s . c o m assert paths.size() > 1; // throw new PhyloUtilsRuntimeException("Taxonomy path not unique : " + DSStringUtils.join(taxa, "; ")); Set<Integer> leafIds = new HashSet<Integer>(); for (Deque<Integer> path : paths) { leafIds.add(path.peekLast()); } BasicRootedPhylogeny<Integer> theIntegerTree = (BasicRootedPhylogeny<Integer>) theIntegerTreeStub.get(); return theIntegerTree.commonAncestor(leafIds, 0.75); } }