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:org.apache.ambari.server.stack.StackManagerTest.java

@Test
public void testServiceDeletion() {
    StackInfo stack = stackManager.getStack("HDP", "2.0.6");
    Collection<ServiceInfo> allServices = stack.getServices();

    assertEquals(11, allServices.size());
    HashSet<String> expectedServices = new HashSet<String>();
    expectedServices.add("GANGLIA");
    expectedServices.add("HBASE");
    expectedServices.add("HCATALOG");
    expectedServices.add("HDFS");
    expectedServices.add("HIVE");
    expectedServices.add("MAPREDUCE2");
    expectedServices.add("OOZIE");
    expectedServices.add("PIG");
    expectedServices.add("ZOOKEEPER");
    expectedServices.add("FLUME");
    expectedServices.add("YARN");

    for (ServiceInfo service : allServices) {
        assertTrue(expectedServices.remove(service.getName()));
    }/* ww  w.ja v  a  2 s  . c  o  m*/
    assertTrue(expectedServices.isEmpty());
}

From source file:org.apache.zeppelin.rest.NotebookRestApi.java

/**
 * set note authorization information/*from  w w  w .  jav  a2 s  .  co m*/
 */
@PUT
@Path("{noteId}/permissions")
@ZeppelinApi
public Response putNotePermissions(@PathParam("noteId") String noteId, String req) throws IOException {
    String principal = SecurityUtils.getPrincipal();
    HashSet<String> roles = SecurityUtils.getRoles();
    HashSet<String> userAndRoles = new HashSet<>();
    userAndRoles.add(principal);
    userAndRoles.addAll(roles);

    checkIfUserIsAnon(getBlockNotAuthenticatedUserErrorMsg());
    checkIfUserIsOwner(noteId, ownerPermissionError(userAndRoles, notebookAuthorization.getOwners(noteId)));

    HashMap<String, HashSet<String>> permMap = gson.fromJson(req,
            new TypeToken<HashMap<String, HashSet<String>>>() {
            }.getType());
    Note note = notebook.getNote(noteId);

    LOG.info("Set permissions {} {} {} {} {}", noteId, principal, permMap.get("owners"), permMap.get("readers"),
            permMap.get("writers"));

    HashSet<String> readers = permMap.get("readers");
    HashSet<String> owners = permMap.get("owners");
    HashSet<String> writers = permMap.get("writers");
    // Set readers, if writers and owners is empty -> set to user requesting the change
    if (readers != null && !readers.isEmpty()) {
        if (writers.isEmpty()) {
            writers = Sets.newHashSet(SecurityUtils.getPrincipal());
        }
        if (owners.isEmpty()) {
            owners = Sets.newHashSet(SecurityUtils.getPrincipal());
        }
    }
    // Set writers, if owners is empty -> set to user requesting the change
    if (writers != null && !writers.isEmpty()) {
        if (owners.isEmpty()) {
            owners = Sets.newHashSet(SecurityUtils.getPrincipal());
        }
    }

    notebookAuthorization.setReaders(noteId, readers);
    notebookAuthorization.setWriters(noteId, writers);
    notebookAuthorization.setOwners(noteId, owners);
    LOG.debug("After set permissions {} {} {}", notebookAuthorization.getOwners(noteId),
            notebookAuthorization.getReaders(noteId), notebookAuthorization.getWriters(noteId));
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    note.persist(subject);
    notebookServer.broadcastNote(note);
    notebookServer.broadcastNoteList(subject, userAndRoles);
    return new JsonResponse<>(Status.OK).build();
}

From source file:gr.demokritos.iit.cru.creativity.reasoning.diagrammatic.DiagrammaticComputationalTools.java

