Example usage for java.util ArrayList isEmpty

List of usage examples for java.util ArrayList isEmpty

Introduction

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

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:cz.incad.kramerius.virtualcollections.VirtualCollectionsManager.java

public static List<VirtualCollection> getVirtualCollectionsFromFedora(FedoraAccess fedoraAccess,
        ArrayList<String> languages) throws Exception {
    try {/*  w w  w. j  a  va 2  s .  c om*/
        IResourceIndex g = ResourceIndexService.getResourceIndexImpl();
        Document doc = g.getVirtualCollections();

        NodeList nodes = doc.getDocumentElement().getElementsByTagNameNS(SPARQL_NS, "result");
        NodeList children;
        Node child;
        String name;
        String pid;
        boolean canLeave;

        ArrayList<String> langs = new ArrayList<String>();

        if (languages == null || languages.isEmpty()) {
            String[] ls = KConfiguration.getInstance().getPropertyList("interface.languages");
            for (int i = 0; i < ls.length; i++) {
                String lang = ls[++i];
                langs.add(lang);
            }
        } else {
            langs = new ArrayList<String>(languages);
        }

        List<VirtualCollection> vcs = new ArrayList<VirtualCollection>();
        for (int i = 0; i < nodes.getLength(); i++) {
            canLeave = false;
            name = null;
            pid = null;
            Node node = nodes.item(i);
            children = node.getChildNodes();
            for (int j = 0; j < children.getLength(); j++) {
                child = children.item(j);
                if ("title".equals(child.getLocalName())) {
                    name = child.getFirstChild().getNodeValue();
                } else if ("object".equals(child.getLocalName())) {
                    pid = ((Element) child).getAttribute("uri").replaceAll("info:fedora/", "");
                } else if ("canLeave".equals(child.getLocalName())) {
                    canLeave = Boolean.parseBoolean(child.getFirstChild().getNodeValue().replaceAll("\"", "")
                            .substring(("canLeave:").length()));
                }
            }

            if (name != null && pid != null) {
                try {
                    VirtualCollection vc = new VirtualCollection(name, pid, canLeave);

                    for (String lang : langs) {
                        String dsName = TEXT_DS_PREFIX + lang;
                        String value = IOUtils.readAsString(fedoraAccess.getDataStream(pid, dsName),
                                Charset.forName("UTF8"), true);
                        vc.addDescription(lang, value);
                    }
                    vcs.add(vc);
                } catch (Exception vcex) {
                    logger.log(Level.WARNING,
                            "Could not get virtual collection for  " + pid + ": " + vcex.toString());

                }
            }
        }
        return vcs;
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Error getting virtual collections", ex);
        throw new Exception(ex);
    }
}

From source file:entity.files.SYSFilesTools.java

/**
 * <code>putFile(String)</code> speichert eine Datei auf dem FTP Server ab und erstellt eine SYSFiles EntityBean. Die Methode geht dabei wie folgt vor:
 * <ol>// w w  w  .  j  a v a  2s  .  co m
 * <li>Zuerst wird der MD5 der zu speichernden Datei berechnet.</li>
 * <li>Anhand dieser MD5 Signatur wird ermittelt, ob es schon einen entsprechenden Eintrag in der Datenbank gibt.
 * <ul>
 * <li>Wenn ja, dann wird einfach der PK zurckgegeben. Nochmal speichern braucht man das ja nicht. <b>RETURN</b></li>
 * <li>Wenn nicht, dann geht die Bearbeitung weiter.</li>
 * </ul>
 * <li>Erstellen einer SYSFiles EB</li>
 * <li>Senden der Datei an den FTP Server</li>
 * <li>Wenn die letzten beiden Schritte erfolgreich waren, dann wird die neue EB als Ergebnis zurck gegeben. null, bei Fehler.</li>
 * </ol>
 *
 * @param file File Objekt der zu speichernden Datei
 * @return EB der neuen Datei. null bei Fehler.
 */
