Example usage for java.util HashSet iterator

List of usage examples for java.util HashSet iterator

Introduction

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

Prototype

public Iterator<E> iterator() 

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:org.intermine.bio.dataconversion.XenmineConverter.java

/**
 * //from   www .j a  va  2 s  .  c  o m
 * @param reader
 * @throws Exception
 * @throws ObjectStoreException
 */
private void processInteractionsFile(Reader preader) throws Exception, ObjectStoreException {

    /* Xenbase gene ID      
     * gene symbol     
     *  interactant ID:interactant symbol:co-citation occurrence
     */
    System.out.println("Processing Interactants file....");

    Iterator<?> tsvIter;
    try {
        tsvIter = FormattedTextParser.parseTabDelimitedReader(preader);
    } catch (Exception e) {
        throw new Exception("cannot parse file: " + preader.toString(), e);
    }

    while (tsvIter.hasNext()) {

        String[] line = (String[]) tsvIter.next();

        if (line.length < 3) {
            LOG.error("Couldn't process line. Expected 3 cols, but was " + line.length);
            continue;
        }

        String genePageId = line[0].trim().substring(12);
        String symbol = line[1].trim();
        String interactants = line[2].trim(); //genePageId-PMID:symbol:someNumber   

        if (interactants == null || interactants.length() == 0 || interactants.equals("")) {
            continue;
        }
        String[] interactingGenes = interactants.split(",");

        //System.out.println("Gene Page.."+ genePageId + "  Length of inG.." + interactingGenes.length);

        HashSet geneIds = genesPageName.get(genePageId);
        Iterator it = geneIds.iterator();

        while (it.hasNext()) {

            String geneId = (String) it.next();
            Item gene = genes.get(geneId);

            if (interactingGenes.length != 0) {

                for (int i = 0; i < interactingGenes.length; i++) {

                    String gpid[] = interactingGenes[i].split("\\:");
                    String genePageIdInteractant = gpid[0];

                    //System.out.println("gene interactant.." + genePageIdInteractant);

                    HashSet interactingGeneIds = genesPageName.get(genePageIdInteractant);
                    if (interactingGeneIds == null) {
                        continue;
                    }
                    Iterator itt = interactingGeneIds.iterator();

                    while (itt.hasNext()) {

                        String interactingGeneId = (String) itt.next();
                        Item interactingGene = genes.get(interactingGeneId);

                        if (gene != null && interactingGene != null) {
                            getInteraction(gene.getIdentifier(), interactingGene.getIdentifier());
                        }
                    }

                }

            }
        }

    }

    preader.close();

}

From source file:org.intermine.bio.dataconversion.XenmineConverter.java

/**
 * /*from   ww  w .  ja va 2  s  .  c o  m*/
 * @param reader
 * @throws Exception
 * @throws ObjectStoreException
 */
