Example usage for java.util LinkedList isEmpty

List of usage examples for java.util LinkedList isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:de.vanita5.twittnuker.util.net.ssl.AbstractCheckSignatureVerifier.java

public static String[] getCNs(final X509Certificate cert) {
    final LinkedList<String> cnList = new LinkedList<String>();
    /*/* w w  w . j a  v a  2  s . co  m*/
     * Sebastian Hauer's original StrictSSLProtocolSocketFactory used
     * getName() and had the following comment:
     *
     * Parses a X.500 distinguished name for the value of the "Common Name"
     * field. This is done a bit sloppy right now and should probably be
     * done a bit more according to <code>RFC 2253</code>.
     *
     * I've noticed that toString() seems to do a better job than getName()
     * on these X500Principal objects, so I'm hoping that addresses
     * Sebastian's concern.
     *
     * For example, getName() gives me this:
     * 1.2.840.113549.1.9.1=#16166a756c6975736461766965734063756362632e636f6d
     *
     * whereas toString() gives me this: EMAILADDRESS=juliusdavies@cucbc.com
     *
     * Looks like toString() even works with non-ascii domain names! I
     * tested it with "&#x82b1;&#x5b50;.co.jp" and it worked fine.
     */

    final String subjectPrincipal = cert.getSubjectX500Principal().toString();
    final StringTokenizer st = new StringTokenizer(subjectPrincipal, ",+");
    while (st.hasMoreTokens()) {
        final String tok = st.nextToken().trim();
        if (tok.length() > 3) {
            if (tok.substring(0, 3).equalsIgnoreCase("CN=")) {
                cnList.add(tok.substring(3));
            }
        }
    }
    if (!cnList.isEmpty()) {
        final String[] cns = new String[cnList.size()];
        cnList.toArray(cns);
        return cns;
    } else
        return null;
}

From source file:org.unitime.timetable.onlinesectioning.server.AbstractServer.java

protected OnlineSectioningHelper getCurrentHelper() {
    LinkedList<OnlineSectioningHelper> h = sHelper.get();
    if (h == null || h.isEmpty())
        return new OnlineSectioningHelper(null);
    return h.peek();
}

From source file:org.kitodo.production.forms.dataeditor.StructurePanel.java

private void checkPhysicalDragDrop(MediaUnit dragUnit, MediaUnit dropUnit) {
    StructuralElementViewInterface divisionView = dataEditor.getRuleset().getStructuralElementView(
            dropUnit.getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());

    LinkedList<MediaUnit> dragParents;
    if (divisionView.getAllowedSubstructuralElements().containsKey(dragUnit.getType())) {
        dragParents = MetadataEditor.getAncestorsOfMediaUnit(dragUnit,
                dataEditor.getWorkpiece().getMediaUnit());
        if (dragParents.isEmpty()) {
            Helper.setErrorMessage("No parents of media unit " + dragUnit.getType() + " found!");
        } else {//from w ww  .  j  a v a  2  s.  c  o m
            MediaUnit parentUnit = dragParents.get(dragParents.size() - 1);
            if (parentUnit.getChildren().contains(dragUnit)) {
                preservePhysical();
                return;
            } else {
                Helper.setErrorMessage(
                        "Parents of media unit " + dragUnit.getType() + " do not contain media " + "unit!");
            }
        }
    } else {
        Helper.setErrorMessage("Media unit of type '" + dragUnit.getType()
                + "' NOT allowed as child of media unit of type '" + dropUnit.getType() + "!");
    }
    show();
}

From source file:org.unitime.timetable.onlinesectioning.server.AbstractServer.java

protected void releaseCurrentHelper() {
    LinkedList<OnlineSectioningHelper> h = sHelper.get();
    h.poll();//from  w  w w. j a  va2  s.  c o  m
    if (h.isEmpty())
        sHelper.remove();
}

From source file:org.xchain.namespaces.jsl.AbstractTemplateCommand.java