private static SYSFiles putFile(EntityManager em, FileTransferClient ftp, File file) throws Exception {
    SYSFiles sysfile = null;

    String md5 = SYSTools.getMD5Checksum(file);
    Query query = em.createQuery("SELECT s FROM SYSFiles s WHERE s.md5 = :md5");
    query.setParameter("md5", md5);

    ArrayList<SYSFiles> alreadyExistingFiles = new ArrayList<SYSFiles>(query.getResultList());

    // Gibts die Datei schon ?
    if (alreadyExistingFiles.isEmpty()) { // nein, noch nicht
        sysfile = em.merge(new SYSFiles(file.getName(), md5, new Date(file.lastModified()), file.length(),
                OPDE.getLogin().getUser()));
        //            FileInputStream fis = new FileInputStream(file);
        ftp.uploadFile(file.getPath(), sysfile.getRemoteFilename());

        //            ftp.storeF.storeFile(file.getPath(),sysfile.getRemoteFilename());
        OPDE.info(
                SYSTools.xx("misc.msg.upload") + ": " + sysfile.getFilename() + " (" + sysfile.getMd5() + ")");
        //            fis.close();
    } else { // Ansonsten die bestehende Datei zurckgeben

        sysfile = alreadyExistingFiles.get(0);

        // Does the User own this file already ?
        //            for (SYSFiles mySYSfile : alreadyExistingFiles) {
        //                if (mySYSfile.getResident().equals(resident)) {
        //                    sysfile = mySYSfile;
        //                    break;
        //                }
        //            }
        //            if (sysfile == null) {
        //                sysfile = em.merge(new SYSFiles(file.getName(), md5, new Date(file.lastModified()), file.length(), OPDE.getLogin().getUser(), resident));
        //            }
    }

    return sysfile;
}

From source file:levelBuilder.DialogMaker.java

/**
 * Provides other action buttons.//from   w w  w  . j  av a 2  s .  c  o  m
 */
private static void actionWindow() {
    //Performs actions based on button pushes.
    class ActionHandler implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            switch (e.getActionCommand()) {
            case "edge":
                if (addedEdgeID != 0.0) {
                    DialogNode n = g.getSource(addedEdgeID);
                    int length;
                    if (n.getChildren().length == 0)
                        length = 0;
                    else
                        length = n.getChildren().length;
                    DialogNode[] newChildren = new DialogNode[length + 1];
                    for (int c = 0; c < newChildren.length - 1; c++)
                        newChildren[c] = n.getChildren()[c];
                    newChildren[newChildren.length - 1] = nodeMap.get(g.getDest(addedEdgeID).getText());
                    n.setChildren(newChildren);
                    addedEdgeID = 0.0;
                }
            case "save":
                saveGraph();
            case "check":
                //Checks for errors and displays them if they exist.
                ArrayList<String> errorList = new ArrayList<String>();
                errorList = dg.check();
                if (errorList.isEmpty()) {
                    JOptionPane.showMessageDialog(null, "No errors!", null, JOptionPane.PLAIN_MESSAGE);
                } else {
                    JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0));
                    for (String error : errorList)
                        panel.add(new JLabel(error));
                    JOptionPane.showMessageDialog(null, panel, "Errors. Fix these to continue.",
                            JOptionPane.PLAIN_MESSAGE);
                }
            case "reload":
                loadGraph(false);
            }
        }
    }

    JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0));

    //Buttons
    JButton button3 = new JButton("New edge");
    button3.setActionCommand("edge");
    button3.addActionListener(new ActionHandler());
    panel.add(button3);

    JButton button6 = new JButton("Save");
    button6.setActionCommand("save");
    button6.addActionListener(new ActionHandler());
    panel.add(button6);

    JButton button7 = new JButton("Check");
    button7.setActionCommand("check");
    button7.addActionListener(new ActionHandler());
    panel.add(button7);

    JButton button1 = new JButton("Reload");
    button1.setActionCommand("reload");
    button1.addActionListener(new ActionHandler());
    panel.add(button1);

    JFrame frame = new JFrame("Other Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(panel);
    frame.pack();
    frame.setLocation(windowWidth + horizontalWindowPlacement, 0);
    frame.setVisible(true);
}