private void processNonEntrezOrthologFile(Reader preader) throws Exception, ObjectStoreException {

    /* Xenbase 
     * OMIM    
     * MGI     
     * ZFIN
     */
    System.out.println("Processing  Non Entrze Orthologs.. XenbaseGeneNonEntrezOrthologMapping.txt file....");

    Iterator<?> tsvIter;
    try {
        tsvIter = FormattedTextParser.parseTabDelimitedReader(preader);
    } catch (Exception e) {
        throw new Exception("cannot parse file: " + preader.toString(), e);
    }

    String prevXenopusId = "";

    while (tsvIter.hasNext()) {

        String[] line = (String[]) tsvIter.next();

        if (line.length < 4) {
            LOG.error("Couldn't process line. Expected 4 cols, but was " + line.length);
            continue;
        }
        System.out.println(line[0].trim());

        String xenopusId = line[0].trim().substring(8); //it doesn;t say GENEPAGE!!
        String omimId = line[1].trim();
        String mgiId = line[2].trim();
        String zfinId = line[3].trim();
        String chickenId = line[4].trim();

        if (prevXenopusId == xenopusId) {

            HashSet geneIds = genesPageName.get(xenopusId);
            Iterator it = geneIds.iterator();

            while (it.hasNext()) {

                String geneId = (String) it.next();
                Item gene0 = genes.get(geneId);
                if (gene0 != null) {

                    if (!StringUtils.isEmpty(zfinId)) {
                        String gene3 = getGene(zfinId, "7955");
                        if (gene3 != null)
                            processHomologues(gene0.getIdentifier(), gene3);
                    }

                }

            }

        } else {

            HashSet geneIds = genesPageName.get(xenopusId);
            Iterator it = geneIds.iterator();

            while (it.hasNext()) {

                String geneId = (String) it.next();
                Item gene0 = genes.get(geneId);
                if (gene0 != null) {

                    if (!StringUtils.isEmpty(omimId)) {
                        String gene1 = getGene(omimId, "9606");
                        if (gene1 != null)
                            processHomologues(gene0.getIdentifier(), gene1);
                    }

                    if (!StringUtils.isEmpty(mgiId)) {
                        String gene2 = getGene(mgiId, "10090");
                        if (gene2 != null)
                            processHomologues(gene0.getIdentifier(), gene2);
                    }

                    if (!StringUtils.isEmpty(zfinId)) {
                        String gene3 = getGene(zfinId, "7955");
                        if (gene3 != null)
                            processHomologues(gene0.getIdentifier(), gene3);
                    }
                    if (!StringUtils.isEmpty(chickenId)) {
                        String gene4 = getGene(chickenId, "9031");
                        if (gene4 != null)
                            processHomologues(gene0.getIdentifier(), gene4);
                    }

                }

            }
        }

        prevXenopusId = xenopusId;

    }

    preader.close();

}

From source file:org.unitime.timetable.model.Solution.java

public void removeDivSecNumbers(org.hibernate.Session hibSession) {
    HashSet classes = new HashSet();
    for (Iterator i = getAssignments().iterator(); i.hasNext();) {
        Assignment assignment = (Assignment) i.next();
        Class_ clazz = assignment.getClazz();
        if (clazz == null || clazz.getClassSuffix() == null)
            continue;
        classes.add(clazz);//from w  w w .ja  va2 s .c  om
    }

    HashSet subparts2fix = new HashSet();

    for (Iterator i = classes.iterator(); i.hasNext();) {
        Class_ clazz = (Class_) i.next();

        clazz.setClassSuffix(null);

        subparts2fix.add(clazz.getSchedulingSubpart());

        hibSession.update(clazz);
    }

    List otherClasses = new SolutionDAO().getSession()
            .createQuery("select distinct c from Class_ c, Solution s inner join s.owner.departments d "
                    + "where s.uniqueId = :solutionId and c.managingDept=d and "
                    + "c.uniqueId not in (select a.clazz.uniqueId from s.assignments a)")
            .setLong("solutionId", getUniqueId().longValue()).list();
    for (Iterator i = otherClasses.iterator(); i.hasNext();) {
        Class_ clazz = (Class_) i.next();
        if (clazz.getClassSuffix() == null)
            continue;
        clazz.setClassSuffix(null);

        subparts2fix.add(clazz.getSchedulingSubpart());

        hibSession.update(clazz);
    }

    for (Iterator i = subparts2fix.iterator(); i.hasNext();) {
        SchedulingSubpart subpart = (SchedulingSubpart) i.next();

        TreeSet takenDivNums = new TreeSet(takenDivisionNumbers(subpart));
        int dec = 0, lastDiv = 0;

        for (Iterator j = takenDivNums.iterator(); j.hasNext();) {
            int div = ((Integer) j.next()).intValue();
            dec += (div - lastDiv - 1);
            lastDiv = div;
            if (dec > 0) {
                sLog.debug(subpart.getSchedulingSubpartLabel() + ": " + div + "->" + (div - dec));
                InstructionalOffering offering = subpart.getInstrOfferingConfig().getInstructionalOffering();
                ItypeDesc itype = subpart.getItype();
                for (Iterator i1 = offering.getInstrOfferingConfigs().iterator(); i1.hasNext();) {
                    InstrOfferingConfig cfg = (InstrOfferingConfig) i1.next();
                    for (Iterator i2 = cfg.getSchedulingSubparts().iterator(); i2.hasNext();) {
                        SchedulingSubpart s = (SchedulingSubpart) i2.next();
                        if (!s.getItype().equals(itype))
                            continue;
                        for (Iterator i3 = s.getClasses().iterator(); i3.hasNext();) {
                            Class_ clazz = (Class_) i3.next();
                            if (clazz.getClassSuffix() == null || clazz.getClassSuffix().length() != 6)
                                continue;
                            int clazzDivNum = Integer.parseInt(clazz.getClassSuffix().substring(0, 3));
                            int clazzSecNum = Integer.parseInt(clazz.getClassSuffix().substring(3, 6));
                            if (clazzDivNum == div) {
                                clazz.setClassSuffix(sSufixFormat.format(clazzDivNum - dec)
                                        + sSufixFormat.format(clazzSecNum));
                                hibSession.update(clazz);
                            }
                        }
                    }
                }

            }
        }
    }
}