private final void popElementOutputState() {
    // get the stack for the current thread.
    LinkedList<ElementOutputState[]> stack = elementOutputStateStackTL.get();

    // if there was not a stack, then we are in an illegal state.
    if (stack == null) {
        throw new IllegalStateException("popElementOutputState() called when there was not a current stack.");
    }/*from  ww w  .j  a  v a2 s.  c o m*/

    // remove the state array from the stack.
    stack.removeFirst();

    // if the stack is now empty, clean the thread local up.
    if (stack.isEmpty()) {
        elementOutputStateStackTL.remove();
    }

}

From source file:org.gcaldaemon.core.FeedUtilities.java

private static final byte[] removeDuplicatedEntries(SyndFeed feed, HashMap feedCache, double duplicationRatio)
        throws Exception {

    // Remove duplicated feed entries
    if (feedCache.isEmpty()) {
        return null;
    }/*from w w  w .ja  v a2s. c  om*/
    SyndEntry[] entries = getFeedEntries(feed);
    LinkedList duplicatedEntries = new LinkedList();
    HashMap syndEntryCache = new HashMap();
    SyndEntry entry;
    boolean found;
    for (int i = 0; i < entries.length; i++) {
        entry = entries[i];
        found = false;

        // Find entry
        Iterator urls = feedCache.keySet().iterator();
        while (urls.hasNext()) {
            String url = (String) urls.next();
            if (url.endsWith(".ics")) {
                continue;
            }
            SyndEntry[] otherEntries = (SyndEntry[]) syndEntryCache.get(url);
            if (otherEntries == null) {
                CachedCalendar container = (CachedCalendar) feedCache.get(url);
                SyndFeed otherFeed = parseFeed(container.previousBody);
                otherEntries = getFeedEntries(otherFeed);
                syndEntryCache.put(url, otherEntries);
            }
            found = foundDuplicatedEntry(entry, otherEntries, duplicationRatio);
            if (found) {
                break;
            }
        }

        // Store duplicated entry
        if (found) {
            duplicatedEntries.addLast(entry);
            log.debug("Duplicated feed entry: " + entry.getTitle().trim());
        }
    }

    // Convert to byte array
    if (!duplicatedEntries.isEmpty()) {
        List list = feed.getEntries();
        list.removeAll(duplicatedEntries);
        WireFeed wire = feed.createWireFeed();
        WireFeedOutput out = new WireFeedOutput();
        StringWriter writer = new StringWriter();
        out.output(wire, writer);
        byte[] bytes = StringUtils.encodeString(writer.toString(), StringUtils.UTF_8);
        return bytes;
    }
    return null;
}

From source file:org.apache.hadoop.mapred.util.ProcfsBasedProcessTree.java

/**
 * Get the process-tree with latest state. If the root-process is not alive,
 * an empty tree will be returned.//from www  .ja  v  a 2  s .  c o  m
 * 
 * @return the process-tree with latest state.
 */
