Example usage for java.util Deque add

List of usage examples for java.util Deque add

Introduction

In this page you can find the example usage for java.util Deque add.

Prototype

boolean add(E e);

Source Link

Document

Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

Usage

From source file:co.cask.cdap.gateway.handlers.metrics.MetricsSuiteTestBase.java

public static void stop() {
    collectionService.stopAndWait();/*from   www. jav  a 2  s  .c  o m*/

    Deque<File> files = Lists.newLinkedList();
    files.add(dataDir);

    File file = files.peekLast();
    while (file != null) {
        File[] children = file.listFiles();
        if (children == null || children.length == 0) {
            files.pollLast().delete();
        } else {
            Collections.addAll(files, children);
        }
        file = files.peekLast();
    }
}

From source file:ivorius.ivtoolkit.maze.components.MazeComponentConnector.java

private static <M extends WeightedMazeComponent<C>, C> void addAllExits(
        MazeComponentPlacementStrategy<M, C> placementStrategy,
        Deque<Triple<MazeRoom, MazeRoomConnection, C>> exitStack,
        Set<Map.Entry<MazeRoomConnection, C>> entries) {
    for (Map.Entry<MazeRoomConnection, C> exit : entries) {
        if (placementStrategy.shouldContinue(exit.getKey().getLeft()))
            exitStack.add(Triple.of(exit.getKey().getLeft(), exit.getKey(), exit.getValue()));
        if (placementStrategy.shouldContinue(exit.getKey().getRight()))
            exitStack.add(Triple.of(exit.getKey().getRight(), exit.getKey(), exit.getValue()));
    }//  w  w w  . j av a  2 s .com
}

From source file:com.reprezen.swaggerparser.test.ExamplesTest.java

@Parameters
public static Collection<URL> findExamples() throws IOException {
    Collection<URL> examples = Lists.newArrayList();
    Deque<URL> dirs = Queues.newArrayDeque();
    String auth = System.getenv("GITHUB_AUTH") != null ? System.getenv("GITHUB_AUTH") + "@" : "";
    String request = String.format("https://%sapi.github.com/repos/%s/contents/%s?ref=%s", auth, SPEC_REPO,
            EXAMPLES_ROOT, EXAMPLES_BRANCH);
    dirs.add(new URL(request));
    while (!dirs.isEmpty()) {
        URL url = dirs.remove();//from w w w  . j  a v  a2  s  .  c  om
        String json = IOUtils.toString(url, Charsets.UTF_8);
        JsonNode tree = mapper.readTree(json);
        for (JsonNode result : iterable(tree.elements())) {
            String type = result.get("type").asText();
            String path = result.get("path").asText();
            String resultUrl = result.get("url").asText();
            if (type.equals("dir")) {
                dirs.add(new URL(resultUrl));
            } else if (type.equals("file") && (path.endsWith(".yaml") || path.endsWith(".json"))) {
                String downloadUrl = result.get("download_url").asText();
                examples.add(new URL(downloadUrl));
            }
        }
    }
    return examples;
}

From source file:org.nickelproject.util.testUtil.ClasspathUtil.java

private static Iterable<String> getAllSubClasses(final Class<?>... pTags) {
    final Deque<String> vClassNames = Lists.newLinkedList();
    final Set<String> vResults = Sets.newHashSet();
    for (final Class<?> vClass : pTags) {
        vClassNames.add(vClass.getCanonicalName());
    }/*from w  w  w. j a  v a 2  s.c  o m*/
    while (!vClassNames.isEmpty()) {
        final String vCurrentClass = vClassNames.pollFirst();
        for (final String vChild : kChildren.get(vCurrentClass)) {
            vClassNames.addLast(vChild);
            vResults.add(vChild);
        }
    }
    return vResults;
}

From source file:org.anarres.cpp.Main.java