From source file:net.opentsdb.meta.Annotation.java

/**
 * Attempts to fetch a global or local annotation from storage
 * @param tsdb The TSDB to use for storage access
 * @param tsuid The TSUID as a byte array. May be null if retrieving a global
 * annotation/* w w w .ja v  a  2s.c  o m*/
 * @param start_time The start time as a Unix epoch timestamp
 * @return A valid annotation object if found, null if not
 */
public static Deferred<Annotation> getAnnotation(final TSDB tsdb, final byte[] tsuid, final long start_time) {

    /**
     * Called after executing the GetRequest to parse the meta data.
     */
    final class GetCB implements Callback<Deferred<Annotation>, ArrayList<KeyValue>> {

        /**
         * @return Null if the meta did not exist or a valid Annotation object if 
         * it did.
         */
        @Override
        public Deferred<Annotation> call(final ArrayList<KeyValue> row) throws Exception {
            if (row == null || row.isEmpty()) {
                return Deferred.fromResult(null);
            }

            Annotation note = JSON.parseToObject(row.get(0).value(), Annotation.class);
            return Deferred.fromResult(note);
        }

    }

    final GetRequest get = new GetRequest(tsdb.dataTable(), getRowKey(start_time, tsuid));
    get.family(FAMILY);
    get.qualifier(getQualifier(start_time));
    return tsdb.getClient().get(get).addCallbackDeferring(new GetCB());
}

From source file:net.opentsdb.tree.TreeRule.java

/**
 * Attempts to retrieve the specified tree rule from storage.
 * @param tsdb The TSDB to use for storage access
 * @param tree_id ID of the tree the rule belongs to
 * @param level Level where the rule resides
 * @param order Order where the rule resides
 * @return A TreeRule object if found, null if it does not exist
 * @throws HBaseException if there was an issue
 * @throws IllegalArgumentException if the one of the required parameters was
 * missing/*  w  ww .  j  av a 2 s  .c  o m*/
 * @throws JSONException if the object could not be serialized
 */
public static Deferred<TreeRule> fetchRule(final TSDB tsdb, final int tree_id, final int level,
        final int order) {
    if (tree_id < 1 || tree_id > 65535) {
        throw new IllegalArgumentException("Invalid Tree ID");
    }
    if (level < 0) {
        throw new IllegalArgumentException("Invalid rule level");
    }
    if (order < 0) {
        throw new IllegalArgumentException("Invalid rule order");
    }

    // fetch the whole row
    final GetRequest get = new GetRequest(tsdb.treeTable(), Tree.idToBytes(tree_id));
    get.family(Tree.TREE_FAMILY());
    get.qualifier(getQualifier(level, order));

    /**
     * Called after fetching to parse the results
     */
    final class FetchCB implements Callback<Deferred<TreeRule>, ArrayList<KeyValue>> {

        @Override
        public Deferred<TreeRule> call(final ArrayList<KeyValue> row) {
            if (row == null || row.isEmpty()) {
                return Deferred.fromResult(null);
            }
            return Deferred.fromResult(parseFromStorage(row.get(0)));
        }
    }

    return tsdb.getClient().get(get).addCallbackDeferring(new FetchCB());
}

From source file:net.opentsdb.tree.Branch.java

/**
 * Attempts to fetch only the branch definition object from storage. This is
 * much faster than scanning many rows for child branches as per the 
 * {@link #fetchBranch} call. Useful when building trees, particularly to
 * fetch the root branch.//from   ww  w . ja v a  2 s . c  o m
 * @param tsdb The TSDB to use for access
 * @param branch_id ID of the branch to retrieve
 * @return A branch if found, null if it did not exist
 * @throws JSONException if the object could not be deserialized
 */
