List of usage examples for java.util Deque size
int size();
From source file:Main.java
public static void main(String[] args) { Deque<Integer> deque = new ArrayDeque<Integer>(8); deque.add(15);/*www . ja v a 2 s. c o m*/ deque.add(20); deque.add(25); deque.add(22); System.out.println(deque); // this will print the size of this deque int retval = deque.size(); System.out.println("Size of deque = " + retval); }
From source file:com.twosigma.beaker.core.rest.RecentMenuRest.java
private static List<String> reverseView(Deque<String> input) { List<String> ret = new ArrayList<>(input.size()); Iterator<String> it = input.descendingIterator(); while (it.hasNext()) { ret.add(it.next());//w w w. j a v a 2 s . co m } return ret; }
From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.AbstractOAuth2Base.java
protected static void createOrDescend(JsonObject root, Deque<String> keyPath, String value) { // If there are still key-path elements remaining to traverse. if (keyPath.size() > 1) { // If there's no object already at this key-path create a new JsonObject. if (root.getJsonObject(keyPath.peek()) == null) { JsonObject newJson = new JsonObject(); String val = keyPath.pop(); root.put(val, newJson); createOrDescend(newJson, keyPath, value); } else { // If there's already an existing object on key-path, grab it and traverse. createOrDescend(root.getJsonObject(keyPath.pop()), keyPath, value); }/*from w w w. j ava 2 s. co m*/ } else { // Set the value. Boolean boolObj = BooleanUtils.toBooleanObject(value); if (boolObj != null) { root.put(keyPath.pop(), boolObj); } else if (StringUtils.isNumeric(value)) { root.put(keyPath.pop(), Long.parseLong(value)); } else { root.put(keyPath.pop(), value); } } }
From source file:PathUtils.java
/** * Calculates the relative path between a specified root directory and a target path. * * @param root The absolute path of the root directory. * @param target The path to the target file or directory. * @return The relative path between the specified root directory and the target path. * @throws IllegalArgumentException <ul><li>The root file cannot be null.</li><li>The target cannot be * null.</li><li>The root file must be a directory.</li><li>The root file must be * absolute.</li></ul> *///w w w .jav a 2s . c o m public static String relativize(final File root, final File target) throws IllegalArgumentException { if (root == null) throw new IllegalArgumentException("The root file cannot be null."); if (target == null) throw new IllegalArgumentException("The target cannot be null."); if (!root.isDirectory()) throw new IllegalArgumentException("The root file must be a directory."); if (!root.isAbsolute()) throw new IllegalArgumentException("The root file must be absolute."); if (!target.isAbsolute()) return target.toString(); if (root.equals(target)) return "."; // Deconstruct hierarchies final Deque<File> rootHierarchy = new ArrayDeque<File>(); for (File f = root; f != null; f = f.getParentFile()) rootHierarchy.push(f); final Deque<File> targetHierarchy = new ArrayDeque<File>(); for (File f = target; f != null; f = f.getParentFile()) targetHierarchy.push(f); // Trace common root while (rootHierarchy.size() > 0 && targetHierarchy.size() > 0 && rootHierarchy.peek().equals(targetHierarchy.peek())) { rootHierarchy.pop(); targetHierarchy.pop(); } // Create relative path final StringBuilder sb = new StringBuilder(rootHierarchy.size() * 3 + targetHierarchy.size() * 32); while (rootHierarchy.size() > 0) { sb.append(".."); rootHierarchy.pop(); if (rootHierarchy.size() > 0 || targetHierarchy.size() > 0) sb.append(File.separator); } while (targetHierarchy.size() > 0) { sb.append(targetHierarchy.pop().getName()); if (targetHierarchy.size() > 0) sb.append(File.separator); } return sb.toString(); }
From source file:com.willwinder.universalgcodesender.utils.Settings.java
private static void updateRecent(Deque<String> stack, int maxSize, String element) { stack.remove(element);/*from w w w . j a v a2 s .c om*/ stack.push(element); while (stack.size() > maxSize) stack.removeLast(); }
From source file:ivorius.ivtoolkit.maze.components.MazeComponentConnector.java
public static <M extends WeightedMazeComponent<C>, C> List<ShiftedMazeComponent<M, C>> randomlyConnect( MorphingMazeComponent<C> morphingComponent, List<M> components, ConnectionStrategy<C> connectionStrategy, final MazeComponentPlacementStrategy<M, C> placementStrategy, Random random) {/*from ww w . ja v a2 s .co m*/ List<ShiftedMazeComponent<M, C>> result = new ArrayList<>(); Deque<Triple<MazeRoom, MazeRoomConnection, C>> exitStack = new ArrayDeque<>(); Predicate<ShiftedMazeComponent<M, C>> componentPredicate = Predicates.and( MazeComponents.<M, C>compatibilityPredicate(morphingComponent, connectionStrategy), MazeComponentPlacementStrategies.placeable(placementStrategy)); WeightedSelector.WeightFunction<ShiftedMazeComponent<M, C>> weightFunction = getWeightFunction(); addAllExits(placementStrategy, exitStack, morphingComponent.exits().entrySet()); while (exitStack.size() > 0) { Triple<MazeRoom, MazeRoomConnection, C> triple = exitStack.removeLast(); MazeRoom room = triple.getLeft(); if (morphingComponent.rooms().contains(room)) continue; // Has been filled while queued MazeRoomConnection exit = triple.getMiddle(); C connection = triple.getRight(); List<ShiftedMazeComponent<M, C>> placeable = FluentIterable.from(components) .transformAndConcat(MazeComponents.<M, C>shiftAllFunction(exit, connection, connectionStrategy)) .filter(componentPredicate).toList(); if (placeable.size() == 0) { IvToolkitCoreContainer.logger.warn("Did not find fitting component for maze!"); IvToolkitCoreContainer.logger.warn("Suggested: X with exits " + FluentIterable.from(morphingComponent.exits().entrySet()).filter(entryConnectsTo(room))); continue; } ShiftedMazeComponent<M, C> selected = WeightedSelector.canSelect(placeable, weightFunction) ? WeightedSelector.select(random, placeable, weightFunction) : placeable.get(random.nextInt(placeable.size())); // All weight 0 = select at random addAllExits(placementStrategy, exitStack, selected.exits().entrySet()); morphingComponent.add(selected); result.add(selected); } return result; }
From source file:io.hawt.osgi.jmx.RBACDecorator.java
/** * Checks if two {@link ObjectName}s may share RBAC info - if the same configadmin PIDs are examined by Karaf * @param realJmxAclPids//from w w w .jav a 2 s . co m * @param o1 * @param o2 * @return */ public static boolean mayShareRBACInfo(List<String> realJmxAclPids, ObjectName o1, ObjectName o2) { if (o1 == null || o2 == null) { return false; } Deque<String> pids1 = new LinkedList<>(); List<String> pidCandidates1 = iterateDownPids(nameSegments(o1)); List<String> pidCandidates2 = iterateDownPids(nameSegments(o2)); for (String pidCandidate1 : pidCandidates1) { pids1.add(getGeneralPid(realJmxAclPids, pidCandidate1)); } for (String pidCandidate2 : pidCandidates2) { if (pids1.peek() == null || !pids1.pop().equals(getGeneralPid(realJmxAclPids, pidCandidate2))) { return false; } } return pids1.size() == 0; }
From source file:com.fizzed.blaze.system.TailTest.java
@Test public void works() throws Exception { Tail tail = new Tail(null); String s = "a\nb\nc\n"; StringReader sr = new StringReader(s); tail.pipeInput(new ReaderInputStream(sr)); Deque<String> output = tail.run(); assertThat(output.size(), is(3)); assertThat(output.remove(), is("a")); assertThat(output.remove(), is("b")); assertThat(output.remove(), is("c")); }
From source file:eu.openanalytics.rsb.rservi.CircularRServiUriSelector.java
private URI getCircular(final Deque<URI> applicationRserviPoolUris) { if (applicationRserviPoolUris.size() == 1) { return applicationRserviPoolUris.peek(); }/*from w w w. j a v a 2 s . c o m*/ synchronized (applicationRserviPoolUris) { final URI uri = applicationRserviPoolUris.poll(); applicationRserviPoolUris.add(uri); return uri; } }
From source file:bb.mcmc.analysis.ESSConvergeStat.java
@Override protected double calculateEachProgress(Double stat, Deque<Double> record) { if (!Double.isNaN(stat)) { if (record.size() > 0) { record.pop();//w w w.j ava 2s.c om } record.add(stat); } stat = record.peekFirst(); double progress = stat / essThreshold; return progress; }