Example usage for java.util Queue add

List of usage examples for java.util Queue add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Inserts the specified element into this queue 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:org.polymap.rhei.batik.engine.PanelContextInjector.java

@Override
public void run() {
    Queue<Class> types = new ArrayDeque(16);
    types.add(panel.getClass());

    while (!types.isEmpty()) {
        Class type = types.remove();
        if (type.getSuperclass() != null) {
            types.add(type.getSuperclass());
        }/*from   w  w w  .  ja va2s.  c o  m*/

        for (Field f : type.getDeclaredFields()) {
            // ContextProperty
            if (Context.class.isAssignableFrom(f.getType())) {
                f.setAccessible(true);
                Type ftype = f.getGenericType();
                if (ftype instanceof ParameterizedType) {
                    // set
                    try {
                        f.set(panel, new ContextPropertyInstance(f, context));
                        log.debug("injected: " + f.getName() + " (" + panel.getClass().getSimpleName() + ")");
                        continue;
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                } else {
                    throw new IllegalStateException("ContextProperty has no type param: " + f.getName());
                }
            }

            // @Context annotation
            Scope annotation = f.getAnnotation(Scope.class);
            if (annotation != null) {
                f.setAccessible(true);
                throw new UnsupportedOperationException("Injecting context property as direct member.");

                //                    Object value = context.get( f.getType() );
                //
                //                    try {
                //                        f.set( panel, value );
                //                        log.info( "injected: " + f.getName() + " <- " + value );
                //                    }
                //                    catch (Exception e) {
                //                        throw new RuntimeException( e );
                //                    }
            }
        }
    }
}

From source file:io.cloudslang.lang.tools.build.validation.StaticValidatorImpl.java

private void addExceptionIfTrue(boolean expression, String message, Queue<RuntimeException> exceptions) {
    if (!expression) {
        exceptions.add(new RuntimeException(message));
    }//  w  ww  . java  2 s .  com
}

From source file:gobblin.util.HadoopUtils.java

/**
 * This method is an additive implementation of the {@link FileSystem#rename(Path, Path)} method. It moves all the
 * files/directories under 'from' path to the 'to' path without overwriting existing directories in the 'to' path.
 *
 * <p>/*from w w  w  . j a v  a 2  s . c  o m*/
 * The rename operation happens at the first non-existent sub-directory. If a directory at destination path already
 * exists, it recursively tries to move sub-directories. If all the sub-directories also exist at the destination,
 * a file level move is done
 * </p>
 *
 * @param fileSystem on which the data needs to be moved
 * @param from path of the data to be moved
 * @param to path of the data to be moved
 */
public static void renameRecursively(FileSystem fileSystem, Path from, Path to) throws IOException {

    log.info(String.format("Recursively renaming %s in %s to %s.", from, fileSystem.getUri(), to));

    FileSystem throttledFS = getOptionallyThrottledFileSystem(fileSystem, 10000);

    ExecutorService executorService = ScalingThreadPoolExecutor.newScalingThreadPool(1, 100, 100,
            ExecutorsUtils.newThreadFactory(Optional.of(log), Optional.of("rename-thread-%d")));
    Queue<Future<?>> futures = Queues.newConcurrentLinkedQueue();

    try {
        if (!fileSystem.exists(from)) {
            throw new IOException("Trying to rename a path that does not exist! " + from);
        }

        futures.add(executorService.submit(new RenameRecursively(throttledFS, fileSystem.getFileStatus(from),
                to, executorService, futures)));
        int futuresUsed = 0;
        while (!futures.isEmpty()) {
            try {
                futures.poll().get();
                futuresUsed++;
            } catch (ExecutionException | InterruptedException ee) {
                throw new IOException(ee.getCause());
            }
        }

        log.info(String.format("Recursive renaming of %s to %s. (details: used %d futures)", from, to,
                futuresUsed));

    } finally {
        ExecutorsUtils.shutdownExecutorService(executorService, Optional.of(log), 1, TimeUnit.SECONDS);
    }
}

From source file:org.jboss.on.plugins.tomcat.test.TomcatPluginTest.java

private Set<Resource> findResource(Resource parent, String typeName) {
    Set<Resource> foundResources = new HashSet<Resource>();

    Queue<Resource> discoveryQueue = new LinkedList<Resource>();
    discoveryQueue.add(parent);

    while (!discoveryQueue.isEmpty()) {
        Resource currentResource = discoveryQueue.poll();

        log.info("Discovered resource of type: " + currentResource.getResourceType().getName());
        if (currentResource.getResourceType().getName().equals(typeName)) {
            foundResources.add(currentResource);
        }//from   w ww.j  a v a 2  s.c  o  m

        for (Resource child : currentResource.getChildResources()) {
            discoveryQueue.add(child);
        }
    }

    return foundResources;
}

From source file:io.cloudslang.lang.tools.build.validation.StaticValidatorImpl.java

private void addExceptionIfEmptyString(String string, String message, Queue<RuntimeException> exceptions) {
    if (StringUtils.isEmpty(string)) {
        exceptions.add(new RuntimeException(message));
    }//from w  ww . j  ava2  s. c  o  m
}

From source file:de.berlios.jhelpdesk.web.ticket.UploadFileController.java

private synchronized void addPathToSession(HttpSession session, String path) {
    Queue<String> paths = (Queue<String>) session.getAttribute("paths");
    if (!paths.contains(path)) {
        paths.add(path);
    }//from  w ww  .  ja v  a  2s  .c o m
}

From source file:org.wicketopia.mapping.ClassBasedTypeMapping.java

@SuppressWarnings("unchecked")
private Queue<Class<?>> createTypeQueue(final Class<?> originalType) {
    Queue<Class<?>> queue = new LinkedList<Class<?>>();
    Class currentType = originalType;
    do {//from   w  w w .ja  v a2  s  .  co  m
        queue.add(currentType);
        currentType = currentType.getSuperclass();
    } while (currentType != null);
    queue.addAll(ClassUtils.getAllInterfaces(originalType));
    return queue;
}

From source file:org.polymap.rhei.batik.layout.cp.BestFirstOptimizerTest.java

@Test
public void boundSolutionQueue() {
    Queue<TestScoredSolution> queue = SolutionQueueBuilder.create(3);
    queue.add(new TestScoredSolution(PercentScore.NULL));
    queue.add(new TestScoredSolution(new PercentScore(10)));

    assertEquals(2, queue.size());/*  w  w w . j  a  va2  s.c o  m*/
    //        assertEquals( PercentScore.NULL, queue.getFirst().score );
    assertEquals(new PercentScore(10), queue.peek().score);

    queue.add(new TestScoredSolution(new PercentScore(5)));
    assertEquals(3, queue.size());
    assertEquals(new PercentScore(10), queue.peek().score);

    queue.add(new TestScoredSolution(new PercentScore(5)));
    assertEquals(3, queue.size());
    //        assertEquals( new PercentScore( 5 ), queue.getFirst().score );
    assertEquals(new PercentScore(10), queue.peek().score);

    queue.add(new TestScoredSolution(new PercentScore(20)));
    assertEquals(3, queue.size());
    //        assertEquals( new PercentScore( 5 ), queue.getFirst().score );
    assertEquals(new PercentScore(20), queue.peek().score);
}

From source file:org.polymap.rhei.batik.layout.cp.BestFirstOptimizerTest.java

@Test
public void unboundSolutionQueue() {
    Queue<TestScoredSolution> queue = SolutionQueueBuilder.create(-1);
    queue.add(new TestScoredSolution(PercentScore.NULL));
    queue.add(new TestScoredSolution(new PercentScore(10)));

    assertEquals(2, queue.size());//  w ww . j av  a2  s  .c  om
    //        assertEquals( PercentScore.NULL, queue.getFirst().score );
    assertEquals(new PercentScore(10), queue.peek().score);

    queue.add(new TestScoredSolution(new PercentScore(5)));
    assertEquals(3, queue.size());
    assertEquals(new PercentScore(10), queue.peek().score);

    queue.add(new TestScoredSolution(new PercentScore(5)));
    //        assertEquals( 3, queue.size() );
    //        assertEquals( new PercentScore( 5 ), queue.getFirst().score );
    assertEquals(new PercentScore(10), queue.peek().score);

    queue.add(new TestScoredSolution(new PercentScore(20)));
    //        assertEquals( 3, queue.size() );
    //        assertEquals( new PercentScore( 5 ), queue.getFirst().score );
    assertEquals(new PercentScore(20), queue.peek().score);
}

From source file:org.mule.tools.rhinodo.node.fs.Request.java

public Request(Queue<Function> asyncFunctionQueue, ReadStream readStream, WriteStream writeStream) {
    this.readStream = readStream;
    this.writeStream = writeStream;

    asyncFunctionQueue.add(new BaseFunction() {
        @Override/*w  ww  . j  a va2  s .  c  om*/
        public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
            try {
                FileUtils.copyFile(Request.this.readStream.getFile(), Request.this.writeStream.getFile());
                Function close = events.get("close");
                if (close != null) {
                    close.call(cx, scope, thisObj, new Object[] {});
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            return Undefined.instance;
        }
    });

}