Example usage for java.util LinkedList getFirst

List of usage examples for java.util LinkedList getFirst

Introduction

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

Prototype

public E getFirst() 

Source Link

Document

Returns the first element in this list.

Usage

From source file:com.hs.mail.imap.parser.ParseException.java

public ParseException(LinkedList<Token> tokens, String message, Throwable cause) {
    super(message, cause);
    this.tag = CollectionUtils.isNotEmpty(tokens) ? tokens.getFirst().value : "*";
}

From source file:fitnesse.authentication.PasswordFile.java

private void loadCipher(LinkedList<String> lines) {
    if (lines.size() > 0) {
        String firstLine = lines.getFirst();
        if (firstLine.startsWith("!")) {
            String cipherClassName = firstLine.substring(1);
            instantiateCipher(cipherClassName);
            lines.removeFirst();/*from  w w w  . jav  a  2s.co  m*/
        }
    }
}

From source file:de.science.hack.meshbuilding.AbstractFaceBuilderTask.java

/**
 * creates two triangle based on the two projections
 *
 * @param projections/*from  ww  w .j  a  v a  2  s .  c  o  m*/
 * @return
 */
protected List<Vec3D[]> createTriangles(LinkedList<Line> projections) {
    List<Vec3D[]> triangles = new ArrayList<>(2);
    if (!projections.isEmpty()) {
        Line first = projections.getFirst();
        Line last = projections.getLast();
        triangles.add(createTriangle(first.getPoint1(), first.getPoint2(), last.getPoint1()));
        triangles.add(createTriangle(first.getPoint2(), last.getPoint1(), last.getPoint2()));
    }
    return triangles;
}

From source file:org.piraso.headless.EntryCriteria.java

public Entry firstResult() {
    LinkedList<Entry> items = list();

    if (CollectionUtils.isEmpty(items)) {
        return null;
    }//from  www  .  j  ava2 s  .  c  om

    return items.getFirst();
}

From source file:com.zimbra.cs.imap.ImapMessage.java

static void serializeStructure(PrintStream ps, MimeMessage root, boolean extensions)
        throws IOException, MessagingException {
    LinkedList<LinkedList<MPartInfo>> queue = new LinkedList<LinkedList<MPartInfo>>();
    LinkedList<MPartInfo> level = new LinkedList<MPartInfo>();
    level.add(Mime.getParts(root).get(0));
    queue.add(level);//from  w w w . ja v  a 2 s  . c  om

    boolean pop = false;
    while (!queue.isEmpty()) {
        level = queue.getLast();
        if (level.isEmpty()) {
            queue.removeLast();
            pop = true;
            continue;
        }

        MPartInfo mpi = level.getFirst();
        MimePart mp = mpi.getMimePart();
        boolean hasChildren = mpi.getChildren() != null && !mpi.getChildren().isEmpty();

        // we used to force unset charsets on text/plain parts to US-ASCII, but that always seemed unwise...
        ContentType ctype = new ContentType(mp.getHeader("Content-Type", null))
                .setContentType(mpi.getContentType());
        String primary = nATOM(ctype.getPrimaryType()), subtype = nATOM(ctype.getSubType());

        if (!pop)
            ps.write('(');
        if (primary.equals("\"MULTIPART\"")) {
            if (!pop) {
                // 7.4.2: "Multiple parts are indicated by parenthesis nesting.  Instead of a body type
                //         as the first element of the parenthesized list, there is a sequence of one
                //         or more nested body structures.  The second element of the parenthesized
                //         list is the multipart subtype (mixed, digest, parallel, alternative, etc.)."
                if (!hasChildren) {
                    ps.print("NIL");
                } else {
                    queue.addLast(new LinkedList<MPartInfo>(mpi.getChildren()));
                    continue;
                }
            }
            ps.write(' ');
            ps.print(subtype);
            if (extensions) {
                // 7.4.2: "Extension data follows the multipart subtype.  Extension data is never
                //         returned with the BODY fetch, but can be returned with a BODYSTRUCTURE
                //         fetch.  Extension data, if present, MUST be in the defined order.  The
                //         extension data of a multipart body part are in the following order:
                //         body parameter parenthesized list, body disposition, body language,
                //         body location"
                ps.write(' ');
                nparams(ps, ctype);
                ps.write(' ');
                ndisposition(ps, mp.getHeader("Content-Disposition", null));
                ps.write(' ');
                nlist(ps, mp.getContentLanguage());
                ps.write(' ');
                nstring(ps, mp.getHeader("Content-Location", null));
            }
        } else {
            if (!pop) {
                // 7.4.2: "The basic fields of a non-multipart body part are in the following order:
                //         body type, body subtype, body parameter parenthesized list, body id, body
                //         description, body encoding, body size."
                String cte = mp.getEncoding();
                cte = (cte == null || cte.trim().equals("") ? "7bit" : cte);
                aSTRING(ps, ctype.getPrimaryType());
                ps.write(' ');
                aSTRING(ps, ctype.getSubType());
                ps.write(' ');
                nparams(ps, ctype);
                ps.write(' ');
                nstring(ps, mp.getContentID());
                ps.write(' ');
                nstring2047(ps, mp.getDescription());
                ps.write(' ');
                aSTRING(ps, cte);
                ps.write(' ');
                ps.print(Math.max(mp.getSize(), 0));
            }
            boolean rfc822 = primary.equals("\"MESSAGE\"") && subtype.equals("\"RFC822\"");
            if (rfc822) {
                // 7.4.2: "A body type of type MESSAGE and subtype RFC822 contains, immediately
                //         after the basic fields, the envelope structure, body structure, and
                //         size in text lines of the encapsulated message."
                if (!pop) {
                    if (!hasChildren) {
                        ps.print(" NIL NIL");
                    } else {
                        MimeMessage mm = (MimeMessage) mpi.getChildren().get(0).getMimePart();
                        ps.write(' ');
                        serializeEnvelope(ps, mm);
                        ps.write(' ');
                        queue.addLast(new LinkedList<MPartInfo>(mpi.getChildren()));
                        continue;
                    }
                }
                ps.write(' ');
                ps.print(getLineCount(mp));
            } else if (primary.equals("\"TEXT\"")) {
                // 7.4.2: "A body type of type TEXT contains, immediately after the basic fields, the
                //         size of the body in text lines.  Note that this size is the size in its
                //         content transfer encoding and not the resulting size after any decoding."
                ps.write(' ');
                ps.print(getLineCount(mp));
            }
            if (extensions) {
                // 7.4.2: "Extension data follows the basic fields and the type-specific fields
                //         listed above.  Extension data is never returned with the BODY fetch,
                //         but can be returned with a BODYSTRUCTURE fetch.  Extension data, if
                //         present, MUST be in the defined order.  The extension data of a
                //         non-multipart body part are in the following order: body MD5, body
                //         disposition, body language, body location"
                ps.write(' ');
                nstring(ps, mp.getContentMD5());
                ps.write(' ');
                ndisposition(ps, mp.getHeader("Content-Disposition", null));
                ps.write(' ');
                nlist(ps, mp.getContentLanguage());
                ps.write(' ');
                nstring(ps, mp.getHeader("Content-Location", null));
            }
        }
        ps.write(')');

        level.removeFirst();
        pop = false;
    }
}

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

