Example usage for java.util LinkedList addFirst

List of usage examples for java.util LinkedList addFirst

Introduction

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

Prototype

public void addFirst(E e) 

Source Link

Document

Inserts the specified element at the beginning of this list.

Usage

From source file:org.batoo.jpa.core.impl.criteria.expression.SizeExpression.java

/**
 * {@inheritDoc}/* w  w w  .  j  a  v  a2  s  . c  om*/
 * 
 */
@Override
public String[] getSqlRestrictionFragments(BaseQueryImpl<?> query) {
    final CriteriaBuilderImpl cb = query.getMetamodel().getEntityManagerFactory().getCriteriaBuilder();
    final Joinable rp = this.collection.getParentPath().getRootPath();

    final LinkedList<AbstractMapping<?, ?, ?>> chain = Lists.newLinkedList();

    AbstractMapping<?, ?, ?> mapping = this.collection.getMapping();
    while (!(mapping instanceof EntityMapping)) {
        chain.addFirst(mapping);

        mapping = mapping.getParent();
    }

    final SubqueryImpl<Long> s = query.subquery(Long.class);
    final RootImpl<?> r = s.from(rp.getEntity());

    AbstractFrom<?, ?> from = r;
    for (final AbstractMapping<?, ?, ?> chainMember : chain) {
        from = from.join(chainMember.getName());
    }

    s.where(cb.equal(r, (AbstractExpression<?>) rp));

    s.select(cb.count(cb.literal(1)));

    return s.getSqlRestrictionFragments(query);
}

From source file:com.moss.simpledeb.core.action.CopyAction.java