public HashSet<String> FindConcepts(String concept, int difficulty, String category)
        throws InstantiationException, IllegalAccessException, SQLException, ClassNotFoundException, Exception {
    HashSet<String> concepts = new HashSet<String>();
    HashSet<String> TempConcepts = new HashSet<String>();

    ///---------translate
    concept = Translator.bingTranslate(concept, this.language, "en", "general");
    if (wn.getCommonPos(concept) == null) { ////new addition if the word cannot be translated to english
        return concepts;
    }/*from  w  ww .  ja  va2s .  c o m*/

    if (category.equalsIgnoreCase("equivalence")) {
        //to be done
    } else if (category.equalsIgnoreCase("subsumption")) {
        for (int i = 0; i < difficulty; i++) {//for the given dificculty, abstract as many times
            TempConcepts = ConceptGraphPolymerismEngine(concept); //polymerism doesn't return many
            if (TempConcepts.isEmpty()) {
                break;
            }
            concepts = TempConcepts;//define the temporary conecpts as new conecpts in case the next concepts are empty
            //take one concept at random from the abstraction, and make it the new concept
            int pointer = new Random().nextInt(concepts.size());
            int c = 0;
            for (String k : concepts) {
                if (c == pointer) {
                    concept = k;
                }
                c = c + 1;
            }
        }
    } else if (category.equalsIgnoreCase("supersumption")) {
        for (int i = 0; i < difficulty; i++) {
            TempConcepts = ConceptGraphAbstractionEngine(concept);
            if (TempConcepts.isEmpty()) {
                break;
            }
            concepts = TempConcepts;//define the temporary concepts as new conecpts in case the next concepts are empty
            //take one concept at random from the abstraction, and make it the new concept
            int pointer = new Random().nextInt(concepts.size());
            int c = 0;
            for (String k : concepts) {
                if (c == pointer) {
                    concept = k;
                }
                c = c + 1;
            }
        }
    } else {
        String type = "subject";
        //take alternatively the object of the subject and the subject of the object until diff is reached
        for (int i = 0; i < difficulty; i++) {
            TempConcepts = FactRetriever(concept, type);
            if (TempConcepts.isEmpty()) {
                break;
            }
            concepts = TempConcepts;
            int pointer = new Random().nextInt(concepts.size());
            int c = 0;
            for (String k : concepts) {
                if (c == pointer) {
                    if (type.equalsIgnoreCase("subject")) {
                        if (!k.split("---")[1].isEmpty()) {
                            concept = k.split("---")[1];//take the object
                            type = "object";
                        }
                    } else {
                        if (!k.split("---")[0].isEmpty()) {
                            concept = k.split("---")[0];//take the subject
                            type = "subject";
                        }
                    }
                }
                c = c + 1;
            }
        }
    }
    HashSet<String> finCon = new HashSet<String>();

    ///---------translate
    if (!this.language.equalsIgnoreCase("en")) {
        for (String s : concepts) {
            String n = Translator.bingTranslate(s, "en", this.language, "general");
            if (wn.getCommonPos(n) == null) {//if the word is not english
                finCon.add(n);
            }
        }
    } else {
        finCon.addAll(concepts);
    }
    return finCon;
}

From source file:it.iit.genomics.cru.igb.bundles.mi.business.MIResult.java

public float getScore() {

    if (score > -1) {
        return score;
    }/*w  ww  .  ja  va 2s.  co m*/

    HashSet<AAPosition> residuesOnProteins = new HashSet<>();
    HashSet<AAPosition> residuesOnContacts = new HashSet<>();

    residuesOnProteins.addAll(queryResiduesA);
    residuesOnProteins.addAll(queryResiduesB);

    residuesOnContacts.addAll(structureMapper.getInterfaceAAPositionsA());
    residuesOnContacts.addAll(structureMapper.getInterfaceAAPositionsB());

    if (residuesOnProteins.isEmpty()) {
        return 0;
    }

    float residueScore = ((float) residuesOnContacts.size()) / residuesOnProteins.size();

    this.score = residueScore;

    return residueScore;
}

From source file:ubic.gemma.ontology.GoMetric.java

/**
 * Tailored to handle computing overlap between two gene lists which may contain duplicate genes of the same name
 * but different IDs. If gene lists do not contain duplicates (size = 1) the result will be the same as that of
 * computing simple overlap./*  ww  w  . j a  v  a 2s.  c om*/
 * 
 * @param sameGenes1
 * @param sameGenes2
 * @param geneGoMap
 * @param goAspect if non-null, limit overlap to only terms in the given aspect.
 * @return number of overlapping terms between merged sets of GO terms for duplicate gene lists
 */
public Double computeMergedOverlap(List<Gene> sameGenes1, List<Gene> sameGenes2,
        Map<Long, Collection<String>> geneGoMap, GOAspect goAspect) {
    HashSet<String> mergedGoTerms1 = new HashSet<String>();
    HashSet<String> mergedGoTerms2 = new HashSet<String>();

    for (Gene gene1 : sameGenes1) {
        if (geneGoMap.containsKey(gene1.getId())) {
            mergedGoTerms1.addAll(geneGoMap.get(gene1.getId()));
        }
    }
    for (Gene gene2 : sameGenes2) {
        if (geneGoMap.containsKey(gene2.getId())) {
            mergedGoTerms2.addAll(geneGoMap.get(gene2.getId()));
        }
    }

    if (mergedGoTerms1.isEmpty() || mergedGoTerms2.isEmpty())
        return 0.0;

    double score = 0.0;

    for (String goTerm1 : mergedGoTerms1) {

        /*
         * aspect filtering.
         */
        if (goAspect != null) {
            if (GeneOntologyServiceImpl.getTermAspect(goTerm1).equals(goAspect)) {
                continue;
            }
        }

        if (goTerm1.equalsIgnoreCase(process) || goTerm1.equalsIgnoreCase(function)
                || goTerm1.equalsIgnoreCase(component))
            continue;
        for (String goTerm2 : mergedGoTerms2) {

            if (goAspect != null) {
                if (GeneOntologyServiceImpl.getTermAspect(goTerm2).equals(goAspect)) {
                    continue;
                }
            }

            if (goTerm2.equalsIgnoreCase(process) || goTerm2.equalsIgnoreCase(function)
                    || goTerm2.equalsIgnoreCase(component))
                continue;

            if (goTerm1.equalsIgnoreCase(goTerm2))
                score++;
        }
    }

    return score;
}

