Example usage for java.util HashSet contains

List of usage examples for java.util HashSet contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:com.bmwcarit.barefoot.road.BfmapReaderTest.java

@Test
public void testBfmapReader() throws IOException, JSONException {
    {/*from  w w w  .  ja  va2s  .  c o m*/
        RoadWriter writer = new BfmapWriter(
                BfmapReaderTest.class.getResource("").getPath() + "oberbayern.bfmap.test");
        RoadReader reader = Testmap.instance().reader();
        BaseRoad road = null;

        writer.open();
        reader.open();
        while ((road = reader.next()) != null) {
            writer.write(road);
        }
        reader.close();
        writer.close();
    }

    HashSet<Long> set = new HashSet<>();

    {
        RoadMap map = Testmap.instance();
        RoadReader reader = new BfmapReader(
                BfmapReaderTest.class.getResource("oberbayern.bfmap.test").getPath());
        BaseRoad road = null;

        reader.open();
        while ((road = reader.next()) != null) {
            Road other = map.get(road.id() * 2);

            if (other == null) {
                fail();
            }

            assertTrue(road.source() == other.source());
            assertTrue(road.target() == other.target());
            assertTrue(road.refid() == other.base().refid());

            if (set.contains(road.id())) {
                fail();
            } else {
                set.add(road.id());
            }
        }
        reader.close();
    }

    {
        RoadReader reader = Testmap.instance().reader();
        BaseRoad road = null;

        reader.open();
        while ((road = reader.next()) != null) {
            if (!set.contains(road.id())) {
                fail();
            }
        }
        reader.close();
    }
}

From source file:es.pode.gestorFlujo.presentacion.objetosPendientes.Publicar.PublicarControllerImpl.java

private String[] interseccionNodos(String nodos) throws Exception {
    SrvNodoService nodosPlataforma = this.getSrvNodoService();

    String[] nodosListados = obtenNodosLocalesIds(nodosPlataforma);
    HashSet nodosTotal = new HashSet(Arrays.asList(nodosListados));
    ArrayList listaNodos = new ArrayList(Arrays.asList(nodos.split(",")));
    HashSet nodosLeidos = new HashSet(listaNodos);
    nodosLeidos.retainAll(nodosTotal);/* w w  w.j a v  a  2s . c  o m*/
    if (!nodosLeidos.contains(nodosListados[0])) {
        nodosLeidos.add(nodosListados[0]);
    }
    String[] retorno = (String[]) nodosLeidos.toArray(new String[0]);
    return retorno;
}

From source file:Business.InvertedIndex.java

public List searchForWholePhrase(List<DocInfo> docList, String[] queryTerms) {

    HashMap<DocInfo, Integer> documentPhraseScore = new HashMap<>();

    for (DocInfo doc : docList) {
        documentPhraseScore.put(doc, 0);
        int count = 0;
        for (String word1 : queryTerms) {
            String word2 = word1.replaceAll("[^\\w]", "");
            es.setCurrent(word2);//  w  ww  .  j  a  va  2  s . co  m
            es.stem();
            String queryTerm = es.getCurrent();
            HashSet<Integer> positions = new HashSet<>();

            if (doc.getTermsInADocument().containsKey(queryTerm)) {
                if (positions.isEmpty()) {
                    positions.addAll(doc.getTermsInADocument().get(queryTerm).getPositions());
                } else {
                    ArrayList<Integer> newPositions = doc.getTermsInADocument().get(queryTerm).getPositions();
                    ArrayList<Integer> tempList = new ArrayList<>();
                    boolean b = false;
                    for (int po : newPositions) {

                        if (positions.contains(po - 1)) {
                            tempList.add(po);
                            int currentScore = documentPhraseScore.get(doc);
                            int newScore = currentScore + count;
                            documentPhraseScore.put(doc, newScore);
                            b = true;
                        }
                    }
                    if (b) {
                        positions.clear();
                        positions.addAll(tempList);
                    }
                }
            }
            if (count == 0) {
                count++;
            } else {
                count = count * 10;
            }
        }

    }

    Set<DocInfo> set = documentPhraseScore.keySet();
    List<DocInfo> sortedDocs = new ArrayList<>(set);

    Collections.sort(sortedDocs, (DocInfo s1, DocInfo s2) -> Double.compare(documentPhraseScore.get(s2),
            documentPhraseScore.get(s1)));
    return sortedDocs;
}