From source file:org.intermine.bio.dataconversion.XenmineConverter.java

/**
 * /*from ww  w. j  av  a 2s  .com*/
 * @param reader
 * @throws Exception
 * @throws ObjectStoreException
 */

private void processAnatomyMappingFile(Reader preader) throws Exception, ObjectStoreException {

    /* Xenbase Gene ID
     * gene symbol
     * start stage
     * end stage
     * tissues
     * XB-GENEPAGE-478053      trnt1   XAO:1000031 NF stage 10.5       XAO:1000009 frog       
     *  XAO:0000001 ectoderm,XAO:0003024 head,XAO:0000129 intestine,XAO:0000133 liver,XAO:0000256 oocyte,
     *  XAO:0000258 ovary,XAO:0000157 testis,XAO:0003004 whole organism
     */

    System.out.println("Processing Anatomy Mapping file....");

    Iterator<?> tsvIter;
    try {
        tsvIter = FormattedTextParser.parseTabDelimitedReader(preader);
    } catch (Exception e) {
        throw new Exception("cannot parse file: " + preader.toString(), e); //getCurrentFile()
    }

    while (tsvIter.hasNext()) {

        String[] line = (String[]) tsvIter.next();

        String xenbaseGeneId = line[0].trim().substring(12);
        String symbol = line[1].trim();
        String startStageFull = line[2].trim(); //XAO:1000049 NF stage 35 and 36
        String[] t = startStageFull.split("\\s");
        String startStage = t[0];
        String endStageFull = line[3].trim();
        String[] te = endStageFull.split("\\s");
        String endStage = te[0];
        String anatomicalTissue = line[4].trim();
        System.out.println(xenbaseGeneId);
        HashSet geneIds = genesPageName.get(xenbaseGeneId); //check this stuff with what is in genes..a thorough once over
        Iterator it = geneIds.iterator();
        while (it.hasNext()) {

            String geneId = (String) it.next();
            Item gene = genes.get(geneId);
            if (gene != null) {
                //figure out how to store this stuff
                Item anatomy = createItem("AnatomyMapping");
                Item sterm = getTerm(startStage);
                Item eterm = getTerm(endStage);
                anatomy.setReference("startStage", sterm.getIdentifier());
                anatomy.setReference("endStage", eterm.getIdentifier());
                setAnatomicalTissues(anatomy, anatomicalTissue, "tissues");
                anatomy.setReference("gene", gene.getIdentifier());
                store(anatomy); //don't store all other items created if there is no gene to associate with..?
            }
        }

    }

    preader.close();

}

From source file:org.intermine.bio.dataconversion.XenmineConverter.java