static List<TokenS> replay(Deque<TokenS> input, List<Action> actions) {
    List<TokenS> result = new ArrayList<TokenS>();
    for (Action action : actions) {
        //            System.out.println("Action:" + action + " rest:" + input);
        if (action instanceof Skip) {
            TokenS actual = ((Skip) action).token;
            TokenS expected = input.removeFirst();
            if (!expected.equals(actual)) {
                throw new RuntimeException("Skipping " + actual + ", found " + expected + " input " + input);
            }/*from w w  w .j a  v  a2 s .  c  o  m*/
            result.add(actual);
        } else {
            Replace replace = (Replace) action;
            for (TokenS actual : replace.original) {
                TokenS expected = input.removeFirst();
                if (!expected.equals(actual)) {
                    System.err.println("At " + expected.token.getFile());
                    throw new RuntimeException(
                            "Expected " + expected + " old " + actual + " instead\n" + replace.toJson());
                }
            }
            List<TokenS> replSeq = new ArrayList<TokenS>();
            for (MapSeg mapSeg : replace.mapping) {
                if (mapSeg instanceof New) {
                    for (Token token : ((New) mapSeg).tokens) {
                        replSeq.add(new TokenS(token, Empty.bag()));
                    }
                } else {
                    Sub sub = (Sub) mapSeg;
                    Deque<TokenS> subInput = new LinkedList<>();
                    for (int i : sub.indicies) {
                        subInput.add(replace.original.get(i));
                    }
                    for (TokenS tokenS : replay(subInput, sub.actions)) {
                        replSeq.add(tokenS);
                    }
                }
            }
            for (int i = replSeq.size() - 1; i >= 0; i--) {
                TokenS tokenS = replSeq.get(i);
                input.addFirst(new TokenS(tokenS.token, tokenS.disables.plusAll(replace.disables)));
            }
        }
    }
    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.  j a  va  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:io.anserini.index.IndexWebCollection.java

static Deque<Path> discoverWarcFiles(Path p, final String suffix) {

    final Deque<Path> stack = new ArrayDeque<>();

    FileVisitor<Path> fv = new SimpleFileVisitor<Path>() {

        @Override//from   w  ww. j  a v a  2s . c o  m
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {

            Path name = file.getFileName();
            if (name != null && name.toString().endsWith(suffix))
                stack.add(file);
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
            if ("OtherData".equals(dir.getFileName().toString())) {
                LOG.info("Skipping: " + dir);
                return FileVisitResult.SKIP_SUBTREE;
            }
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFileFailed(Path file, IOException ioe) {
            LOG.error("Visiting failed for " + file.toString(), ioe);
            return FileVisitResult.SKIP_SUBTREE;
        }
    };

    try {
        Files.walkFileTree(p, fv);
    } catch (IOException e) {
        LOG.error("IOException during file visiting", e);
    }
    return stack;
}

From source file:org.aksw.simba.bengal.triple2nl.converter.DefaultIRIConverter.java

private static String splitCamelCase(String s) {
    StringBuilder sb = new StringBuilder();
    for (String token : s.split(" ")) {
        String[] split = StringUtils.splitByCharacterTypeCamelCase(token);
        Deque<String> list = new ArrayDeque<>();
        for (int i = 0; i < split.length; i++) {
            String s1 = split[i];
            if (i > 0 && s1.length() == 1 && !org.apache.commons.lang3.StringUtils.isNumeric(s1)) { // single
                // character
                // ->
                // append
                // to
                // previous
                // token
                list.add(list.pollLast() + s1);
            } else {
                list.add(s1);//from w w  w .ja v a2 s. co  m
            }
        }
        sb.append(StringUtils.join(list, ' ')).append(" ");
    }
    return sb.toString().trim();
    // return s.replaceAll(
    // String.format("%s|%s|%s",
    // "(?<=[A-Z])(?=[A-Z][a-z])",
    // "(?<=[^A-Z])(?=[A-Z])",
    // "(?<=[A-Za-z])(?=[^A-Za-z])"
    // ),
    // " "
    // );
}

From source file:org.lunarray.model.descriptor.builder.annotation.base.listener.operation.result.SetResultListener.java

/** {@inheritDoc} */
@Override/*from w w  w .ja  v a 2s. c o m*/
public void handleEvent(final UpdatedOperationReferenceEvent<E, B> event) throws EventException {
    SetResultListener.LOGGER.debug("Handling event {}", event);
    Validate.notNull(event, "Event may not be null.");
    final AnnotationOperationDescriptorBuilder<E, B> builder = event.getBuilder();
    final Deque<Member> members = new LinkedList<Member>();
    members.add(builder.getOperation());
    members.addAll(builder.getBuilderContext().getAccessorContext().getDescribedProperties());
    final java.lang.reflect.Type type = GenericsUtil.getRealType(members);
    final AnnotationResultDescriptorBuilder<R, E, B> resultDescriptor = builder.getResultBuilder();
    if (type instanceof Class) {
        resultDescriptor.type((Class<?>) type);
    } else {
        final Class<?> guessedClazz = GenericsUtil.guessClazz(type);
        resultDescriptor.type(guessedClazz);
    }

}

From source file:org.lunarray.model.descriptor.builder.annotation.base.listener.operation.parameter.SetParameterListener.java

/** {@inheritDoc} */
@Override//from w ww .java2 s  .c om
public void handleEvent(final UpdatedParameterEvent<P, B> event) throws EventException {
    SetParameterListener.LOGGER.debug("Handling event {}", event);
    Validate.notNull(event, "Event may not be null.");
    final AnnotationParameterDescriptorBuilder<P, B> builder = event.getBuilder();
    final Deque<DescribedParameter<?>> params = new LinkedList<DescribedParameter<?>>();
    params.add(event.getParameter());
    final java.lang.reflect.Type type = GenericsUtil.getRealType(params);
    if (type instanceof Class) {
        builder.type((Class<?>) type);
    } else {
        builder.type(Object.class);
    }
}