@Override
public void run(final DebState state) throws Exception {

    File target = new File(targetDir);
    LinkedList<File> pathsNeeded = new LinkedList<File>();

    File f = target;/*  w w w .j a  v a2 s  . c o m*/
    while (f != null) {
        pathsNeeded.addFirst(f);
        f = f.getParentFile();
    }

    for (int i = 0; i < assumedTargetPathLevel; i++) {
        pathsNeeded.removeFirst();
    }

    for (File e : pathsNeeded) {
        String p = "./" + e.getPath();

        if (!p.endsWith("/")) {
            p = p + "/";
        }

        TarArchiveEntry tarEntry = new TarArchiveEntry(p);
        tarEntry.setGroupId(0);
        tarEntry.setGroupName("root");
        tarEntry.setIds(0, 0);
        tarEntry.setModTime(System.currentTimeMillis());
        tarEntry.setSize(0);
        tarEntry.setUserId(0);
        tarEntry.setUserName("root");
        tarEntry.setMode(Integer.parseInt("755", 8));

        ArchivePath path = new DirArchivePath(tarEntry);
        state.addPath(component, path);
    }

    files.visit(new FileVisitor() {
        public void file(File file) {
            try {
                copyFile(file, state);
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    });
}

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

@Override
public int run(String[] args) throws Exception {
    LinkedList<String> argList = new LinkedList<>();
    Collections.addAll(argList, args);
    while (argList.isEmpty() == false) {
        String arg = argList.removeFirst();
        if (arg.equals("--")) { //$NON-NLS-1$
            break;
        } else {//from   www.  j  a v  a2  s.com
            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> 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) {
        List<ResourceInfo> list = source.list(basePath, pattern, new Counter());
        for (ResourceInfo info : list) {
            System.out.println(info.getPath());
        }
    }
    return 0;
}

From source file:org.lavajug.streamcaster.server.web.controllers.LiveStreamController.java

/**
 *
 *//*from ww w  . ja va  2  s. co  m*/
@GET("/index")
public void index() {

    LinkedList<String> devices = new LinkedList<>();
    Path devicesPath = Paths.get("/dev");

    try {
        for (Path device : Files.newDirectoryStream(devicesPath)) {
            if (device.getFileName().toString().startsWith("video")) {
                devices.addFirst(device.toAbsolutePath().toString());
            }
        }
    } catch (IOException ex) {
    }
    context.addParameter("isWindows", SystemUtils.IS_OS_WINDOWS);
    context.addParameter("devices", devices);
    context.addParameter("section", "LIVE");
    context.addParameter("current", Configuration.getCurrentProfile());
    render();
}

From source file:com.norconex.commons.lang.io.FileUtil.java

/**
 * Returns the specified number of lines starting from the end
 * of a text file.//from  ww  w. j  a v  a2 s.c o  m
 * @param file the file to read lines from
 * @param encoding the file encoding
 * @param numberOfLinesToRead the number of lines to read
 * @param stripBlankLines whether to return blank lines or not
 * @param filter InputStream filter
 * @return array of file lines
 * @throws IOException i/o problem
 */
public static String[] tail(File file, String encoding, final int numberOfLinesToRead, boolean stripBlankLines,
        IInputStreamFilter filter) throws IOException {
    assertFile(file);
    assertNumOfLinesToRead(numberOfLinesToRead);
    LinkedList<String> lines = new LinkedList<String>();
    BufferedReader reader = new BufferedReader(
            new InputStreamReader(new ReverseFileInputStream(file), encoding));
    int remainingLinesToRead = numberOfLinesToRead;
    String line = StringUtils.EMPTY;
    while (line != null && remainingLinesToRead-- > 0) {
        line = StringUtils.defaultString(reader.readLine());
        char[] chars = line.toCharArray();
        for (int j = 0, k = chars.length - 1; j < k; j++, k--) {
            char temp = chars[j];
            chars[j] = chars[k];
            chars[k] = temp;
        }
        String newLine = new String(chars);
        if (!stripBlankLines || StringUtils.isNotBlank(line)) {
            if (filter != null && filter.accept(newLine)) {
                lines.addFirst(newLine);
            } else {
                remainingLinesToRead++;
            }
        } else {
            remainingLinesToRead++;
        }
    }
    reader.close();
    return lines.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
}

From source file:io.github.jeddict.jpa.spec.extend.cache.Cache.java

public void addClass(String _class, LinkedList<String> collection) {
    if (StringUtils.isEmpty(_class)) {
        return;/*w ww .  ja  va2s .c  om*/
    }
    if (collection.contains(_class)) {
        collection.remove(_class);
    }
    while (COLLECTION_SIZE < collection.size()) {
        collection.removeLast();
    }
    collection.addFirst(_class);
}

From source file:com.offbynull.voip.kademlia.model.NodeMostRecentSet.java

public ActivityChangeSet removeMostRecent(int count) {
    LinkedList<Activity> removed = new LinkedList<>();
    for (int i = 0; i < count; i++) {
        Activity e = entries.removeLast();
        if (e == null) {
            break;
        }//w  w  w  .  j a  v  a  2  s .  c o  m
        removed.addFirst(e);
    }
    return ActivityChangeSet.removed(removed);
}

From source file:jp.troter.tags.capture.ContentForTag.java

public void concatToContextValue(String name, LinkedList<String> current) {
    String value = StringUtils.isBlank(this.value) ? this.body : this.value;
    value = CaptureUtil.nullToEmpty(value);
    if (!duplicate && current.contains(value)) {
        return;//w  w  w.  j  a v  a 2s  .co m
    }

    if (addFirst) {
        current.addFirst(value);
    } else {
        current.add(value);
    }

    pageContext.setAttribute(name, current, PageContext.REQUEST_SCOPE);
}

From source file:com.hp.alm.ali.idea.ui.chooser.FilterableTree.java

public void run() {
    final HierarchicalEntityModel model = (HierarchicalEntityModel) getModel();

    synchronized (model) {
        String filter;// w  w w . ja va  2 s  . c  o m
        synchronized (queue) {
            filter = queue.removeFirst();
        }

        final Set<EntityNode> expanded = new HashSet<EntityNode>();
        for (EntityNode node : model.getNodes()) {
            if (isExpanded(new TreePath(node.getPath().toArray()))) {
                expanded.add(node);
            }
        }

        model.setFilter(filter);
        model.clearChildFilteredFlag();

        if (!filter.isEmpty()) {
            model.getStatus().loading();
            try {
                String entityType = model.getEntityType();
                Set<String> processed = new HashSet<String>();
                LinkedList<String> ordered = new LinkedList<String>();
                while (entityType != null && processed.add(entityType)) {
                    ordered.addFirst(entityType); // parent first (may spare us from some missing-parent requests)
                    entityType = Metadata.getParentEntity(entityType);
                }
                for (String entity : ordered) {
                    handle(model, entity, filter);
                }
                model.getStatus().clear();
            } catch (Exception e) {
                model.getStatus().info("Failed to load data", e, null, null);
            }
        }

        UIUtil.invokeAndWaitIfNeeded(new Runnable() {
            public void run() {
                List<EntityNode> toLoad = new LinkedList<EntityNode>();
                for (EntityNode node : model.getNodes()) {
                    node.filterVisible();
                    TreePath path = new TreePath(node.getPath().toArray());
                    if (node.isChildMatching()) {
                        collapsePath(path); // workaround for expand not working sometimes (?!)
                        expandPath(path);
                    } else if (expanded.contains(node)) {
                        expandPath(path);
                    }
                    if (node.isIncomplete() && node.matchesFilter()) {
                        toLoad.add(node);
                    }
                }
                if (!toLoad.isEmpty()) {
                    model.lazyLoadChildren(toLoad, false);
                }
            }
        });
    }
}

From source file:org.dcm4che3.conf.core.misc.DeepEquals.java

/**
 * Deeply compare two Collections that must be same length and in same order.
 * @param col1 First collection of items to compare
 * @param col2 Second collection of items to compare
 * @param stack add items to compare to the Stack (Stack versus recursion)
 * @param visited Set of objects already compared (prevents cycles)
 * value of 'true' indicates that the Collections may be equal, and the sets
 * items will be added to the Stack for further comparison.
 *//*from ww w.  j  a  v a  2  s  .  c om*/
private static boolean compareOrderedCollection(Collection col1, Collection col2, LinkedList stack,
        Set visited) {
    // Same instance check already performed...

    if (col1.size() != col2.size()) {
        return false;
    }

    // try sorting
    if (col1 instanceof List) {

        if (!col1.isEmpty()) {
            Object el = ((List) col1).get(0);

            if (el instanceof Comparable) {

                Collections.sort((List) col1);
                Collections.sort((List) col1);

            }
        }

    }

    Iterator i1 = col1.iterator();
    Iterator i2 = col2.iterator();

    while (i1.hasNext()) {
        DualKey dk = new DualKey(i1.next(), i2.next());
        if (!visited.contains(dk)) { // push contents for further comparison
            stack.addFirst(dk);
        }
    }
    return true;
}