Example usage for java.util HashSet isEmpty

List of usage examples for java.util HashSet isEmpty

Introduction

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

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:it.iit.genomics.cru.structures.bridges.uniprot.UniprotkbUtils.java

/**
 *
 * @param refSeqs/*from  www  .j  a  va  2  s  .c  o  m*/
 * @return
 * @throws BridgesRemoteAccessException
 */
public MapOfMap<String, MoleculeEntry> getUniprotEntriesFromRefSeqs(Collection<String> refSeqs)
        throws BridgesRemoteAccessException {
    String tool = UNIPROT_TOOL;

    MapOfMap<String, MoleculeEntry> refseq2uniprots = new MapOfMap<>(refSeqs);

    if (refSeqs.isEmpty()) {
        return refseq2uniprots;
    }

    HashSet<String> refs2get = new HashSet<>();

    try {
        for (String refseq : refSeqs) {
            if (cache.containsKey(refseq.toUpperCase().split("\\.")[0])) {
                refseq2uniprots.addAll(refseq, cache.get(refseq.toUpperCase().split("\\.")[0]));
            } else {
                refs2get.add(refseq);

                // if size == limit, do query
                if (refs2get.size() == maxQueries) {

                    String location = UNIPROT_SERVER + tool + "/?" + "query=keyword:181+AND+organism:"
                            + URLEncoder.encode("\"" + taxid + "\"", "UTF-8")
                            + "+AND+(database%3A(type%3Arefseq+"
                            + URLEncoder.encode(
                                    "" + StringUtils.join(refs2get, ") OR database:(type:refseq ") + "",
                                    "UTF-8")
                            + "))";

                    Collection<MoleculeEntry> uniprotEntries = getUniprotEntriesXML(location);

                    for (MoleculeEntry entry : uniprotEntries) {
                        for (String xref : entry.getRefseqs()) {
                            if (xref.endsWith(".")) {
                                xref = xref.substring(0, xref.length() - 1);
                            }
                            if (refseq2uniprots.containsKey(xref.trim())) {
                                refseq2uniprots.add(xref, entry);
                            } else if (refseq2uniprots.containsKey(xref.split("[.]")[0])) {
                                refseq2uniprots.add(xref.split("[.]")[0], entry);
                            }
                        }
                    }
                    refs2get.clear();
                }

            }
        }

        if (refs2get.isEmpty()) {
            return refseq2uniprots;
        }

        String location = UNIPROT_SERVER + tool + "/?" + "query=keyword:181+AND+organism:"
                + URLEncoder.encode("\"" + taxid + "\"", "UTF-8") + "+AND+(database%3A(type%3Arefseq+"
                + URLEncoder.encode("" + StringUtils.join(refs2get, ") OR database:(type:refseq ") + "",
                        "UTF-8")
                + "))";

        Collection<MoleculeEntry> uniprotEntries = getUniprotEntriesXML(location);

        for (MoleculeEntry entry : uniprotEntries) {
            for (String xref : entry.getRefseqs()) {
                if (xref.endsWith(".")) {
                    xref = xref.substring(0, xref.length() - 1);
                }
                if (refseq2uniprots.containsKey(xref.trim())) {
                    refseq2uniprots.add(xref, entry);
                } else if (refseq2uniprots.containsKey(xref.split("[.]")[0])) {
                    refseq2uniprots.add(xref.split("[.]")[0], entry);
                }
            }
        }

    } catch (UnsupportedEncodingException e) {
        logger.error("cannot get proteins for " + StringUtils.join(refSeqs, ", "), e);
    }

    return refseq2uniprots;
}

From source file:org.apache.hadoop.hive.ql.QTestUtil.java

/**
 * Returns the default UDF names which should not be removed when resetting the test database
 * @return The list of the UDF names not to remove
 *///from  w w w.  jav  a2 s.  c  o  m
private Set<String> getSrcUDFs() {
    HashSet<String> srcUDFs = new HashSet<String>();
    // FIXME: moved default value to here...for now
    // i think this features is never really used from the command line
    String defaultTestSrcUDFs = "qtest_get_java_boolean";
    for (String srcUDF : System.getProperty("test.src.udfs", defaultTestSrcUDFs).trim().split(",")) {
        srcUDF = srcUDF.trim();
        if (!srcUDF.isEmpty()) {
            srcUDFs.add(srcUDF);
        }
    }
    if (srcUDFs.isEmpty()) {
        throw new RuntimeException("Source UDFs cannot be empty");
    }
    return srcUDFs;
}

From source file:amie.keys.CSAKey.java