public ProcfsBasedProcessTree getProcessTree() {
    if (pid != -1) {
        // Get the list of processes
        List<Integer> processList = getProcessList();

        Map<Integer, ProcessInfo> allProcessInfo = new HashMap<Integer, ProcessInfo>();

        // cache the processTree to get the age for processes
        Map<Integer, ProcessInfo> oldProcs = new HashMap<Integer, ProcessInfo>(processTree);
        processTree.clear();

        ProcessInfo me = null;
        for (Integer proc : processList) {
            // Get information for each process
            ProcessInfo pInfo = new ProcessInfo(proc);
            if (constructProcessInfo(pInfo, procfsDir) != null) {
                allProcessInfo.put(proc, pInfo);
                if (proc.equals(this.pid)) {
                    me = pInfo; // cache 'me'
                    processTree.put(proc, pInfo);
                }
            }
        }

        if (me == null) {
            return this;
        }

        // Add each process to its parent.
        for (Map.Entry<Integer, ProcessInfo> entry : allProcessInfo.entrySet()) {
            Integer pID = entry.getKey();
            if (pID != 1) {
                ProcessInfo pInfo = entry.getValue();
                ProcessInfo parentPInfo = allProcessInfo.get(pInfo.getPpid());
                if (parentPInfo != null) {
                    parentPInfo.addChild(pInfo);
                }
            }
        }

        // now start constructing the process-tree
        LinkedList<ProcessInfo> pInfoQueue = new LinkedList<ProcessInfo>();
        pInfoQueue.addAll(me.getChildren());
        while (!pInfoQueue.isEmpty()) {
            ProcessInfo pInfo = pInfoQueue.remove();
            if (!processTree.containsKey(pInfo.getPid())) {
                processTree.put(pInfo.getPid(), pInfo);
            }
            pInfoQueue.addAll(pInfo.getChildren());
        }

        // update age values and compute the number of jiffies since last update
        for (Map.Entry<Integer, ProcessInfo> procs : processTree.entrySet()) {
            ProcessInfo oldInfo = oldProcs.get(procs.getKey());
            if (procs.getValue() != null) {
                procs.getValue().updateJiffy(oldInfo);
                if (oldInfo != null) {
                    procs.getValue().updateAge(oldInfo);
                }
            }
        }

        if (LOG.isDebugEnabled()) {
            // Log.debug the ProcfsBasedProcessTree
            LOG.debug(this.toString());
        }
    }
    return this;
}

From source file:org.cloudata.core.tabletserver.RecordSearcher.java

private boolean fetchFromWinner(LinkedList<ColumnValueEntry> workPlace, Searchable[] searchers, int winnerIndex)
        throws IOException {
    ColumnValue columnValue = null;//from w  ww.  j av  a 2  s .  c om
    if (searchers[winnerIndex] != null) {
        columnValue = searchers[winnerIndex].next();
    }

    if (columnValue != null) {
        workPlace.add(new ColumnValueEntry(columnValue, winnerIndex));
        return true;
    } else {
        if (searchers[winnerIndex] != null) {
            searchers[winnerIndex].close();
        }
        searchers[winnerIndex] = null;

        boolean end = workPlace.isEmpty();
        for (int i = 0; i < searchers.length; i++) {
            if (searchers[i] != null) {
                columnValue = searchers[i].next();
                if (columnValue != null) {
                    workPlace.add(new ColumnValueEntry(columnValue, i));
                    end = false;
                    break;
                } else {
                    searchers[i].close();
                    searchers[i] = null;
                }
            }
        }
        return !end;
    }
}

From source file:org.cloudata.core.common.ipc.CClient.java

/**
 * Makes a set of calls in parallel. Each parameter is sent to the
 * corresponding address. When all values are available, or have timed out or
 * errored, the collected results are returned in an array. The array contains
 * nulls for calls that timed out or errored.
 *//*from   www  . ja v  a2 s.c  o m*/
//  public NWritable[] call(NWritable[] params, InetSocketAddress[] addresses)
//      throws IOException {
//    if (addresses.length == 0)
//      return new NWritable[0];
//
//    ParallelResults results = new ParallelResults(params.length);
//    synchronized (results) {
//      byte[] data = null;
//      int dataLength = 0;
//
//      // long time1 = System.nanoTime();
//      for (int i = 0; i < params.length; i++) {
//        final ParallelCall call = new ParallelCall(params[i], results, i);
//        try {
//          if (data == null) {
//            NDataOutputBuffer d = new NDataOutputBuffer(); // for serializing
//                                                           // the
//            call.param.write(d);
//            data = d.getData();
//            dataLength = d.getLength();
//          }
//          parallelCallExecutor.execute(new SendTask(call, addresses[i], data,
//              dataLength, results));
//        } catch (IOException e) {
//          results.size--; // wait for one fewer result
//        }
//      }
//      // long time2 = System.nanoTime();
//      // System.out.println(">>>>>" + (time2 - time1));
//
//      try {
//        results.wait(timeout); // wait for all results
//      } catch (InterruptedException e) {
//      }
//
//      if (results.count == 0) {
//        throw new SocketTimeoutException("no responses");
//      } else {
//        return results.values;
//      }
//    }
//  }