From source file:org.apache.hadoop.hdfs.server.namenode.ha.TestRetryCacheWithHA.java

@SuppressWarnings("unchecked")
private void listCachePools(HashSet<String> poolNames, int active) throws Exception {
    HashSet<String> tmpNames = (HashSet<String>) poolNames.clone();
    RemoteIterator<CachePoolEntry> pools = dfs.listCachePools();
    int poolCount = poolNames.size();
    for (int i = 0; i < poolCount; i++) {
        CachePoolEntry pool = pools.next();
        String pollName = pool.getInfo().getPoolName();
        assertTrue("The pool name should be expected", tmpNames.remove(pollName));
        if (i % 2 == 0) {
            int standby = active;
            active = (standby == 0) ? 1 : 0;
            cluster.shutdownNameNode(standby);
            cluster.waitActive(active);//  w w w .j a v a  2 s .  c om
            cluster.restartNameNode(standby, false);
        }
    }
    assertTrue("All pools must be found", tmpNames.isEmpty());
}

From source file:com.milaboratory.core.tree.SequenceTreeMapTest.java

@Test
public void testRandomizedTest3() throws Exception {
    for (int f = 0; f < repeats * 6; ++f) {
        //System.out.println(f);
        Alphabet alphabet = getAlphabetSequence(f);

        for (byte t = 0; t < 3; ++t) {
            final Sequence seqRight = randomSequence(alphabet, 50, 100),
                    seqLeft = randomSequence(alphabet, 50, 100), spacer = randomSequence(alphabet, 200, 200),
                    goodSequence = concatenate(seqLeft, spacer, seqRight);

            SequenceTreeMap map = new SequenceTreeMap(alphabet);

            int[] mut = new int[3];
            mut[t] = 3;//from  w  w  w.  jav  a  2 s  .  c  o  m

            HashSet<Sequence> lErr = new HashSet<>(), rErr = new HashSet<>(), lrErr = new HashSet<>();

            Sequence seq1, seq2, mseq;

            for (int i = 0; i < 100; ++i) {
                //Left Error
                seq1 = introduceErrors(seqLeft, mut);
                mseq = concatenate(seq1, spacer, seqRight);
                lErr.add(mseq);
                map.put(mseq, mseq);

                //Right Error
                seq1 = introduceErrors(seqRight, mut);
                mseq = concatenate(seqLeft, spacer, seq1);
                rErr.add(mseq);
                map.put(mseq, mseq);

                //LR Error
                seq1 = introduceErrors(seqLeft, mut);
                seq2 = introduceErrors(seqRight, mut);
                mseq = concatenate(seq1, spacer, seq2);
                lrErr.add(mseq);
                map.put(mseq, mseq);
            }

            SequenceTreeMap.Node<Sequence> n;

            //Left run
            NeighborhoodIterator neighborhoodIterator = map.getNeighborhoodIterator(goodSequence, 1.3,
                    new double[] { 0.1, 0.1, 0.1 }, mut, new MutationGuide() {
                        @Override
                        public boolean allowMutation(Sequence ref, int position, byte type, byte code) {
                            return position < seqLeft.size() + 100;
                        }
                    });

            HashSet<Sequence> acc = new HashSet<>(lErr);

            while ((n = neighborhoodIterator.nextNode()) != null) {
                assertTrue(lErr.contains(n.object));
                assertFalse(rErr.contains(n.object));
                assertFalse(lrErr.contains(n.object));
                acc.remove(n.object);
            }
            assertTrue(acc.isEmpty());

            //Right run
            neighborhoodIterator = map.getNeighborhoodIterator(goodSequence, 1.3,
                    new double[] { 0.1, 0.1, 0.1 }, mut, new MutationGuide() {
                        @Override
                        public boolean allowMutation(Sequence ref, int position, byte type, byte code) {
                            return position > seqLeft.size() + 100;
                        }
                    });

            acc = new HashSet<>(rErr);

            while ((n = neighborhoodIterator.nextNode()) != null) {
                assertTrue(rErr.contains(n.object));
                assertFalse(lErr.contains(n.object));
                assertFalse(lrErr.contains(n.object));
                acc.remove(n.object);
            }
            assertTrue(acc.isEmpty());
        }
    }
}