private Graph mergeGraphs(Graph currentGraph, Graph graph2, HashSet<Node> currentGraphTopNodes,
        HashSet<Integer> conditionProperties) {
    HashSet<Node> childrenNodes = new HashSet<>();
    for (Node currentGraphNewtopNode : currentGraphTopNodes) {
        if (currentGraphNewtopNode.toExplore) {
            //   System.out.println("currentGraphNewtopNode:"+currentGraphNewtopNode);
            if (graph2.graph.containsKey(currentGraphNewtopNode)) {
                // System.out.println("yes");
                Node nodeInGraphNew2 = graph2.getNode(currentGraphNewtopNode);
                if (!nodeInGraphNew2.toExplore) {
                    //   System.out.println("no2");
                    currentGraphNewtopNode.toExplore = false;
                    currentGraph.createOrGetNode(currentGraphNewtopNode);
                } else {
                    // System.out.println("yes2");
                    HashSet<Integer> allProperties = new HashSet<>();
                    allProperties.addAll(conditionProperties);
                    allProperties.addAll(currentGraphNewtopNode.set);
                    //  System.out.println("allProperties:"+allProperties);
                    if (!containsSubSet(allProperties)) {
                        //  System.out.println("no3");
                        currentGraphNewtopNode.toExplore = false;
                        currentGraph.createOrGetNode(currentGraphNewtopNode);
                    }/*from  ww w  .  jav  a2  s . c o  m*/
                }
            } else {
                //   System.out.println("no");
                currentGraphNewtopNode.toExplore = false;
                currentGraph.createOrGetNode(currentGraphNewtopNode);
            }
        }

        if (currentGraph.graph.get(currentGraphNewtopNode) != null) {
            childrenNodes.addAll(currentGraph.graph.get(currentGraphNewtopNode));
        }
    }
    if (!childrenNodes.isEmpty()) {
        mergeGraphs(currentGraph, graph2, childrenNodes, conditionProperties);
    }
    return currentGraph;
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java

protected List<Integer> getSelectionIndexes(Collection<? extends Entity> items) {
    if (items.isEmpty()) {
        return Collections.emptyList();
    }//from   ww w.j a  v  a 2  s  . co m
    List<Integer> indexes = Lists.newArrayList();
    if (datasource instanceof CollectionDatasource.Ordered) {
        HashSet<Entity> itemSet = new HashSet<>(items);
        int itemIndex = 0;
        CollectionDatasource.Ordered orderedDs = (CollectionDatasource.Ordered) datasource;
        Object id = orderedDs.firstItemId();
        while (id != null && !itemSet.isEmpty()) {
            int rowIndex = impl.convertRowIndexToView(itemIndex);
            // noinspection unchecked
            Entity itemById = datasource.getItem(id);
            if (itemSet.contains(itemById)) {
                indexes.add(rowIndex);
                itemSet.remove(itemById);
            }
            // noinspection unchecked
            id = orderedDs.nextItemId(id);
            itemIndex++;
        }
    } else {
        for (Entity item : items) {
            int idx = tableModel.getRowIndex(item);
            if (idx != -1) {
                indexes.add(impl.convertColumnIndexToView(idx));
            }
        }
    }
    return indexes;
}

From source file:org.ramadda.geodata.cdmdata.CdmDataOutputHandler.java

/**
 * Get the grid dates/*from ww w.jav a2 s.  c  o m*/
 *
 * @param dataset  the dataset
 *
 * @return  the dates or null
 */
private List<Date> getGridDates(GridDataset dataset) {
    List<Date> gridDates = null;
    List<GridDatatype> grids = dataset.getGrids();
    HashSet<Date> dateHash = new HashSet<Date>();
    List<CoordinateAxis1DTime> timeAxes = new ArrayList<CoordinateAxis1DTime>();

    for (GridDatatype grid : grids) {
        GridCoordSystem gcs = grid.getCoordinateSystem();
        CoordinateAxis1DTime timeAxis = gcs.getTimeAxis1D();
        if ((timeAxis != null) && !timeAxes.contains(timeAxis)) {
            timeAxes.add(timeAxis);

            Date[] timeDates = timeAxis.getTimeDates();
            for (Date timeDate : timeDates) {
                dateHash.add(timeDate);
            }
        }
    }
    if (!dateHash.isEmpty()) {
        gridDates = Arrays.asList(dateHash.toArray(new Date[dateHash.size()]));
        Collections.sort(gridDates);
    }

    return gridDates;
}

From source file:it.iit.genomics.cru.structures.bridges.uniprot.UniprotkbUtils.java

/**
 *
 * @param ensemblGeneIDs//from   w w  w  . jav a  2s  .co m
 * @return
 * @throws BridgesRemoteAccessException
 */
public MapOfMap<String, MoleculeEntry> getUniprotEntriesFromEnsembl(Collection<String> ensemblGeneIDs)
        throws BridgesRemoteAccessException {
    String tool = UNIPROT_TOOL;

    MapOfMap<String, MoleculeEntry> ensembl2uniprots = new MapOfMap<>(ensemblGeneIDs);

    if (ensemblGeneIDs.isEmpty()) {
        return ensembl2uniprots;
    }

    HashSet<String> refs2get = new HashSet<>();

    try {

        for (String ensemblGeneID : ensemblGeneIDs) {
            if (cache.containsKey(ensemblGeneID.toUpperCase().split("\\.")[0])) {
                ensembl2uniprots.addAll(ensemblGeneID, cache.get(ensemblGeneID.toUpperCase().split("\\.")[0]));
            } else {
                refs2get.add(ensemblGeneID);

                // if size == limit, do query
                if (refs2get.size() == maxQueries) {
                    String location = UNIPROT_SERVER + tool + "/?" + "query=keyword:181+AND+organism:"
                            + URLEncoder.encode("\"" + taxid + "\"", "UTF-8")
                            + "+AND+(database%3A(type%3Aensembl+"
                            + URLEncoder.encode(
                                    "" + StringUtils.join(refs2get, ") OR database:(type:ensembl ") + "",
                                    "UTF-8")
                            + "))";

                    Collection<MoleculeEntry> uniprotEntries = getUniprotEntriesXML(location);

                    for (MoleculeEntry entry : uniprotEntries) {
                        for (String xref : entry.getEnsemblGenes()) {
                            if (xref.endsWith(".")) {
                                xref = xref.substring(0, xref.length() - 1);
                            }
                            if (ensembl2uniprots.containsKey(xref.trim())) {
                                ensembl2uniprots.add(xref, entry);
                            } else if (ensembl2uniprots.containsKey(xref.split("[.]")[0])) {
                                ensembl2uniprots.add(xref.split("[.]")[0], entry);
                            }
                        }
                    }
                    refs2get.clear();
                }
            }
        }

        if (refs2get.isEmpty()) {
            return ensembl2uniprots;
        }

        String location = UNIPROT_SERVER + tool + "/?" + "query=keyword:181+AND+organism:"
                + URLEncoder.encode("\"" + taxid + "\"", "UTF-8") + "+AND+(database%3A(type%3Aensembl+"
                + URLEncoder.encode("" + StringUtils.join(refs2get, ") OR database:(type:ensembl ") + "",
                        "UTF-8")
                + "))";

        Collection<MoleculeEntry> uniprotEntries = getUniprotEntriesXML(location);

        for (MoleculeEntry entry : uniprotEntries) {
            for (String xref : entry.getEnsemblGenes()) {
                if (xref.endsWith(".")) {
                    xref = xref.substring(0, xref.length() - 1);
                }
                if (ensembl2uniprots.containsKey(xref.trim())) {
                    ensembl2uniprots.add(xref, entry);
                } else if (ensembl2uniprots.containsKey(xref.split("[.]")[0])) {
                    ensembl2uniprots.add(xref.split("[.]")[0], entry);
                }
            }
        }

    } catch (UnsupportedEncodingException e) {
        logger.error("cannot get proteins for " + StringUtils.join(ensemblGeneIDs, ", "), e);
    }

    return ensembl2uniprots;
}

From source file:tvbrowser.ui.mainframe.MainFrame.java

/**
 * extract the drag and drop targets from the event
 * @param transferable//  ww w .j  a  v  a 2s .co  m
 * @param dataFlavors
 * @return
 */
private File[] getDragDropPlugins(final DataFlavor[] dataFlavors, final Transferable transferable) {
    HashSet<File> files = new HashSet<File>();
    for (DataFlavor flavor : dataFlavors) {
        try {
            Object data = transferable.getTransferData(flavor);

            if (data instanceof List) {
                for (Object o : ((List) data)) {
                    if (o instanceof File) {
                        addPluginFile((File) o, files);
                    }
                }
                if (!files.isEmpty()) {
                    break;
                }
            } else if (data instanceof String) {
                String name = ((String) data).trim();
                if (name.toLowerCase().endsWith("jar")) {
                    File pluginFile = new File(name);
                    if (pluginFile.canRead()) {
                        addPluginFile(pluginFile, files);
                        if (!files.isEmpty()) {
                            break;
                        }
                    } else {
                        try {
                            URI uri = new URI(name);
                            addPluginFile(new File(uri), files);
                        } catch (URISyntaxException e) { // ignore
                        }
                        if (!files.isEmpty()) {
                            break;
                        }
                    }
                }
            }
        } catch (UnsupportedFlavorException e) { //ignore
        } catch (IOException e) { //ignore
        }
    }
    return files.toArray(new File[files.size()]);
}

From source file:com.emc.storageos.volumecontroller.impl.plugins.IsilonCommunicationInterface.java

private HashMap<String, HashSet<Integer>> getExportsIncludingSubDir(String fsPath,
        HashMap<String, HashSet<Integer>> expMap) {
    HashMap<String, HashSet<Integer>> expMapWithIds = new HashMap<>();
    for (String expPath : expMap.keySet()) {
        if (expPath.equalsIgnoreCase(fsPath) || expPath.contains(fsPath + "/")) {
            HashSet<Integer> expIds = expMap.get(expPath);
            if (expIds != null && !expIds.isEmpty()) {
                expMapWithIds.put(expPath, expIds);
            } else {
                expMapWithIds.put(expPath, new HashSet<Integer>());
            }// w w w  .  j ava2s  .  co m
        }
    }
    return expMapWithIds;
}

From source file:dao.DirectoryAuthorDaoDb.java

/**
 * Given a directoryid, returns HashSet of authors
 * @param directoryId the id of the directory
 * @param userId administrator of directory
 * @param userLogin administrator's login of directory
 * @param accessFlag access Flag//from  w w  w  . jav  a 2s  .  com
 * @return HashSet - list of authors with the login and member name
 * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect
 */
public HashSet listAuthorsOfDirectory(String directoryId, String userId, String userLogin, int accessFlag) {

    if (RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(userLogin)) {
        throw new BaseDaoException("params are null");
    }

    /**
          *  check user permissions
          */
    if (!diaryAdmin.isDiaryAdmin(userLogin) && !isAuthor(directoryId, userId)) {
        throw new BaseDaoException(
                "User does not have permission to list authors, " + directoryId + " userId = " + userId);
    }

    Fqn fqn = cacheUtil.fqn(DbConstants.DIR_AUTHORS);
    Object obj = treeCache.get(fqn, directoryId);
    if (obj != null) {
        return (HashSet) obj;
    }

    /**
     *  Get scalability datasource for directory, diradmin, 
     *  hdlogin not partitioned
     */
    String sourceName = scalabilityManager.getReadZeroScalability();
    ds = scalabilityManager.getSource(sourceName);
    if (ds == null) {
        throw new BaseDaoException("ds null, listAuthors() " + sourceName + " userId = " + userId);
    }

    HashSet myResult = null;
    Connection conn = null;
    try {
        conn = ds.getConnection();
        myResult = listAuthorQuery.run(conn, directoryId);
    } catch (Exception e) {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e1) {
            throw new BaseDaoException(
                    "error while listing author query, conn.close()exception in listAuthorQuery " + userLogin,
                    e1);
        }
        throw new BaseDaoException("exception in list authors, " + userLogin, e);
    }

    try {
        if (conn != null) {
            conn.close();
        }
    } catch (Exception e2) {
        throw new BaseDaoException("conn.close exception after completing listAuthorQuery " + userLogin, e2);
    }

    if ((myResult != null) && (!myResult.isEmpty())) {
        treeCache.put(fqn, directoryId, myResult);
    }
    logger.info("myResult = " + myResult.toString());
    return myResult;
}