//  class SendTask implements Runnable {
//    ParallelCall call;
//
//    InetSocketAddress address;
//
//    byte[] data;
//
//    int dataLength;
//
//    ParallelResults results;
//
//    public SendTask(ParallelCall call, InetSocketAddress address, byte[] data,
//        int dataLength, ParallelResults results) {
//      this.call = call;
//      this.address = address;
//      this.data = data;
//      this.dataLength = dataLength;
//      this.results = results;
//    }
//
//    public void run() {
//      try {
//        Connection connection = getConnection(address);
//        connection.sendParam(call, data, dataLength);
//      } catch (IOException e) {
//        synchronized (results) {
//          results.size--;
//        }
//      }
//    }
//  }

public void closeThisConnection(InetSocketAddress address, Connection conn) {
    //LOG.warn("closeThisConnection:" + address + "," + this);
    synchronized (connections) {
        LinkedList<Connection> hostConnections = connections.get(address);
        if (hostConnections != null) {
            hostConnections.remove(conn);
            if (hostConnections.isEmpty()) {
                connections.remove(address);
            }
        }
    }
    conn.close();
}

From source file:com.redhat.rcm.version.mgr.VersionManager.java

protected List<PomPeek> peekAtPomHierarchy(final File topPom, final VersionManagerSession session)
        throws IOException {
    final LinkedList<File> pendingPoms = new LinkedList<File>();
    pendingPoms.add(topPom.getCanonicalFile());

    final String topDir = topPom.getParentFile().getCanonicalPath();

    final Set<File> seen = new HashSet<File>();
    final List<PomPeek> peeked = new ArrayList<PomPeek>();

    while (!pendingPoms.isEmpty()) {
        final File pom = pendingPoms.removeFirst();
        seen.add(pom);/*from  w  w  w. j a  va  2s .co m*/

        logger.info("PEEK: " + pom);

        final PomPeek peek = new PomPeek(pom);
        final FullProjectKey key = peek.getKey();
        if (key != null) {
            session.addPeekPom(key, pom);
            peeked.add(peek);

            final File dir = pom.getParentFile();

            final String relPath = peek.getParentRelativePath();
            if (relPath != null) {
                logger.info("Found parent relativePath: " + relPath + " in pom: " + pom);
                File parent = new File(dir, relPath);
                if (parent.isDirectory()) {
                    parent = new File(parent, "pom.xml");
                }

                logger.info("Looking for parent POM: " + parent);

                parent = parent.getCanonicalFile();
                if (parent.getParentFile().getCanonicalPath().startsWith(topDir) && parent.exists()
                        && !seen.contains(parent) && !pendingPoms.contains(parent)) {
                    pendingPoms.add(parent);
                } else {
                    logger.info("Skipping reference to non-existent parent relativePath: '" + relPath + "' in: "
                            + pom);
                }
            }

            final Set<String> modules = peek.getModules();
            if (modules != null && !modules.isEmpty()) {
                for (final String module : modules) {
                    logger.info("Found module: " + module + " in pom: " + pom);
                    File modPom = new File(dir, module);
                    if (modPom.isDirectory()) {
                        modPom = new File(modPom, "pom.xml");
                    }

                    logger.info("Looking for module POM: " + modPom);

                    if (modPom.getParentFile().getCanonicalPath().startsWith(topDir) && modPom.exists()
                            && !seen.contains(modPom) && !pendingPoms.contains(modPom)) {
                        pendingPoms.addLast(modPom);
                    } else {
                        logger.info("Skipping reference to non-existent module: '" + module + "' in: " + pom);
                    }
                }
            }
        } else {
            logger.info("Skipping " + pom + " as its a template file.");
        }
    }

    return peeked;
}