/**
 * /*  w  w  w  .j  a  v a  2  s . co  m*/
 * @param reader
 * @throws Exception
 * @throws ObjectStoreException
 */

private void processLiteratureFile(Reader preader) throws Exception, ObjectStoreException {

    /* Xenbase Literature ID      
     * PMID     
     *  Xenbase genePage IDs associated with the PMID above
     */

    System.out.println("Processing Literature file....");

    Iterator<?> tsvIter;
    try {
        tsvIter = FormattedTextParser.parseTabDelimitedReader(preader);
    } catch (Exception e) {
        throw new Exception("cannot parse file: " + preader.toString(), e); //getCurrentFile()
    }

    while (tsvIter.hasNext()) {

        String[] line = (String[]) tsvIter.next();

        if (line.length < 3) {
            LOG.error("Couldn't process line. Expected 3 cols, but was " + line.length);
            continue;
        }

        String literatureId = line[0].trim().substring(7);
        String pmid = line[1].trim();
        String litGenes = line[2].trim(); //XB-GENEPAGE-491748 elavl2,XB-GENEPAGE-481418 gdf1,XB-GENEPAGE-481799 elavl1      

        if (litGenes.isEmpty() || litGenes == null) {
            System.out.println("empty 3rd column.");
            continue;

        }

        String storedRefId = getPub(pmid, literatureId);

        String[] gids = litGenes.split(",");

        if (gids.length != 0) {
            for (int i = 0; i < gids.length; i++) {

                String gpid[] = gids[i].split("\\s");
                String genePageId = gpid[0].substring(12);

                HashSet geneIds = genesPageName.get(genePageId); //check this stuff with what is in genes..a thorough once over
                Iterator it = geneIds.iterator();
                while (it.hasNext()) {

                    String geneId = (String) it.next();
                    Item gene = genes.get(geneId);
                    if (gene != null) {
                        gene.addToCollection("publications", storedRefId);
                    }
                }

            }
        } else {

            String gpid[] = litGenes.split("\\s");
            String genePageId = gpid[0].substring(12);
            HashSet geneIds = genesPageName.get(genePageId); //check this stuff with what is in genes..a thorough once over
            Iterator it = geneIds.iterator();
            while (it.hasNext()) {

                String geneId = (String) it.next();
                Item gene = genes.get(geneId);
                if (gene != null) {
                    gene.addToCollection("publications", storedRefId);
                }
            }
        }

    }

    preader.close();

}

From source file:services.SimulationService.java

public boolean remove(SWGObject object, float x, float z, boolean notifyObservers) {
    if (object == null || !object.isInQuadtree()) {
        return false;
    }//from   ww  w .j a va2 s. c o  m

    boolean success = quadTrees.get(object.getPlanet().getName()).remove(x, z, object);
    object.setIsInQuadtree(success);
    if (success && notifyObservers) {
        HashSet<Client> oldObservers = new HashSet<Client>(object.getObservers());
        for (Iterator<Client> it = oldObservers.iterator(); it.hasNext();) {
            Client observerClient = it.next();
            if (observerClient.getParent() != null) {
                observerClient.getParent().makeUnaware(object);

                // Experimental until engine fixed
                if (observerClient.getParent().getAwareObjects().contains(object)) {

                    object.viewChildren(observerClient.getParent(), false, false, new Traverser() {
                        @Override
                        public void process(SWGObject object) {
                            if (object == null)
                                return;
                            if (object.getClient() != null)
                                object.makeUnaware(observerClient.getParent());
                            observerClient.getParent().makeUnaware(object);
                        }
                    });
                    if (!object.isInSnapshot())
                        object.sendDestroy(observerClient);
                    object.removeObserver(observerClient.getParent());
                    observerClient.getParent().getAwareObjects().remove(object);
                }
                // Experimental until engine fixed
            }
        }
    }
    return success;
}

From source file:org.lockss.scheduler.TaskRunner.java