public static Deferred<Branch> fetchBranchOnly(final TSDB tsdb, final byte[] branch_id) {

    final GetRequest get = new GetRequest(tsdb.treeTable(), branch_id);
    get.family(Tree.TREE_FAMILY());
    get.qualifier(BRANCH_QUALIFIER);

    /**
     * Called after the get returns with or without data. If we have data, we'll
     * parse the branch and return it.
     */
    final class GetCB implements Callback<Deferred<Branch>, ArrayList<KeyValue>> {

        @Override
        public Deferred<Branch> call(ArrayList<KeyValue> row) throws Exception {
            if (row == null || row.isEmpty()) {
                return Deferred.fromResult(null);
            }

            final Branch branch = JSON.parseToObject(row.get(0).value(), Branch.class);

            // WARNING: Since the json doesn't store the tree ID, to cut down on
            // space, we have to load it from the row key.
            branch.tree_id = Tree.bytesToId(row.get(0).key());
            return Deferred.fromResult(branch);
        }

    }

    return tsdb.getClient().get(get).addCallbackDeferring(new GetCB());
}

From source file:net.opentsdb.tree.TreeRule.java

/**
 * Attempts to delete all rules belonging to the given tree.
 * @param tsdb The TSDB to use for storage access
 * @param tree_id ID of the tree the rules belongs to
 * @return A deferred to wait on for completion. The value has no meaning and
 * may be null.// w ww.  j a va 2s . c o m
 * @throws HBaseException if there was an issue
 * @throws IllegalArgumentException if the one of the required parameters was
 * missing
 */
public static Deferred<Object> deleteAllRules(final TSDB tsdb, final int tree_id) {
    if (tree_id < 1 || tree_id > 65535) {
        throw new IllegalArgumentException("Invalid Tree ID");
    }

    // fetch the whole row
    final GetRequest get = new GetRequest(tsdb.treeTable(), Tree.idToBytes(tree_id));
    get.family(Tree.TREE_FAMILY());

    /**
     * Called after fetching the requested row. If the row is empty, we just
     * return, otherwise we compile a list of qualifiers to delete and submit
     * a single delete request to storage.
     */
    final class GetCB implements Callback<Deferred<Object>, ArrayList<KeyValue>> {

        @Override
        public Deferred<Object> call(final ArrayList<KeyValue> row) throws Exception {
            if (row == null || row.isEmpty()) {
                return Deferred.fromResult(null);
            }

            final ArrayList<byte[]> qualifiers = new ArrayList<byte[]>(row.size());

            for (KeyValue column : row) {
                if (column.qualifier().length > RULE_PREFIX.length
                        && Bytes.memcmp(RULE_PREFIX, column.qualifier(), 0, RULE_PREFIX.length) == 0) {
                    qualifiers.add(column.qualifier());
                }
            }

            final DeleteRequest delete = new DeleteRequest(tsdb.treeTable(), Tree.idToBytes(tree_id),
                    Tree.TREE_FAMILY(), qualifiers.toArray(new byte[qualifiers.size()][]));
            return tsdb.getClient().delete(delete);
        }

    }

    return tsdb.getClient().get(get).addCallbackDeferring(new GetCB());
}

From source file:org.opendatakit.common.android.data.ColumnDefinition.java

/**
 * This must match the code in the javascript layer
 * //from   w w  w . j  a  v  a  2  s  . com
 * See databaseUtils.markUnitOfRetention
 * 
 * Sweeps through the collection of ColumnDefinition objects and marks the
 * ones that exist in the actual database table.
 * 
 * @param defn
 */