From source file:com.intuit.tank.perfManager.workLoads.WorkLoadFactory.java

private Set<? extends RegionRequest> getRegions(JobInstance job) {
    Set<JobRegion> ret = new HashSet<JobRegion>();
    JobRegionDao dao = new JobRegionDao();
    HashSet<VMRegion> regionSet = new HashSet<VMRegion>();
    for (EntityVersion version : job.getJobRegionVersions()) {
        JobRegion jobRegion = null;/*w  ww .  ja va 2 s  .  com*/
        if (version.getObjectId() > 0 && version.getVersionId() > 0) {
            try {
                jobRegion = dao.findRevision(version.getObjectId(), version.getVersionId());
            } catch (Exception e) {
                LOG.error("Error getting region revision: " + e.toString(), e);
            }
        }
        if (jobRegion != null) {
            ret.add(fixJobRegion(jobRegion, job));
            if (regionSet.contains(jobRegion.getRegion())) {
                LOG.warn("attempt to add multiple regions to job");
            } else {
                regionSet.add(jobRegion.getRegion());
            }
        } else {
            LOG.warn("Attempt to add jobRegion version that does not exist. id = " + version.getObjectId()
                    + " : version = " + version.getVersionId());
            jobRegion = dao.findById(version.getObjectId());
            if (jobRegion != null) {
                ret.add(fixJobRegion(jobRegion, job));
                if (regionSet.contains(jobRegion.getRegion())) {
                    LOG.warn("attempt to add multiple regions to job");
                } else {
                    regionSet.add(jobRegion.getRegion());
                }
            } else {
                LOG.warn("Cannot find job region with id " + version.getObjectId()
                        + ". Returning current job Regions.");
                Workload workload = new WorkloadDao().findById(job.getWorkloadId());
                ret = workload.getJobConfiguration().getJobRegions();
                for (JobRegion region : ret) {
                    fixJobRegion(region, job);
                }
                break;
                // throw new RuntimeException("Cannot find job region with id " + version.getObjectId());
            }
        }
    }
    ret = JobRegionDao.cleanRegions(ret);
    return ret;
}

From source file:com.netflix.genie.agent.execution.statemachine.StateMachineAutoConfigurationTest.java

private void assertActionsExecuted(final StateAction... expectedStateActions) {
    Assert.assertEquals(Lists.newArrayList(expectedStateActions), executedActions);

    final HashSet<StateAction> expectedStateActionsSet = Sets.newHashSet(expectedStateActions);

    for (Pair<States, StateAction> stateAndAction : statesWithActions) {
        final TestStateAction action = (TestStateAction) stateAndAction.getRight();
        final int expectedExecutionCount = expectedStateActionsSet.contains(action) ? 1 : 0;
        final int actualExecutionCount = action.getExecutionCount();
        Assert.assertEquals("Unexpected executions for state " + stateAndAction.getLeft() + "action",
                expectedExecutionCount, actualExecutionCount);
    }/*from w  ww.jav a 2 s. co m*/
}

From source file:com.google.dart.engine.internal.element.ClassElementImpl.java

private boolean safeIsOrInheritsProxy(ClassElement classElt, HashSet<ClassElement> visitedClassElts) {
    if (visitedClassElts.contains(classElt)) {
        return false;
    }/*from   w w w. j  av a  2  s .  c  o  m*/
    visitedClassElts.add(classElt);
    if (classElt.isProxy()) {
        return true;
    } else if (classElt.getSupertype() != null
            && safeIsOrInheritsProxy(classElt.getSupertype().getElement(), visitedClassElts)) {
        return true;
    }
    InterfaceType[] supertypes = classElt.getInterfaces();
    for (int i = 0; i < supertypes.length; i++) {
        if (safeIsOrInheritsProxy(supertypes[i].getElement(), visitedClassElts)) {
            return true;
        }
    }
    supertypes = classElt.getMixins();
    for (int i = 0; i < supertypes.length; i++) {
        if (safeIsOrInheritsProxy(supertypes[i].getElement(), visitedClassElts)) {
            return true;
        }
    }
    return false;
}

From source file:de.fuberlin.wiwiss.r2r.Repository.java

