List of usage examples for java.util ArrayDeque ArrayDeque
public ArrayDeque()
From source file:Main.java
public synchronized static void addActivity(Activity a) { if (sStack == null) { sStack = new ArrayDeque<>(); }/*w w w . j a v a 2 s . com*/ sStack.add(a); }
From source file:Main.java
public static <E> ArrayDeque<E> newArrayDeque() { return new ArrayDeque<E>(); }
From source file:org.dataconservancy.packaging.tool.impl.generator.IPMUtil.java
public static String path(Node node, String suffix) { Deque<String> pathStack = new ArrayDeque<>(); pathStack.push(suffix);/*from w w w .j a v a 2 s. c o m*/ pathStack.push(name(node)); while (!node.isRoot()) { node = node.getParent(); if (node.getFileInfo() != null && !node.getFileInfo().isFile()) { pathStack.push("/"); pathStack.push(name(node)); } } StringBuilder builder = new StringBuilder(); pathStack.forEach(builder::append); return builder.toString(); }
From source file:Main.java
/** * Given any of the known collection types, this method will return an instance of the collection. * @param collectionType the type of the collection * @return the collection instance//from w w w . j av a 2s . c om */ public static Collection<?> getCollection(Class<?> collectionType) { if (HashSet.class.equals(collectionType)) { return new HashSet<Object>(); } else if (TreeSet.class.equals(collectionType)) { return new TreeSet<Object>(); } else if (CopyOnWriteArraySet.class.equals(collectionType)) { return new CopyOnWriteArraySet<Object>(); } else if (LinkedHashSet.class.equals(collectionType)) { return new LinkedHashSet<Object>(); } else if (ArrayList.class.equals(collectionType)) { return new ArrayList<Object>(); } else if (LinkedList.class.equals(collectionType)) { return new LinkedList<Object>(); } else if (Vector.class.equals(collectionType)) { return new Vector<Object>(); } else if (Stack.class.equals(collectionType)) { return new Stack<Object>(); } else if (PriorityQueue.class.equals(collectionType)) { return new PriorityQueue<Object>(); } else if (PriorityBlockingQueue.class.equals(collectionType)) { return new PriorityBlockingQueue<Object>(); } else if (ArrayDeque.class.equals(collectionType)) { return new ArrayDeque<Object>(); } else if (ConcurrentLinkedQueue.class.equals(collectionType)) { return new ConcurrentLinkedQueue<Object>(); } else if (LinkedBlockingQueue.class.equals(collectionType)) { return new LinkedBlockingQueue<Object>(); } else if (LinkedBlockingDeque.class.equals(collectionType)) { return new LinkedBlockingDeque<Object>(); } else if (List.class.equals(collectionType)) { return new LinkedList<Object>(); } else if (Set.class.equals(collectionType)) { return new HashSet<Object>(); } else if (Queue.class.equals(collectionType)) { return new PriorityQueue<Object>(); } else if (Deque.class.equals(collectionType)) { return new ArrayDeque<Object>(); } else if (Collection.class.equals(collectionType)) { return new LinkedList<Object>(); } throw new IllegalArgumentException("Unsupported collection type: " + collectionType); }
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 w ww. j a v a 2 s . c om*/ 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:org.roda.core.storage.utils.StorageRecursiveListingUtils.java
private static CloseableIterable<Resource> recursiveListing(final StorageService storage, final CloseableIterable<Resource> iterable) { final Iterator<Resource> directlyUnder = iterable.iterator(); return new CloseableIterable<Resource>() { @Override//from ww w .ja v a2s. c o m public Iterator<Resource> iterator() { return new Iterator<Resource>() { ArrayDeque<CloseableIterable<Resource>> itStack = new ArrayDeque<>(); @Override public boolean hasNext() { boolean hasNext; if (itStack.isEmpty()) { hasNext = directlyUnder.hasNext(); } else { hasNext = false; // find a non-empty iterator or empty stack do { if (!itStack.peek().iterator().hasNext()) { try { itStack.pop().close(); } catch (IOException e) { LOGGER.warn("Error closing file iterable, possible file leak", e); } } else { hasNext = true; } } while (!hasNext && !itStack.isEmpty()); if (itStack.isEmpty()) { hasNext = directlyUnder.hasNext(); } } return hasNext; } @Override public Resource next() { Resource resource; if (itStack.isEmpty()) { resource = directlyUnder.next(); } else { resource = itStack.peek().iterator().next(); } try { if (resource != null && resource.isDirectory()) { CloseableIterable<Resource> subIterable = storage .listResourcesUnderDirectory(resource.getStoragePath(), false); itStack.push(subIterable); } } catch (RequestNotValidException | GenericException | NotFoundException | AuthorizationDeniedException e) { LOGGER.warn("Error while listing all files", e); } return resource; } }; } @Override public void close() throws IOException { iterable.close(); } }; }
From source file:cz.cuni.mff.ksi.jinfer.autoeditor.automatonvisualizer.layouts.graphviz.AutomatonToDot.java
public static <T> String convertToDot(final Automaton<T> automaton, final Transformer<Step<T>, String> edgeLabelTransformer) { final StringBuilder sb = new StringBuilder(); sb.append("digraph finite_state_machine {\n"); sb.append("\trankdir=LR;\n"); sb.append("\tnodesep=\"50\";"); sb.append("\tsplines=\"line\";"); sb.append("\tranksep=\"100\";"); sb.append("\tedge [label = \"\", dir = none, arrowhead=none, arrowtail=none];"); sb.append("\tnode [shape = none, label = \"\", width = 0, height = 0];\n"); final Deque<State<T>> queue = new ArrayDeque<State<T>>(); queue.addAll(automaton.getDelta().keySet()); while (!queue.isEmpty()) { final State<T> actual = queue.removeFirst(); sb.append(actual.getName());/* w w w . j a va 2 s . co m*/ sb.append(";\n"); for (Step<T> step : automaton.getDelta().get(actual)) { sb.append("\t"); sb.append(step.getSource().getName()); sb.append(" -> "); sb.append(step.getDestination().getName()); sb.append("];\n"); } } sb.append("\n}"); return sb.toString(); }
From source file:ca.fastenalcompany.order.OrderManager.java
public OrderManager() { orderQueue = new ArrayDeque<>(); orderList = new ArrayList<>(); }
From source file:io.cloudslang.lang.runtime.env.ExecutionPath.java
public ExecutionPath() { parentPositions = new ArrayDeque<>(); }
From source file:com.tussle.script.StackedBindings.java
public StackedBindings() { bindingStack = new ArrayDeque<>(); bindingStack.push(new SimpleBindings()); bindingMap = new HashMap<>(); }