boolean cleanupSchedule(Scheduler scheduler, boolean doDrop) {
    if (currentSchedule == null) {
        log.debug("cleanupSchedule(): currentSchedule = null");
        return false;
    }/* w  w w  .  ja  va2 s .co  m*/
    // don't do this too often
    if (TimeBase.msSince(lastCleanup) < minCleanupInterval) {
        return false;
    }
    lastCleanup = TimeBase.nowMs();
    List unexpired = getUnexpiredTasks();
    if (scheduler.createSchedule(unexpired)) {
        // no cleanup necessary, nothing pruned
        log.debug("cleanupSchedule(): no cleanup necessary");
        return false;
    }
    HashSet remainingTasks = new HashSet(unexpired);
    HashSet dropped = new HashSet();

    for (int ix = maxDrop; ix > 0; ix--) {
        SchedulableTask droppable = findDroppableTask(dropped);
        if (droppable == null) {
            log.error("Failed to cleanup schedule: " + currentSchedule + " after dropping " + dropped);
            return false;
        }
        if (log.isDebug3())
            log.debug3("Considering dropping: " + droppable);
        remainingTasks.remove(droppable);
        dropped.add(droppable);
        if (scheduler.createSchedule(remainingTasks)) {
            log.debug3("succeeded");
            if (doDrop) {
                for (Iterator iter = dropped.iterator(); iter.hasNext();) {
                    SchedulableTask task = (SchedulableTask) iter.next();
                    log.warning("Dropped " + task);
                    task.setDropped();
                    decrStats(task, STAT_WAITING);
                    addOverrunner(task, STAT_DROPPED);
                }
            }
            return true;
        }
    }
    return false;
}

From source file:pl.edu.icm.coansys.source.ReduceDocsWithSameSourceId.java

@Override
protected void reduce(Writable key, Iterable<BytesWritable> values, Context context)
        throws IOException, InterruptedException {
    ArrayList<String> docIds = new ArrayList<String>();
    HashSet<String> issns = new HashSet<String>();
    HashSet<String> isbns = new HashSet<String>();
    HashSet<String> titles = new HashSet<String>();
    for (BytesWritable value : values) {

        DocumentProtos.DocumentWrapper docWrapper = DocumentProtos.DocumentWrapper.parseFrom(value.copyBytes());
        docIds.add(docWrapper.getRowId());
        String issn = null;// w  w w. ja  v a2  s  .  co  m
        String isbn = null;
        if (docWrapper.hasDocumentMetadata() && docWrapper.getDocumentMetadata().hasBasicMetadata()) {
            DocumentProtos.BasicMetadataOrBuilder bm = docWrapper.getDocumentMetadata()
                    .getBasicMetadataOrBuilder();
            if (bm.hasIssn()) {
                issn = bm.getIssn();
            }
            if (bm.hasIsbn()) {
                isbn = bm.getIsbn();
            }
            if (StringUtils.isNotBlank(isbn)) {
                isbn = isbn.trim().toUpperCase();
                isbns.add(isbn);
            }
            if (StringUtils.isNotBlank(issn)) {
                issn = issn.trim().toUpperCase();
                issns.add(issn);
            }
            if (bm.hasJournal()) {
                String title = bm.getJournal().trim();
                if (StringUtils.isNotBlank(title)) {
                    titles.add(title);
                }
            }
        }

    }
    String issn = null;
    String isbn = null;
    ArrayList<String> titleA = new ArrayList<String>(titles);
    Collections.sort(titleA, new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            //najdusze naprzd
            return o2.length() - o1.length();
        }

    });

    if (issns.size() > 0) {
        issn = issns.iterator().next();
    }
    if (isbns.size() > 0) {
        isbn = isbns.iterator().next();
    }
    String id = "http://comac.ceon.pl/source-";
    if (issn != null) {
        id += ("issn-" + issn);
        if (isbn != null) {
            id += "-";
        }
    }
    if (isbn != null) {
        id += ("isbn-" + isbn);
    }
    for (String docId : docIds) {
        ParentModelProtos.ParentDisambiguationOut.Builder parent = ParentModelProtos.ParentDisambiguationOut
                .newBuilder();
        parent.setDocId(docId);
        parent.setParentId(id);
        parent.addAllParentName(titles);
        if (isbn != null) {
            parent.setType(DocumentProtos.BasicMetadata.ParentType.BOOK);
        } else {
            parent.setType(DocumentProtos.BasicMetadata.ParentType.JOURNAL);
        }
        context.write(new Text(docId), new BytesWritable(parent.build().toByteArray()));
    }

}