private boolean mergeWithReferencedMappings(String mappingURI, List<String> prefixDefinitions, String classRef,
        List<String> sourcePatterns) {
    HashSet<String> mappingPath = new HashSet<String>();
    while (classRef != null) {
        if (mappingPath.contains(classRef)) {
            if (log.isDebugEnabled()) {
                StringBuilder sb = new StringBuilder();
                sb.append("Mapping <").append(mappingURI)
                        .append("> references other mappings that lead to a cycle. ");
                sb.append("Cycle starts with mapping: <").append(classRef).append(">.");
                log.debug(sb.toString());
            }//  w  w  w. j a  va 2s.  c  o m
            return false;
        } else
            mappingPath.add(classRef);

        MappingData mapData = getMappingDataOfUri(classRef);
        if (mapData == null)
            return false;
        sourcePatterns.add(mapData.sourcePattern);
        prefixDefinitions.addAll(mapData.prefixDefinitions);
        classRef = getReferencedClassMappingUri(classRef);
    }
    return true;
}

From source file:examples.ClassPropertyUsageAnalyzer.java

private void addSuperClasses(EntityIdValue itemIdValue, HashSet<EntityIdValue> superClasses) {
    if (superClasses.contains(itemIdValue)) {
        return;//from  w  w w.  j  a va 2s  .co m
    }
    superClasses.add(itemIdValue);
    ClassRecord classRecord = this.classRecords.get(itemIdValue);
    if (classRecord == null) {
        return;
    }

    for (EntityIdValue superClass : classRecord.superClasses) {
        addSuperClasses(superClass, superClasses);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.grefine.GrefinePropertyListServlet.java

private HashMap<VClass, List<DataProperty>> populateClassPropertiesMap(VClassDao vcDao, DataPropertyDao dao,
        String uri, HashSet<String> propURIs) {

    HashMap<VClass, List<DataProperty>> classPropertiesMap = new HashMap<VClass, List<DataProperty>>();
    List<DataProperty> props = new ArrayList<DataProperty>();
    VClass topVc = vcDao.getVClassByURI(uri);
    Collection<DataProperty> dataProps = dao.getDataPropertiesForVClass(uri);
    Iterator<DataProperty> dataPropIt = dataProps.iterator();
    while (dataPropIt.hasNext()) {
        DataProperty dp = dataPropIt.next();
        if (!(propURIs.contains(dp.getURI()))) {
            propURIs.add(dp.getURI());/*from   w w  w. ja v a 2  s.  co m*/
            DataProperty prop = dao.getDataPropertyByURI(dp.getURI());
            if (prop != null) {
                props.add(prop);
            }
        }
    }

    if (props.size() > 0) {

        Collections.sort(props);
        for (DataProperty prop : props) {
            String nameStr = prop.getPublicName() == null ? prop.getName() == null ? null : prop.getName()
                    : prop.getPublicName();
            if (nameStr != null) {
                if (prop.getDomainClassURI() != null) {
                    VClass vc = vcDao.getVClassByURI(prop.getDomainClassURI());
                    if (classPropertiesMap.get(vc) != null) {
                        ArrayList<DataProperty> existingList = (ArrayList<DataProperty>) classPropertiesMap
                                .get(vc);
                        existingList.add(prop);
                    } else {
                        ArrayList<DataProperty> newList = new ArrayList<DataProperty>();
                        newList.add(prop);
                        classPropertiesMap.put(vc, newList);
                    }

                } else { // some properties have no domain, belong to top vc by default
                    if (classPropertiesMap.get(topVc) != null) {
                        ArrayList<DataProperty> existingList = (ArrayList<DataProperty>) classPropertiesMap
                                .get(topVc);
                        existingList.add(prop);
                    } else {
                        ArrayList<DataProperty> newList = new ArrayList<DataProperty>();
                        newList.add(prop);
                        classPropertiesMap.put(topVc, newList);
                    }
                }
            }
        }
    }
    return classPropertiesMap;
}

From source file:com.haulmont.cuba.core.sys.AbstractViewRepository.java

protected void replaceOverridden(View replacementView) {
    StopWatch replaceTiming = new Slf4JStopWatch("ViewRepository.replaceOverridden");

    HashSet<View> checked = new HashSet<>();

    for (View view : getAllInitialized()) {
        if (!checked.contains(view)) {
            replaceOverridden(view, replacementView, checked);
        }//from ww w.ja v a2s  .  co m
    }

    replaceTiming.stop();
}