private static void markUnitOfRetention(Map<String, ColumnDefinition> defn) {
    // for all arrays, mark all descendants of the array as not-retained
    // because they are all folded up into the json representation of the array
    for (String startKey : defn.keySet()) {
        ColumnDefinition colDefn = defn.get(startKey);
        if (!colDefn.isUnitOfRetention()) {
            // this has already been processed
            continue;
        }
        if (ElementDataType.array.name().equals(colDefn.getElementType())) {
            ArrayList<ColumnDefinition> descendantsOfArray = new ArrayList<ColumnDefinition>(
                    colDefn.getChildren());
            ArrayList<ColumnDefinition> scratchArray = new ArrayList<ColumnDefinition>();
            while (!descendantsOfArray.isEmpty()) {
                for (ColumnDefinition subDefn : descendantsOfArray) {
                    if (!subDefn.isUnitOfRetention()) {
                        // this has already been processed
                        continue;
                    }
                    subDefn.setNotUnitOfRetention();
                    scratchArray.addAll(subDefn.getChildren());
                }
                descendantsOfArray = scratchArray;
            }
        }
    }
    // and mark any non-arrays with multiple fields as not retained
    for (String startKey : defn.keySet()) {
        ColumnDefinition colDefn = defn.get(startKey);
        if (!colDefn.isUnitOfRetention()) {
            // this has already been processed
            continue;
        }
        if (!ElementDataType.array.name().equals(colDefn.getElementType())) {
            if (!colDefn.getChildren().isEmpty()) {
                colDefn.setNotUnitOfRetention();
            }
        }
    }
}

From source file:com.github.codingtogenomic.CodingToGenomic.java

private static String codingToGenomicGene(final String id, final String symbol, final int c, final boolean utr,
        final boolean mapCdna) throws ParseException, MalformedURLException, IOException, InterruptedException {
    final ArrayList<String> tr = getTranscriptIds(id, mapCdna);
    if (tr.isEmpty()) {
        return "-\t-\t-\t" + id + "\tNo coding transcripts found for " + symbol + " (" + id + ")\n";
    }/*from w  ww .  j  ava2  s.c om*/
    /*
    StringBuilder transcriptList = new StringBuilder(tr.get(0));
    for (int i = 1; i < tr.size(); i++){
        transcriptList.append(",").append(tr.get(i));
    }
    //System.out.println(symbol + " => " + id + " => " + transcriptList.toString());
    */
    String fetch = "cds";
    if (mapCdna) {
        fetch = "cdna";
    }
    final String stub = symbol + "\t" + id + "\t";
    StringBuilder results = new StringBuilder();
    for (String t : tr) {
        final String seq = getTranscriptSequence(t, fetch);
        if (seq != null) {
            if (seq.length() >= c) {
                String gCoord;
                if (mapCdna) {
                    gCoord = cdnaToGenomicCoordinate(t, c);
                } else {
                    gCoord = cdsToGenomicCoordinate(t, c, utr);
                }
                if (gCoord != null) {
                    results.append(stub).append(t).append("\t").append(gCoord).append("\n");
                } else {
                    results.append(stub).append(t).append("\tCould not map ").append(fetch.toUpperCase())
                            .append(" coordinate\n");
                }
            } else {
                results.append(stub).append(t).append("\t").append(fetch.toUpperCase()).append("coordinate (")
                        .append(c).append(") > ").append(fetch.toUpperCase()).append(" length (")
                        .append(seq.length()).append(")\n");
            }
        } else {
            results.append(stub).append("-\tNo CDS sequence found\n");
        }

    }
    return results.toString();
}

From source file:adalid.commons.properties.PropertiesHandler.java

private static File[] platformsFolders() {
    if (velocity_folders == null || velocity_folders.length == 0) {
        return null;
    }//from   w w w.  j a v a 2  s.  c  o m
    String platforms = "platforms";
    File file;
    ArrayList<File> files = new ArrayList<>();
    for (File folder : velocity_folders) {
        file = new File(folder.getPath() + FILE_SEP + platforms);
        if (FilUtils.isVisibleDirectory(file)) {
            files.add(file);
        }
    }
    if (files.isEmpty()) {
        logMissingDirectory(VELOCITY_FOLDER_KEY, platforms);
        return null;
    }
    return files.toArray(new File[0]);
}