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:fr.aliasource.webmail.common.conversation.ListConversationsCommand.java

private RawMessage parseHeaders(HashSet<Long> unseen, HashSet<Long> withAttachments, HashSet<Long> starred,
        HashSet<Long> answered, IMAPHeaders head, long uid, HashSet<Long> withInvitations) {
    boolean read = !unseen.contains(uid);
    boolean attach = withAttachments.contains(uid);
    boolean invitation = withInvitations.contains(uid);
    boolean answer = answered.contains(uid);
    boolean star = starred.contains(uid);
    String subject = head.getSubject();
    String smtpId = head.getRawHeader("message-id");
    String pri = head.getRawHeader("x-priority");
    boolean prio = pri != null && pri.trim().startsWith("1");
    // generate a stable uid when none is found in the message
    if (smtpId == null) {
        smtpId = "<" + subject.hashCode() + "-" + uid + "@generated.minig.org>";
    }// w ww  . j av  a  2  s. c  o  m

    String inReplyTo = head.getRawHeader("in-reply-to");
    Address a = null;
    List<Address> ccA = Collections.emptyList();
    List<Address> toA = Collections.emptyList();
    if (isShowRecipientsFolder) {
        toA = head.getTo();
        ccA = head.getCc();
    } else {
        a = head.getFrom();
    }

    RawMessage msg = new RawMessage(uid, smtpId, inReplyTo, subject, read, head.getDate().getTime(), a, attach,
            star, invitation, toA, ccA, answer, prio);
    return msg;
}

From source file:com.nokia.dempsy.container.TestMpContainer.java

@Test
public void testInvokeOutput() throws Exception {
    inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
    outputQueue.poll(1000, TimeUnit.MILLISECONDS);
    inputQueue.add(serializer.serialize(new ContainerTestMessage("bar")));
    outputQueue.poll(1000, TimeUnit.MILLISECONDS);

    assertEquals("number of MP instances", 2, container.getProcessorCount());
    assertTrue("queue is empty", outputQueue.isEmpty());

    container.outputPass();/*from   www .  j  av a2 s  .c  om*/
    OutputMessage out1 = (OutputMessage) serializer
            .deserialize((byte[]) outputQueue.poll(1000, TimeUnit.MILLISECONDS));
    OutputMessage out2 = (OutputMessage) serializer
            .deserialize((byte[]) outputQueue.poll(1000, TimeUnit.MILLISECONDS));

    assertTrue("messages received", (out1 != null) && (out2 != null));
    assertEquals("no more messages in queue", 0, outputQueue.size());

    // order of messages is not guaranteed, so we need to aggregate keys
    HashSet<String> messageKeys = new HashSet<String>();
    messageKeys.add(out1.getKey());
    messageKeys.add(out2.getKey());
    assertTrue("first MP sent output", messageKeys.contains("foo"));
    assertTrue("second MP sent output", messageKeys.contains("bar"));
}

From source file:org.eclipse.lyo.testsuite.oslcv2.CreationAndUpdateJsonTests.java

