Example usage for java.util LinkedList removeFirst

List of usage examples for java.util LinkedList removeFirst

Introduction

In this page you can find the example usage for java.util LinkedList removeFirst.

Prototype

public E removeFirst() 

Source Link

Document

Removes and returns the first element from this list.

Usage

From source file:com.asakusafw.directio.tools.DirectIoDelete.java

@Override
public int run(String[] args) throws Exception {
    LinkedList<String> argList = new LinkedList<>();
    Collections.addAll(argList, args);
    boolean recursive = false;
    while (argList.isEmpty() == false) {
        String arg = argList.removeFirst();
        if (arg.equals("-r") || arg.equals("-recursive")) { //$NON-NLS-1$ //$NON-NLS-2$
            recursive = true;/*from  w  ww .j  a  v a2 s .  c o  m*/
        } else if (arg.equals("--")) { //$NON-NLS-1$
            break;
        } else {
            argList.addFirst(arg);
            break;
        }
    }
    if (argList.size() < 2) {
        LOG.error(MessageFormat.format("Invalid arguments: {0}", Arrays.toString(args)));
        System.err.println(MessageFormat.format("Usage: hadoop {0} -conf <datasource-conf.xml> [-r] "
                + "base-path resource-pattern [resource-pattern [...]]", getClass().getName()));
        return 1;
    }
    String path = argList.removeFirst();
    List<FilePattern> patterns = new ArrayList<>();
    for (String arg : argList) {
        patterns.add(FilePattern.compile(arg));
    }
    if (repository == null) {
        repository = HadoopDataSourceUtil.loadRepository(getConf());
    }
    String basePath = repository.getComponentPath(path);
    DirectDataSource source = repository.getRelatedDataSource(path);
    for (FilePattern pattern : patterns) {
        source.delete(basePath, pattern, recursive, new Counter());
    }
    return 0;
}

From source file:org.gradle.api.LocationAwareException.java

/**
 * Returns the reportable causes for this failure.
 *
 * @return The causes. Never returns null, returns an empty list if this exception has no reportable causes.
 *//*from ww w .j  av a  2s.co m*/
public List<Throwable> getReportableCauses() {
    List<Throwable> causes = new ArrayList<Throwable>();
    LinkedList<Throwable> queue = new LinkedList<Throwable>();
    addCauses(target, queue);
    while (!queue.isEmpty()) {
        Throwable t = queue.removeFirst();
        causes.add(t);
        addCauses(t, queue);
    }
    return causes;
}

From source file:org.tinygroup.jspengine.runtime.JspFactoryImpl.java

private PageContext internalGetPageContext(Servlet servlet, ServletRequest request, ServletResponse response,
        String errorPageURL, boolean needsSession, int bufferSize, boolean autoflush) {
    try {/*  ww w.  ja v  a2  s .c  o  m*/
        PageContext pc = null;
        if (USE_POOL) {
            LinkedList<PageContext> pcPool = (LinkedList<PageContext>) pool.get();
            if (!pcPool.isEmpty()) {
                pc = pcPool.removeFirst();
            }
            if (pc == null) {
                pc = new PageContextImpl(this);
            }
        } else {
            pc = new PageContextImpl(this);
        }
        pc.initialize(servlet, request, response, errorPageURL, needsSession, bufferSize, autoflush);
        return pc;
    } catch (Throwable ex) {
        /* FIXME: need to do something reasonable here!! */
        log.fatal("Exception initializing page context", ex);
        return null;
    }
}

From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceUtil.java

/**
 * Searches file/directories by pattern.
 * @param fs target file system/* w  w  w.  java 2s.c o m*/
 * @param base base path
 * @param pattern search pattern
 * @return found files, or an empty list if not found
 * @throws IOException if failed to search by I/O error
 * @throws IllegalArgumentException if some parameters were {@code null}
 */
public static List<FileStatus> search(FileSystem fs, Path base, FilePattern pattern) throws IOException {
    if (fs == null) {
        throw new IllegalArgumentException("fs must not be null"); //$NON-NLS-1$
    }
    if (base == null) {
        throw new IllegalArgumentException("base must not be null"); //$NON-NLS-1$
    }
    if (pattern == null) {
        throw new IllegalArgumentException("pattern must not be null"); //$NON-NLS-1$
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(MessageFormat.format("Start searching for files (path={0}, resourcePattern={1})", //$NON-NLS-1$
                base, pattern));
    }
    List<FileStatus> current = new ArrayList<>(1);
    try {
        FileStatus stat = fs.getFileStatus(base);
        current.add(stat);
    } catch (FileNotFoundException e) {
        return Collections.emptyList();
    }
    int steps = 0;
    LinkedList<Segment> segments = new LinkedList<>(pattern.getSegments());
    while (segments.isEmpty() == false) {
        if (segments.getFirst().isTraverse()) {
            segments.removeFirst();
            current = recursiveStep(fs, current);
        } else {
            List<Path> step = consumeStep(segments);
            current = globStep(fs, current, step);
        }
        steps++;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(MessageFormat.format(
                "Finish searching for files (path={0}, resourcePattern={1}, results={2}, steps={3})", //$NON-NLS-1$
                base, pattern, current.size(), steps));
    }
    return current;
}