From source file:org.intermine.bio.dataconversion.XenmineConverter.java

/**
 * //  w w w  . j  a  va 2 s  .  c  o  m
 * @param reader
 * @throws Exception
 * @throws ObjectStoreException
 */

private void processGoFile(Reader preader) throws Exception, ObjectStoreException {

    /* Xenbase genepage ID     
     * gene symbol     
     * GO Ids  (comma separated)
     */

    System.out.println("Processing GO file....");

    Iterator<?> tsvIter;
    try {
        tsvIter = FormattedTextParser.parseTabDelimitedReader(preader);
    } catch (Exception e) {
        throw new Exception("cannot parse file: " + preader.toString(), e); //getCurrentFile()
    }

    while (tsvIter.hasNext()) {

        String[] line = (String[]) tsvIter.next();

        if (line.length < 3) {
            LOG.error("Couldn't process line. Expected 3 cols, but was " + line.length);
            continue;
        }

        String genePageId = line[0].trim().substring(12);
        String symbol = line[1].trim();
        String goids = line[2].trim(); //GO:0005525,GO:0007264,GO:0015031

        HashSet geneIds = genesPageName.get(genePageId);
        if (geneIds == null) {
            System.out.println("genePageId: null for genes..");
            continue;
        }
        Iterator it = geneIds.iterator();
        while (it.hasNext()) {

            String geneId = (String) it.next();
            Item gene = genes.get(geneId);
            //System.out.println("genePageId: " + genePageId + " geneId " + geneId);
            String[] gids = goids.split(",");
            for (int i = 0; i < gids.length; i++) {
                String goTermIdentifier = gids[i];
                if (gene != null) {
                    createGoAnnotation(gene.getIdentifier(), gene, goTermIdentifier, "XenBase", "XenBase");
                }
            }

        }
    }

    preader.close();

}

From source file:org.processmining.analysis.petrinet.cpnexport.HLToCPNTranslator.java

/**
 * Gets for the given transitions all the other transitions that are
 * involved in the same choice based on frequencies.
 * /*from w w  w .  j  a va2s  .  c o  m*/
 * @param transitionsFreqDep
 *            HashSet. A hashset in which we only have one transition and
 *            for which we want to obtain all the other transitions that are
 *            involved in the same choice based on frequencies.
 */
private void getTransitionsForChoiceOnFrequencies(HashSet<ColoredTransition> transitionsFreqDep) {
    int oldSizeTransitions = transitionsFreqDep.size();
    HashSet<ColoredPlace> places = new HashSet<ColoredPlace>();
    Iterator<ColoredTransition> transitionsFreqDepIt = transitionsFreqDep.iterator();
    while (transitionsFreqDepIt.hasNext()) {
        ColoredTransition transition = transitionsFreqDepIt.next();
        places.addAll(transition.getPredecessors());
    }
    // get the outgoing transitions for each place in places
    Iterator<ColoredPlace> placesIt = places.iterator();
    while (placesIt.hasNext()) {
        ColoredPlace place = placesIt.next();
        transitionsFreqDep.addAll(place.getSuccessors());
    }

    if (transitionsFreqDep.size() > oldSizeTransitions) {
        getTransitionsForChoiceOnFrequencies(transitionsFreqDep);
    }
}