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:org.kitodo.production.forms.dataeditor.StructurePanel.java

private void checkLogicalDragDrop(IncludedStructuralElement dragStructure,
        IncludedStructuralElement dropStructure) {
    StructuralElementViewInterface divisionView = dataEditor.getRuleset().getStructuralElementView(
            dropStructure.getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());

    LinkedList<IncludedStructuralElement> dragParents;
    if (divisionView.getAllowedSubstructuralElements().containsKey(dragStructure.getType())) {
        dragParents = MetadataEditor.getAncestorsOfStructure(dragStructure,
                dataEditor.getWorkpiece().getRootElement());
        if (!dragParents.isEmpty()) {
            IncludedStructuralElement parentStructure = dragParents.get(dragParents.size() - 1);
            if (parentStructure.getChildren().contains(dragStructure)) {
                preserveLogical();/*  ww w .j a v  a  2 s  .  c  o m*/
                return;
            } else {
                Helper.setErrorMessage(
                        "Parents of structure " + dragStructure.getType() + " do not contain structure!");
            }
        } else {
            Helper.setErrorMessage("No parents of structure " + dragStructure.getType() + " found!");
        }
    } else {
        Helper.setErrorMessage("Structure of type '" + dragStructure.getType()
                + "' NOT allowed as child of structure of type '" + dropStructure.getType() + "'! ");
    }
    show();
}

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

/**
 * Pops the current command execution state array from the stack.
 *//*from ww w. j  a  va  2s  .c  o  m*/