From source file:amie.keys.CSAKey.java

public void discoverConditionalKeysForCondition(Graph newGraph, Graph graph, HashSet<Node> candidateKeys,
        Rule conditionRule, Set<Rule> output) {
    HashSet<Node> newCandidateKeys = new HashSet<>();
    for (Node candidateKey : candidateKeys) {
        //  System.out.println("candidateKey:" + candidateKey);
        if (candidateKey.toExplore) {
            //   System.out.println("candidate:" + candidateKey);
            // if (candidateKey.toExplore) {
            List<String> properties = candidateKey.mapToString(id2Property);
            Rule amieRule = buildAMIERule(properties, conditionRule);
            //    System.out.println("rule:" + amieRule);
            boolean isConditionalKey = isConditionaKey(amieRule);
            //System.out.println("isConditionalKey:"+isConditionalKey +  " Thread " + Thread.currentThread().getId() + "\t" + Utilities.formatKey(amieRule));

            if (amieRule.getSupport() >= support && !isConditionalKey) {
                //System.out.println("Case 0" +  " Thread " + Thread.currentThread().getId());
                if (!newGraph.graph.containsKey(candidateKey)) {
                    //System.out.println("Case 1" +  " Thread " + Thread.currentThread().getId());
                    Node newCandidateKey = candidateKey.clone();
                    HashSet<Node> children = new HashSet<>();
                    newGraph.graph.put(newCandidateKey, children);
                    newGraph.nodes.put(newCandidateKey, newCandidateKey);
                    newCandidateKeys.add(newCandidateKey);
                } else {
                    //System.out.println("Case 2" +  " Thread " + Thread.currentThread().getId());                       
                    HashSet<Node> children = new HashSet<>();
                    newGraph.graph.put(candidateKey, children);
                    newCandidateKeys.add(candidateKey);
                }//  w  w w  .  java2s  .  c o m
            }

            // If the rule is a conditional above the support
            // and there is no a simpler key already discovered
            // then output it
            if (isConditionalKey && amieRule.getSupport() >= support
                    && !isSubsumedByKey(amieRule, conditionRule, conditions2Keys)) {
                //        System.out.println("KEY");
                if (!newGraph.graph.containsKey(candidateKey)) {
                    //       System.out.println("clone");
                    Node newCandidateKey = candidateKey.clone();
                    synchronized (output) {
                        output.add(amieRule);
                    }
                    //System.out.println(Utilities.formatKey(amieRule) + "\tThread " + Thread.currentThread().getId() + " Case 3");
                    System.out.println(Utilities.formatKey(amieRule));
                    conditions2Keys.put(conditionRule, amieRule);
                    newCandidateKey.toExplore = false;
                    HashSet<Node> children = new HashSet<>();
                    newGraph.graph.put(newCandidateKey, children);
                    newGraph.nodes.put(newCandidateKey, newCandidateKey);
                    newCandidateKeys.add(newCandidateKey);
                } else {
                    synchronized (output) {
                        output.add(amieRule);
                    }
                    System.out.println(Utilities.formatKey(amieRule));
                    //System.out.println(Utilities.formatKey(amieRule) + "\tThread " + Thread.currentThread().getId() + " Case 4");
                    conditions2Keys.put(conditionRule, amieRule);
                    candidateKey.toExplore = false;
                    HashSet<Node> children = new HashSet<>();
                    newGraph.graph.put(candidateKey, children);
                    newGraph.nodes.put(candidateKey, candidateKey);
                    newCandidateKeys.add(candidateKey);
                }
            }
        } else {
            //System.out.println("Case 5");
            newCandidateKeys.add(candidateKey);
        }
    }

    // createChildren
    HashSet<Node> allChildren = new HashSet<>();
    // System.out.println("newCandidateKeys:"+newCandidateKeys);
    for (Node parent1 : newCandidateKeys) {
        //    System.out.println("parent1:"+parent1);
        for (Node parent2 : newCandidateKeys) {
            if (parent1 != parent2 && parent1.toExplore != false && parent2.toExplore != false) {
                HashSet<Integer> newSet = new HashSet<>();
                newSet.addAll(parent1.set);
                newSet.addAll(parent2.set);
                HashSet<Integer> condProp_KeyProp = new HashSet<>();
                condProp_KeyProp.addAll(newSet);
                condProp_KeyProp.addAll(getRelations(conditionRule, property2Id));
                //     System.out.println("newSet:" + newSet);
                if ((newSet.size() == parent1.set.size() + 1)
                        && (getSupport(newSet, conditionRule, (int) support))
                        && Graph.containsASuperSetOf(nonKeysInt, condProp_KeyProp) != -1) {
                    //      System.out.println("enters");
                    Node child = new Node(newSet);
                    if (hasFalseParent(newSet, newCandidateKeys)) {
                        //         System.out.println("falseParent");
                        child.toExplore = false;
                    }
                    HashSet<Node> children1 = newGraph.graph.get(parent1);
                    children1.add(child);
                    newGraph.graph.put(parent1, children1);
                    newGraph.nodes.put(child, child);
                    HashSet<Node> grandChildren = new HashSet<>();
                    newGraph.graph.put(child, grandChildren);
                    HashSet<Node> children2 = newGraph.graph.get(parent2);
                    children2.add(child);
                    newGraph.graph.put(parent2, children2);
                    allChildren.add(child);
                }
            }
        }
    }

    if (!allChildren.isEmpty()) {
        discoverConditionalKeysForCondition(newGraph, newGraph, allChildren, conditionRule, output);
    }
}