From source file:org.apache.ddlutils.util.CallbackClosure.java

/**
 * {@inheritDoc}/*from w w w . j a  v a  2s.  c o  m*/
 */
public void execute(Object obj) throws DdlUtilsException {
    LinkedList queue = new LinkedList();

    queue.add(obj.getClass());
    while (!queue.isEmpty()) {
        Class type = (Class) queue.removeFirst();
        Method callback = (Method) _callbacks.get(type);

        if (callback != null) {
            try {
                _parameters[_callbackTypePos] = obj;
                callback.invoke(_callee, _parameters);
                return;
            } catch (InvocationTargetException ex) {
                throw new DdlUtilsException(ex.getTargetException());
            } catch (IllegalAccessException ex) {
                throw new DdlUtilsException(ex);
            }
        }
        if ((type.getSuperclass() != null) && !type.getSuperclass().equals(Object.class)) {
            queue.add(type.getSuperclass());
        }

        Class[] baseInterfaces = type.getInterfaces();

        if (baseInterfaces != null) {
            for (int idx = 0; idx < baseInterfaces.length; idx++) {
                queue.add(baseInterfaces[idx]);
            }
        }
    }
}

From source file:org.jumpmind.db.util.CallbackClosure.java

/**
 * {@inheritDoc}/*from w  w w . ja  v  a2s.co m*/
 */
public void execute(Object obj) throws DdlException {
    LinkedList queue = new LinkedList();

    queue.add(obj.getClass());
    while (!queue.isEmpty()) {
        Class type = (Class) queue.removeFirst();
        Method callback = (Method) _callbacks.get(type);

        if (callback != null) {
            try {
                _parameters[_callbackTypePos] = obj;
                callback.invoke(_callee, _parameters);
                return;
            } catch (InvocationTargetException ex) {
                throw new DdlException(ex.getTargetException());
            } catch (IllegalAccessException ex) {
                throw new DdlException(ex);
            }
        }
        if ((type.getSuperclass() != null) && !type.getSuperclass().equals(Object.class)) {
            queue.add(type.getSuperclass());
        }

        Class[] baseInterfaces = type.getInterfaces();

        if (baseInterfaces != null) {
            for (int idx = 0; idx < baseInterfaces.length; idx++) {
                queue.add(baseInterfaces[idx]);
            }
        }
    }
}

From source file:BasicPriorityLinkedList.java

public Object removeFirst() {
    Object obj = null;/*w  ww  . ja v a 2s  . c o  m*/

    // Initially we are just using a simple prioritization algorithm:
    // Highest priority refs always get returned first.
    // This could cause starvation of lower priority refs.

    // TODO - A better prioritization algorithm

    for (int i = priorities - 1; i >= 0; i--) {
        LinkedList ll = linkedLists[i];

        if (!ll.isEmpty()) {
            obj = ll.removeFirst();
            break;
        }

    }

    if (obj != null) {
        size--;
    }

    return obj;
}

From source file:com.cyclopsgroup.waterview.web.RuntimeTreeNode.java

/**
 * Get node or child node by id//w ww . j a v a2 s  .  c o m
 *
 * @param nodeId Node id
 * @return Node or null if not found
 */
public RuntimeTreeNode getNodeById(String nodeId) {
    LinkedList buffer = new LinkedList();
    buffer.addLast(this);
    while (!buffer.isEmpty()) {
        RuntimeTreeNode node = (RuntimeTreeNode) buffer.removeFirst();
        if (StringUtils.equals(nodeId, node.getNodeId())) {
            return node;
        }
        buffer.addAll(node.children.values());
    }
    return null;
}

From source file:org.fusesource.mop.support.CommandDefinition.java

/**
 * Lets split the argument list into the artifact(s) strings then the remaining arguments
 *///  w  w w  . j  a v  a 2  s  .  c  o  m
protected void splitArgumentList(LinkedList<String> argList, LinkedList<String> artifacts,
        LinkedList<String> remainingArgs) {
    if (argList.isEmpty()) {
        return;
    }
    artifacts.add(argList.removeFirst());
    while (!argList.isEmpty()) {
        String arg = argList.removeFirst();
        if (mop.isAnotherArtifactId(arg)) {
            artifacts.add(arg);
        } else {
            remainingArgs.add(arg);
            remainingArgs.addAll(argList);
            break;
        }
    }

}

From source file:org.commonjava.util.partyline.FileTreeTest.java

private File createStructure(String path, boolean writeTestFile) throws IOException {
    LinkedList<String> parts = new LinkedList<>(Arrays.asList(path.split("/")));
    String fname = parts.removeLast();

    File current = temp.newFolder();
    while (!parts.isEmpty()) {
        current = new File(current, parts.removeFirst());
    }// w  w w.  j a  va  2 s .  co m

    current = new File(current, fname);
    if (writeTestFile) {
        current.getParentFile().mkdirs();
        FileUtils.write(current, "This is a test");
    } else {
        current.mkdirs();
    }

    return current;
}