private static List<Path> consumeStep(LinkedList<Segment> segments) {
    assert segments != null;
    assert segments.isEmpty() == false;
    assert segments.getFirst().isTraverse() == false;
    List<Path> results = new ArrayList<>();

    Segment current = segments.removeFirst();
    for (String segment : resolve(current)) {
        results.add(new Path(segment));
    }/*www .j av  a 2s.  co m*/
    while (isGlobRequired(current) && segments.isEmpty() == false
            && segments.getFirst().isTraverse() == false) {
        current = segments.removeFirst();
        Set<String> suffixCandidates = resolve(current);
        if (suffixCandidates.size() == 1) {
            String suffix = suffixCandidates.iterator().next();
            for (ListIterator<Path> i = results.listIterator(); i.hasNext();) {
                Path parent = i.next();
                i.set(new Path(parent, suffix));
            }
        } else {
            List<Path> nextResults = new ArrayList<>();
            for (Path parent : results) {
                for (String suffix : suffixCandidates) {
                    nextResults.add(new Path(parent, suffix));
                }
            }
            results = nextResults;
        }
    }

    Set<Path> saw = new HashSet<>();
    for (Iterator<Path> iter = results.iterator(); iter.hasNext();) {
        Path path = iter.next();
        if (saw.contains(path)) {
            iter.remove();
        } else {
            saw.add(path);
        }
    }
    return results;
}

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

/**
 * Searches file/directories by pattern.
 * @param fs target file system//from  w w  w  .j  ava2s  .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:se.trillian.goodies.spring.DomainObjectFactoryFactoryBean.java

private static Constructor<?> findMatchingConstructor(Class<?> clazz, Method m) {
    LinkedList<Constructor<?>> constructors = new LinkedList<Constructor<?>>();
    Constructor<?> directMatch = null;
    for (Constructor<?> c : clazz.getDeclaredConstructors()) {
        if (isParameterTypesPrefix(m.getParameterTypes(), c.getParameterTypes())) {
            constructors.add(c);//from www  .ja v a2  s.  co m
            if (directMatch == null && isParameterTypesPrefix(c.getParameterTypes(), m.getParameterTypes())) {
                directMatch = c;
            }
        }
    }
    if (constructors.isEmpty()) {
        throw new IllegalArgumentException("No matching constructor found in " + "implementation class '"
                + clazz + "' for factory method '" + m + "'");
    }
    if (constructors.size() > 1) {
        if (directMatch != null) {
            return directMatch;
        }
        throw new IllegalArgumentException("More than 1 matching constructor "
                + "found in implementation class '" + clazz + "' for factory method '" + m + "'");
    }
    return constructors.getFirst();
}

From source file:io.github.jrobotframework.keyword.csv.criteria.CSVLineCriteria.java

public String[] firstResult() {
    LinkedList<String[]> items = list();

    if (CollectionUtils.isEmpty(items)) {
        throw new IllegalStateException("No items found.");
    }/*from ww  w . java 2 s .com*/

    return items.getFirst();
}

From source file:BasicPriorityLinkedList.java

public Object peekFirst() {
    Object obj = null;//from   w w  w.j av  a 2s.  com

    // 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.getFirst();
        }
        if (obj != null) {
            break;
        }
    }

    return obj;
}