From source file:uk.ac.edukapp.service.WidgetProfileService.java

/**
 * //from www . j  a  va  2s.  co  m
 * @param categories
 * @return
 */
public SearchResults returnWidgetProfilesFilteredByCategories(List<List<Category>> categories) {
    ArrayList<Widgetprofile> widgetList = new ArrayList<Widgetprofile>();

    for (List<Category> group : categories) {
        HashSet<Widgetprofile> groupList = new HashSet<Widgetprofile>();
        for (Category category : group) {
            List<Widgetprofile> widgets = category.getWidgetprofiles();
            if (widgets != null) {
                groupList.addAll(widgets);
            }

        }
        if (widgetList.isEmpty()) {
            widgetList.addAll(groupList);
        } else {
            if (!groupList.isEmpty()) {
                widgetList.retainAll(groupList);
            }
        }
    }
    SearchResults sr = new SearchResults();
    sr.setWidgets(widgetList);
    sr.setNumber_of_results(widgetList.size());
    return sr;
}

From source file:org.apache.hadoop.hdfs.server.namenode.ha.TestRetryCacheWithHA.java

@SuppressWarnings("unchecked")
private void listCacheDirectives(HashSet<String> poolNames, int active) throws Exception {
    HashSet<String> tmpNames = (HashSet<String>) poolNames.clone();
    RemoteIterator<CacheDirectiveEntry> directives = dfs.listCacheDirectives(null);
    int poolCount = poolNames.size();
    for (int i = 0; i < poolCount; i++) {
        CacheDirectiveEntry directive = directives.next();
        String pollName = directive.getInfo().getPool();
        assertTrue("The pool name should be expected", tmpNames.remove(pollName));
        if (i % 2 == 0) {
            int standby = active;
            active = (standby == 0) ? 1 : 0;
            cluster.shutdownNameNode(standby);
            cluster.waitActive(active);/*from  ww  w. j av a2  s  . c  om*/
            cluster.restartNameNode(standby, false);
        }
    }
    assertTrue("All pools must be found", tmpNames.isEmpty());
}

From source file:io.hops.hopsworks.api.zeppelin.rest.NotebookRestApi.java

/**
 * set note authorization information/*from w ww  .ja v a2 s . c  om*/
 */
@PUT
@Path("{noteId}/permissions")
public Response putNotePermissions(@PathParam("noteId") String noteId, String req) throws IOException {
    String principal = SecurityUtils.getPrincipal();
    HashSet<String> roles = SecurityUtils.getRoles();
    HashSet<String> userAndRoles = new HashSet<>();
    userAndRoles.add(principal);
    userAndRoles.addAll(roles);

    checkIfUserIsAnon(getBlockNotAuthenticatedUserErrorMsg());
    checkIfUserIsOwner(noteId, ownerPermissionError(userAndRoles, notebookAuthorization.getOwners(noteId)));

    HashMap<String, HashSet<String>> permMap = gson.fromJson(req,
            new TypeToken<HashMap<String, HashSet<String>>>() {
            }.getType());
    Note note = notebook.getNote(noteId);

    LOG.info("Set permissions {} {} {} {} {}", noteId, principal, permMap.get("owners"), permMap.get("readers"),
            permMap.get("writers"));

    HashSet<String> readers = permMap.get("readers");
    HashSet<String> owners = permMap.get("owners");
    HashSet<String> writers = permMap.get("writers");
    // Set readers, if writers and owners is empty -> set to user requesting the change
    if (readers != null && !readers.isEmpty()) {
        if (owners.isEmpty()) {
            owners = Sets.newHashSet(SecurityUtils.getPrincipal());
        }
    }
    // Set writers, if owners is empty -> set to user requesting the change
    if (writers != null && !writers.isEmpty()) {
        if (owners.isEmpty()) {
            owners = Sets.newHashSet(SecurityUtils.getPrincipal());
        }
    }

    notebookAuthorization.setReaders(noteId, readers);
    notebookAuthorization.setWriters(noteId, writers);
    notebookAuthorization.setOwners(noteId, owners);
    LOG.debug("After set permissions {} {} {}", notebookAuthorization.getOwners(noteId),
            notebookAuthorization.getReaders(noteId), notebookAuthorization.getWriters(noteId));
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    note.persist(subject);
    notebookServer.broadcastNote(note);
    notebookServer.broadcastNoteList(subject, userAndRoles);
    return new JsonResponse<>(Status.OK).build();
}