private final void popCommandExecutionState() {
    // get the stack for the current thread.
    LinkedList<CommandExecutionState[]> stack = commandExecutionStateStackTL.get();

    // if there was not a stack, then we are in an illegal state.
    if (stack == null) {
        throw new IllegalStateException(
                "popCommandExecutionState() called when there was not a current stack.");
    }

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

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

From source file:org.eclipse.che.vfs.impl.fs.LocalFileSystemTest.java

protected List<String> flattenDirectory(String vfsPath) {
    java.io.File directory = getIoFile(vfsPath);
    assertTrue("Not a directory ", directory.isDirectory());
    final int splitIndex = directory.getAbsolutePath().length() + 1;
    List<String> files = new ArrayList<>();
    LinkedList<java.io.File> q = new LinkedList<>();
    q.add(directory);/*w  ww .j  a v a 2  s .c  om*/
    while (!q.isEmpty()) {
        java.io.File current = q.pop();
        java.io.File[] list = current.listFiles(SERVICE_DIR_FILTER);
        if (list != null) {
            for (java.io.File f : list) {
                files.add(f.getAbsolutePath().substring(splitIndex));
                if (f.isDirectory()) {
                    q.push(f);
                }
            }
        }
    }
    if (!files.isEmpty()) {
        java.util.Collections.sort(files);
    }
    return files;
}

From source file:org.gephi.statistics.plugin.ConnectedComponents.java

public void weaklyConnected(HierarchicalUndirectedGraph hgraph, AttributeModel attributeModel) {
    isCanceled = false;//from  ww w . j  a v a2s . com
    componentCount = 0;
    AttributeTable nodeTable = attributeModel.getNodeTable();
    AttributeColumn componentCol = nodeTable.getColumn(WEAKLY);
    if (componentCol == null) {
        componentCol = nodeTable.addColumn(WEAKLY, "Component ID", AttributeType.INT, AttributeOrigin.COMPUTED,
                new Integer(0));
    }

    List<Integer> sizeList = new ArrayList<Integer>();

    hgraph.readLock();

    HashMap<Node, Integer> indicies = new HashMap<Node, Integer>();
    int index = 0;
    for (Node s : hgraph.getNodes()) {
        indicies.put(s, index);
        index++;
    }

    int N = hgraph.getNodeCount();

    //Keep track of which nodes have been seen
    int[] color = new int[N];

    Progress.start(progress, hgraph.getNodeCount());
    int seenCount = 0;
    while (seenCount < N) {
        //The search Q
        LinkedList<Node> Q = new LinkedList<Node>();
        //The component-list
        LinkedList<Node> component = new LinkedList<Node>();

        //Seed the seach Q
        NodeIterable iter = hgraph.getNodes();
        for (Node first : iter) {
            if (color[indicies.get(first)] == 0) {
                Q.add(first);
                iter.doBreak();
                break;
            }
        }

        //While there are more nodes to search
        while (!Q.isEmpty()) {
            if (isCanceled) {
                hgraph.readUnlock();
                return;
            }
            //Get the next Node and add it to the component list
            Node u = Q.removeFirst();
            component.add(u);

            //Iterate over all of u's neighbors
            EdgeIterable edgeIter = hgraph.getEdgesAndMetaEdges(u);

            //For each neighbor
            for (Edge edge : edgeIter) {
                Node reachable = hgraph.getOpposite(u, edge);
                int id = indicies.get(reachable);
                //If this neighbor is unvisited
                if (color[id] == 0) {
                    color[id] = 1;
                    //Add it to the search Q
                    Q.addLast(reachable);
                    //Mark it as used 

                    Progress.progress(progress, seenCount);
                }
            }
            color[indicies.get(u)] = 2;
            seenCount++;
        }
        for (Node s : component) {
            AttributeRow row = (AttributeRow) s.getNodeData().getAttributes();
            row.setValue(componentCol, componentCount);
        }
        sizeList.add(component.size());
        componentCount++;
    }
    hgraph.readUnlock();

    componentsSize = new int[sizeList.size()];
    for (int i = 0; i < sizeList.size(); i++) {
        componentsSize[i] = sizeList.get(i);
    }
}

From source file:com.epam.reportportal.apache.http.conn.ssl.AbstractVerifier.java

public static String[] getCNs(final X509Certificate cert) {
    final LinkedList<String> cnList = new LinkedList<String>();
    /*//from  w  w  w . ja v  a2 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.cloudata.core.common.ipc.CClient.java

/**
 * Get a connection from the pool, or create a new one and add it to the pool.
 * Connections to a given host/port are reused.
 *///from  w ww  . j  a v a  2s . co  m
private Connection getConnection(InetSocketAddress address) throws IOException {
    Connection connection;

    synchronized (connections) {
        LinkedList<Connection> hostConnections = connections.get(address);

        if (hostConnections == null) {
            hostConnections = new LinkedList<Connection>();
            connections.put(address, hostConnections);
        }
        if (hostConnections.isEmpty()) {
            connection = new Connection(address);
        } else {
            connection = hostConnections.removeFirst();
        }
        connection.touch();
    }
    // we don't invoke the method below inside "synchronized (connections)"
    // block above. The reason for that is if the server happens to be slow,
    // it will take longer to establish a connection and that will slow the
    // entire system down.
    connection.setupIOstreams();
    return connection;
}

From source file:org.geometerplus.android.fbreader.QuotesFragmentActivity.java

@Override
protected void onNewIntent(Intent intent) {
    OrientationUtil.setOrientation(this, intent);

    if (!Intent.ACTION_SEARCH.equals(intent.getAction())) {
        return;//from  ww w  .j ava2s  .  c om
    }
    String pattern = intent.getStringExtra(SearchManager.QUERY);
    myQuoteSearchPatternOption.setValue(pattern);

    final LinkedList<Quote> quotes = new LinkedList<Quote>();
    pattern = pattern.toLowerCase();
    for (Quote b : myAllBooksAdapter.quotes()) {
        if (MiscUtil.matchesIgnoreCase(b.getText(), pattern)) {
            quotes.add(b);
        }
    }
    if (!quotes.isEmpty()) {
        showSearchResultsTab(quotes);
    } else {
        UIUtil.showErrorMessage(this, "quoteNotFound");
    }
}

From source file:org.fusesource.mop.MOP.java

protected void helpCommand(LinkedList<String> argList) {
    if (argList.isEmpty()) {
        displayHelp();//www  .  j  a  va  2s. c o  m
        return;
    }
    for (String commandName : argList) {
        checkCommandsLoaded();
        CommandDefinition command = commands.get(commandName);
        if (command == null) {
            p("No such command '" + command + "'");
        } else {
            p();
            p("mop command: " + command.getName());
            p();
            p("usage:");
            p("\t mop [options] " + command.getName() + " " + command.getUsage());
            p();
            p(command.getDescription());
            p();
        }
    }
}

From source file:org.fusesource.mop.MOP.java

private void assertNotEmpty(LinkedList<String> args) throws UsageException {
    if (args.isEmpty()) {
        throw new UsageException("Empty argument list");
    }/*from www .ja va 2  s  . co  m*/
}

From source file:org.eclipse.che.vfs.impl.fs.LocalFileSystemTest.java

protected void compareDirectories(java.io.File a, java.io.File b, boolean checkServiceDirs) throws IOException {
    if (!a.isDirectory() || !b.isDirectory()) {
        fail();/*  ww  w .j a va2 s. c o  m*/
    }
    LinkedList<Pair<java.io.File, java.io.File>> q = new LinkedList<>();
    q.add(new Pair<>(a, b));
    while (!q.isEmpty()) {
        Pair<java.io.File, java.io.File> current = q.pop();
        java.io.File[] files1 = current.first.listFiles(checkServiceDirs ? null : SERVICE_DIR_FILTER);
        java.io.File[] files2 = current.second.listFiles(checkServiceDirs ? null : SERVICE_DIR_FILTER);
        if (files1 == null || files2 == null || files1.length != files2.length) {
            fail();
        }
        Arrays.sort(files1);
        Arrays.sort(files2);
        for (int i = 0; i < files1.length; i++) {
            java.io.File file1 = files1[i];
            java.io.File file2 = files2[i];
            if (!file1.getName().equals(file2.getName())) {
                fail();
            }
            if (file1.isFile()) {
                try (FileInputStream in1 = new FileInputStream(file1);
                        FileInputStream in2 = new FileInputStream(file2)) {
                    compareStreams(in1, in2);
                }
            } else {
                q.push(new Pair<>(file1, file2));
            }
        }
    }
}