private void fillInUsingValueType(JSONObject toCreate, JSONObject property) throws JSONException {
    Object valueTypeObject = property.get("oslc:valueType");
    String key = getQName(property);
    if (valueTypeObject != null) {
        HashSet<String> valueTypes = getValueTypes(property);

        /*/*from w  ww .  j av a2s .  c  om*/
         * Look at each type. Try to fill in something reasonable.
         */
        if (valueTypes.contains(OSLCConstants.STRING_TYPE)
                || valueTypes.contains(OSLCConstants.XML_LITERAL_TYPE)) {
            String string = generateStringValue(getMaxSize(property));
            toCreate.put(key, string);
        } else if (valueTypes.contains(OSLCConstants.BOOLEAN_TYPE)) {
            toCreate.put(key, true);
        } else if (valueTypes.contains(OSLCConstants.INTEGER_TYPE)) {
            toCreate.put(key, 1);
        } else if (valueTypes.contains(OSLCConstants.DOUBLE_TYPE)) {
            toCreate.put(key, 1.0d);
        } else if (valueTypes.contains(OSLCConstants.FLOAT_TYPE)) {
            toCreate.put(key, 1.0f);
        }

        // TODO: Support decimal, date/time, and resource.

    } else {
        // We have no hints. Try to set a string value. This may fail.
        String string = generateStringValue(getMaxSize(property));
        toCreate.put(key, string);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.IndividualsViaObjectPropetyOptions.java

@Override
public Map<String, String> getOptions(EditConfigurationVTwo editConfig, String fieldName,
        WebappDaoFactory wDaoFact) {//  w w  w  .  j  av  a  2s.c  o  m
    HashMap<String, String> optionsMap = new LinkedHashMap<String, String>();
    int optionsCount = 0;

    // first test to see whether there's a default "leave blank"
    // value specified with the literal options                
    if ((defaultOptionLabel) != null) {
        optionsMap.put(LEFT_BLANK, defaultOptionLabel);
    }

    Individual subject = wDaoFact.getIndividualDao().getIndividualByURI(subjectUri);

    //get all vclasses applicable to the individual subject
    HashSet<String> vclassesURIs = getApplicableVClassURIs(subject, wDaoFact);

    if (!rangeTypes.isEmpty()) {
        vclassesURIs = filterToSubclassesOfRange(vclassesURIs, rangeTypes, wDaoFact);
        // is there only one range class and does it have any subclasses? If not, there's no
        // reason to get the mostSpecificType of the individuals displayed in the select element
        if (vreq != null && rangeTypes.size() == 1) {
            hasSubclasses = rangeHasSubclasses(rangeTypes.get(0), vreq);
        }
    }

    if (vclassesURIs.size() == 0) {
        return optionsMap;
    }

    List<Individual> individuals = new ArrayList<Individual>();
    HashSet<String> uriSet = new HashSet<String>();
    for (String vclassURI : vclassesURIs) {
        List<Individual> inds = wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclassURI, -1, -1);
        for (Individual ind : inds) {
            if (!uriSet.contains(ind.getURI())) {
                uriSet.add(ind.getURI());
                individuals.add(ind);
            }
        }
    }

    List<ObjectPropertyStatement> stmts = subject.getObjectPropertyStatements();

    individuals = FieldUtils.removeIndividualsAlreadyInRange(individuals, stmts, predicateUri, objectUri);
    // Collections.sort(individuals,new compareIndividualsByName());a

    for (Individual ind : individuals) {
        String uri = ind.getURI();
        if (uri != null) {
            // The picklist should only display individuals with rdfs labels. 
            // SO changing the following line  -- tlw72
            // String label = ind.getName().trim();
            String label = ind.getRdfsLabel();
            if (label != null) {
                List<String> msTypes = ind.getMostSpecificTypeURIs();
                if (hasSubclasses && msTypes.size() > 0) {
                    String theType = getMsTypeLocalName(msTypes.get(0), wDaoFact);
                    if (theType.length() > 0) {
                        label += " (" + theType + ")";
                    }
                }
                optionsMap.put(uri, label);
                ++optionsCount;
            }
        }
    }
    return optionsMap;
}

From source file:com.jgui.ttscrape.htmlunit.FetchController.java

public HashSet<Long> processShows(HashSet<Long> previousKeys, List<Show> shows) {
    HashSet<Long> newKeys = new HashSet<Long>();
    for (Show s : shows) {
        newKeys.add(s.getDetailKey());/*from ww  w  .j  av  a 2  s.  co m*/
        boolean keeper = true;
        if (previousKeys.contains(s.getDetailKey())) {
            keeper = false;
        } else {
            for (ShowFilter f : filters) {
                if (f.exclude(s)) {
                    keeper = false;
                    break;
                }
            }
        }
        if (keeper) {
            for (ShowPostProcessor pp : postProcessors) {
                pp.postProcess(s);
            }
        }
    }
    return newKeys;
}

From source file:gov.nih.nci.evs.browser.test.tree.ChildPagingEvsTreeConverter.java

/**
 * Walk tree from root.//from w  ww  . ja v a  2 s  . c o m
 *
 * @param node the node
 *
 * @return the jSON object
 */
private LexEvsTreeNode walkTreeFromRoot(LexEvsTreeNode node) {
    LexEvsTreeNode nodeObject = new LexEvsTreeNode();

    System.out.println("walkTreeFromRoot: " + node.getCode() + " " + node.getEntityDescription());

    try {
        nodeObject = buildNode(node);

        if (node.getPathToRootChildren() != null) {
            int children = 0;
            for (LexEvsTreeNode child : node.getPathToRootChildren()) {
                children++;
                nodeObject.addPathToRootChildren(walkTreeFromRoot(child));
            }

            HashSet hset = new HashSet();

            ChildTreeNodeIterator itr = node.getChildIterator();
            while (itr.hasNext() && children < MAX_CHILDREN) {
                LexEvsTreeNode child = itr.next();

                String child_code = child.getCode();

                if (!hset.contains(child_code)) {
                    hset.add(child_code);

                    System.out.println(child.getCode() + " " + child.getEntityDescription());

                    if (!knownChildrenContainsCode(node.getPathToRootChildren(), child.getCode())) {
                        nodeObject.addPathToRootChildren(walkTreeFromRoot(child));
                        children++;
                    }

                } else {
                    break;
                }

            }

            if (children >= MAX_CHILDREN) {
                nodeObject.addPathToRootChildren(buildMoreChildrenNode(node));
            }
        }

    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    return nodeObject;
}

From source file:com.liangc.hq.base.utils.BizappUtils.java

/**
 * Return a <code>List</code> of <code>AuthzSubjectValue</code>
 * objects from a list that do <strong>not</strong> appear in
 * a list of matches.//from w  w  w. ja  v a 2  s .com
 *
 * @param all the list to operate on
 * @param matches the list to grep out
 */
public static List<AuthzSubjectValue> grepSubjects(List all, List matches) {
    if (all == null || matches == null) {
        return new ArrayList(0);
    }

    // build an index of role subjects
    HashSet index = new HashSet();
    Iterator mi = matches.iterator();
    while (mi.hasNext()) {
        Object m = mi.next();
        index.add(((AuthzSubject) m).getId());
    }

    // find available subjects (those not in the index)
    ArrayList objects = new ArrayList();
    Iterator ai = all.iterator();
    while (ai.hasNext()) {
        AuthzSubjectValue obj = (AuthzSubjectValue) ai.next();
        if (!index.contains(obj.getId())) {
            objects.add(obj);
        }
    }

    return objects;
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.ListPropertyWebappsController.java

@Override
protected ResponseValues processRequest(VitroRequest vreq) {

    Map<String, Object> body = new HashMap<String, Object>();
    try {//from w  w  w  .ja  va 2  s  . c o  m

        body.put("displayOption", "all");
        body.put("pageTitle", "All Object Properties");
        body.put("propertyType", "object");

        String noResultsMsgStr = "No object properties found";

        String ontologyUri = vreq.getParameter("ontologyUri");

        ObjectPropertyDao dao = vreq.getUnfilteredWebappDaoFactory().getObjectPropertyDao();
        ObjectPropertyDao opDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getObjectPropertyDao();
        PropertyInstanceDao piDao = vreq.getLanguageNeutralWebappDaoFactory().getPropertyInstanceDao();
        VClassDao vcDao = vreq.getUnfilteredWebappDaoFactory().getVClassDao();
        VClassDao vcDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getVClassDao();
        PropertyGroupDao pgDao = vreq.getUnfilteredWebappDaoFactory().getPropertyGroupDao();

        String vclassURI = vreq.getParameter("vclassUri");

        List<ObjectProperty> props = new ArrayList<ObjectProperty>();
        if (vreq.getParameter("propsForClass") != null) {
            noResultsMsgStr = "There are no object properties that apply to this class.";

            // incomplete list of classes to check, but better than before
            List<String> superclassURIs = vcDao.getAllSuperClassURIs(vclassURI);
            superclassURIs.add(vclassURI);
            superclassURIs.addAll(vcDao.getEquivalentClassURIs(vclassURI));

            Map<String, PropertyInstance> propInstMap = new HashMap<String, PropertyInstance>();
            for (String classURI : superclassURIs) {
                Collection<PropertyInstance> propInsts = piDao.getAllPropInstByVClass(classURI);
                for (PropertyInstance propInst : propInsts) {
                    propInstMap.put(propInst.getPropertyURI(), propInst);
                }
            }
            List<PropertyInstance> propInsts = new ArrayList<PropertyInstance>();
            propInsts.addAll(propInstMap.values());
            Collections.sort(propInsts);

            Iterator<PropertyInstance> propInstIt = propInsts.iterator();
            HashSet<String> propURIs = new HashSet<String>();
            while (propInstIt.hasNext()) {
                PropertyInstance pi = (PropertyInstance) propInstIt.next();
                if (!(propURIs.contains(pi.getPropertyURI()))) {
                    propURIs.add(pi.getPropertyURI());
                    ObjectProperty prop = (ObjectProperty) dao.getObjectPropertyByURI(pi.getPropertyURI());
                    if (prop != null) {
                        props.add(prop);
                    }
                }
            }
        } else {
            props = (vreq.getParameter("iffRoot") != null) ? dao.getRootObjectProperties()
                    : dao.getAllObjectProperties();
        }

        OntologyDao oDao = vreq.getUnfilteredWebappDaoFactory().getOntologyDao();
        HashMap<String, String> ontologyHash = new HashMap<String, String>();

        Iterator<ObjectProperty> propIt = props.iterator();
        List<ObjectProperty> scratch = new ArrayList<ObjectProperty>();
        while (propIt.hasNext()) {
            ObjectProperty p = propIt.next();
            if (p.getNamespace() != null) {
                if (!ontologyHash.containsKey(p.getNamespace())) {
                    Ontology o = oDao.getOntologyByURI(p.getNamespace());
                    if (o == null) {
                        if (!VitroVocabulary.vitroURI.equals(p.getNamespace())) {
                            log.debug(
                                    "doGet(): no ontology object found for the namespace " + p.getNamespace());
                        }
                    } else {
                        ontologyHash.put(p.getNamespace(),
                                o.getName() == null ? p.getNamespace() : o.getName());
                    }
                }
                if (ontologyUri != null && p.getNamespace().equals(ontologyUri)) {
                    scratch.add(p);
                }
            }
        }

        if (ontologyUri != null) {
            props = scratch;
        }

        if (props != null) {
            sortForPickList(props, vreq);
        }

        String json = new String();
        int counter = 0;

        if (props != null) {
            if (props.size() == 0) {
                json = "{ \"name\": \"" + noResultsMsgStr + "\" }";
            } else {
                Iterator<ObjectProperty> propsIt = props.iterator();
                while (propsIt.hasNext()) {
                    if (counter > 0) {
                        json += ", ";
                    }
                    ObjectProperty prop = propsIt.next();

                    String propNameStr = ShowObjectPropertyHierarchyController.getDisplayLabel(prop);

                    try {
                        json += "{ \"name\": "
                                + JSONUtils.quote("<a href='./propertyEdit?uri="
                                        + URLEncoder.encode(prop.getURI()) + "'>" + propNameStr + "</a>")
                                + ", ";
                    } catch (Exception e) {
                        json += "{ \"name\": \"" + propNameStr + "\", ";
                    }

                    json += "\"data\": { \"internalName\": " + JSONUtils.quote(prop.getLocalNameWithPrefix())
                            + ", ";

                    ObjectProperty opLangNeut = opDaoLangNeut.getObjectPropertyByURI(prop.getURI());
                    if (opLangNeut == null) {
                        opLangNeut = prop;
                    }
                    String domainStr = getVClassNameFromURI(opLangNeut.getDomainVClassURI(), vcDao,
                            vcDaoLangNeut);
                    json += "\"domainVClass\": " + JSONUtils.quote(domainStr) + ", ";

                    String rangeStr = getVClassNameFromURI(opLangNeut.getRangeVClassURI(), vcDao,
                            vcDaoLangNeut);
                    json += "\"rangeVClass\": " + JSONUtils.quote(rangeStr) + ", ";

                    if (prop.getGroupURI() != null) {
                        PropertyGroup pGroup = pgDao.getGroupByURI(prop.getGroupURI());
                        json += "\"group\": "
                                + JSONUtils.quote((pGroup == null) ? "unknown group" : pGroup.getName())
                                + " } } ";
                    } else {
                        json += "\"group\": \"unspecified\" } }";
                    }
                    counter += 1;
                }
            }
            body.put("jsonTree", json);
        }

    } catch (Throwable t) {
        t.printStackTrace();
    }

    return new TemplateResponseValues(TEMPLATE_NAME, body);
}

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

@Test
public void testExclusion() throws IOException, JSONException {
    Properties properties = new Properties();
    properties.load(new FileInputStream("config/oberbayern.properties"));
    RoadReader reader = Loader.reader(properties);
    Polygon polygon = (Polygon) GeometryEngine.geometryFromWkt(
            "POLYGON ((11.40848 47.93157, 11.45109 47.93157,11.45109 47.89296,11.40848 47.89296,11.40848 47.93157))",
            WktImportFlags.wktImportDefaults, Type.Polygon);
    HashSet<Short> exclusion = new HashSet<>(Arrays.asList((short) 117));
    BaseRoad road = null;// w w w  . j  a  va  2  s . co  m

    reader.open(polygon, exclusion);
    int count = 0;

    while ((road = reader.next()) != null) {
        assertTrue(GeometryEngine.overlaps(polygon, road.geometry(), SpatialReference.create(4326))
                || GeometryEngine.contains(polygon, road.geometry(), SpatialReference.create(4326)));
        assertTrue(!exclusion.contains(road.type()));
        count += 1;
    }

    reader.close();
    assertTrue(count > 0);
}

From source file:com.iflytek.spider.util.EncodingDetector.java

private void findDisagreements(String url, List<EncodingClue> newClues) {
    HashSet<String> valsSeen = new HashSet<String>();
    HashSet<String> sourcesSeen = new HashSet<String>();
    boolean disagreement = false;
    for (int i = 0; i < newClues.size(); i++) {
        EncodingClue clue = newClues.get(i);
        if (!clue.isEmpty() && !sourcesSeen.contains(clue.source)) {
            if (valsSeen.size() > 0 && !valsSeen.contains(clue.value) && clue.meetsThreshold()) {
                disagreement = true;/*from  www.jav a2s .c o  m*/
            }
            if (clue.meetsThreshold()) {
                valsSeen.add(clue.value);
            }
            sourcesSeen.add(clue.source);
        }
    }
    if (disagreement) {
        // dump all values in case of disagreement
        StringBuffer sb = new StringBuffer();
        sb.append("Disagreement: " + url + "; ");
        for (int i = 0; i < newClues.size(); i++) {
            if (i > 0) {
                sb.append(", ");
            }
            sb.append(newClues.get(i));
        }
        LOG.trace(sb.toString());
    }
}