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:org.busko.routemanager.web.TestDataController.java

private void initGtfsAgencyData() {
    HashSet<String> agencyIds = new HashSet<String>();
    for (Agency agency : Agency.findAllAgencys()) {
        agencyIds.add(agency.getAgencyId());
    }//from   w ww. j a v a 2  s  . c  o  m

    if (!agencyIds.contains("GoBus")) {
        Agency agency = new Agency("GoBus", "Dunedin City GoBus",
                "http://www.orc.govt.nz/Information-and-Services/Buses/Bus-Information/", "Pacific/Auckland",
                "+643 474 0287", "en", "10");
        agency.setLive(true);
        agency.persist();
    }
    if (!agencyIds.contains("Connectabus")) {
        Agency agency = new Agency("Connectabus", "Connectabus", "http://connectabus.com/", "Pacific/Auckland",
                "+643 441 4471", "en", "11");
        agency.setLive(true);
        agency.persist();
    }
    if (!agencyIds.contains("InvercargillCity")) {
        Agency agency = new Agency("InvercargillCity", "Invercargill City Council",
                "http://www.icc.govt.nz/ServicesA-Z/Buses.aspx", "Pacific/Auckland", "+643 218 7108", "en",
                "12");
        agency.setLive(true);
        agency.persist();
    }
    if (!agencyIds.contains("TheBlenheimBus")) {
        Agency agency = new Agency("TheBlenheimBus", "The Blenheim Bus",
                "http://www.marlborough.govt.nz/Services/Parking-Roads-and-Transport/Blenheim-Bus-Service.aspx",
                "Pacific/Auckland", "+643 520 7400", "en", "20");
        agency.setLive(true);
        agency.persist();
    }
    if (!agencyIds.contains("theBayBus")) {
        Agency agency = new Agency("theBayBus", "BayBus", "http://www.baybus.co.nz/", "Pacific/Auckland",
                "+643 864 4669", "en", "21");
        agency.persist();
    }
    if (!agencyIds.contains("NelsonBus")) {
        Agency agency = new Agency("NelsonBus", "Nelson Bus", "http://www.nelsoncitycouncil.co.nz/nbus/",
                "Pacific/Auckland", "+643 546 0200", "en", "22");
        agency.persist();
    }
    if (!agencyIds.contains("Tranzit")) {
        Agency agency = new Agency("Tranzit", "Tranzit",
                "http://www.newplymouthnz.com/OurDistrict/Transport/NewPlymouthBusServices.htm",
                "Pacific/Auckland", "+646 759 6060", "en", "23");
        agency.persist();
    }
    if (!agencyIds.contains("Citylink")) {
        Agency agency = new Agency("CityLink", "CityLink Whangarei",
                "http://www.nrc.govt.nz/transport/getting-around/whangarei-bus-service/", "Pacific/Auckland",
                "+649 470 1200", "en", "24");
        agency.persist();
    }

    //        if (!agencyIds.contains("Intercity")) {
    //            Agency agency = new Agency();
    //            agency.setAgencyId("Intercity");
    //            agency.setAgencyName("Intercity Coachlines");
    //            agency.setAgencyUrl("http://www.intercity.co.nz/cheap-north-island-buses/bus-auckland-to-tauranga/");
    //            agency.setAgencyTimezone("Pacific/Auckland");
    //            agency.setAgencyPhone("+649 583 5780");
    //            agency.setAgencyLang("en");
    //            agency.setUniqueEncoding("24");
    //            agency.persist();
    //        }
    if (!agencyIds.contains("NakedBus")) {
        Agency agency = new Agency("NakedBus", "Naked Bus", "http://nakedbus.com/nz/bus/", "Pacific/Auckland",
                "0900 62533", "en", "99");
        agency.setLive(true);
        agency.persist();
    }
}

From source file:de.fuberlin.agcsw.svont.changedetection.smartcex.PartitionEL.java

/**
 * Splits the given ontology into two partitions: The set of OWL EL
 * compliant axioms and the set of axioms which are not compliant with the
 * OWL EL profile. The EL compliant partition is stored in the left part of
 * resulting pair, and the EL non-compliant partition is stored in the right
 * part./*w w w .j a v  a 2s.  c o  m*/
 * 
 * @param sourceOnto
 *            The source ontology to be partitioned.
 * @param compatibilityMode
 *            Specifies the reasoner with which the resulting partition
 *            should be compatible (e.g. Pellet has a different notion of EL
 *            than other reasoners).
 * @return A pair containing two ontologies. The left part is the partition
 *         of the source ontology with all EL-compliant axioms. The right
 *         part is the partition of the source ontology with all
 *         non-EL-compliant axioms. If the source ontology already conforms
 *         to the OWL-EL profile, then the left part of the result contains
 *         the source ontology, and the right part is null.
 * @throws OWLOntologyCreationException
 *             If there is an error loading the source ontology.
 * @throws IllegalAccessException 
 * @throws InstantiationException 
 */
public static Pair<OWLOntology, OWLOntology> partition(OWLOntology sourceOnto,
        ReasonerCompatibilityMode compatibilityMode)
        throws OWLOntologyCreationException, InstantiationException, IllegalAccessException {

    OWLProfile elProfile = compatibilityMode.getProfileClass().newInstance();

    OWLProfileReport report = elProfile.checkOntology(sourceOnto);

    if (report.isInProfile()) {
        return new ImmutablePair<OWLOntology, OWLOntology>(sourceOnto, null);
    }

    HashSet<OWLAxiom> nonELAxioms = new HashSet<OWLAxiom>();

    Set<OWLProfileViolation> violations = report.getViolations();
    for (OWLProfileViolation violation : violations) {
        nonELAxioms.add(violation.getAxiom());
    }

    OWLOntologyID ontologyID = sourceOnto.getOntologyID();
    IRI ontologyIRI = ontologyID.getOntologyIRI();

    IRI targetELOntologyIRI = IRI.create(ontologyIRI.toString() + "/ELpart");
    IRI targetNonELOntologyIRI = IRI.create(ontologyIRI.toString() + "/nonELpart");

    OWLOntologyManager targetELOntoManager = OWLManager.createOWLOntologyManager();
    targetELOntoManager.addIRIMapper(new NonMappingOntologyIRIMapper());
    OWLOntology targetELOnto = targetELOntoManager.createOntology(new OWLOntologyID(targetELOntologyIRI));

    OWLOntologyManager targetNonELOntoManager = OWLManager.createOWLOntologyManager();
    targetNonELOntoManager.addIRIMapper(new NonMappingOntologyIRIMapper());
    OWLOntology targetNonELOnto = targetNonELOntoManager
            .createOntology(new OWLOntologyID(targetNonELOntologyIRI));

    Set<OWLAxiom> allAxioms = sourceOnto.getAxioms();
    for (OWLAxiom axiom : allAxioms) {
        if (nonELAxioms.contains(axiom)) {
            targetNonELOntoManager.addAxiom(targetNonELOnto, axiom);
            System.out.println("- " + axiom);
        } else {
            targetELOntoManager.addAxiom(targetELOnto, axiom);
            System.out.println("+ " + axiom);
        }
    }

    return new ImmutablePair<OWLOntology, OWLOntology>(targetELOnto, targetNonELOnto);
}

From source file:graph.module.DepthModule.java

/**
 * Recursively calculate the node depth.
 * //from   ww  w.  j  a v  a2s.co m
 * @param node
 *            The node to calculate depth for.
 * @param seen
 *            If the node has been seen already in this calculation.
 * @return The minimum depth of the above node.
 */
private int processNode(DAGNode node, HashSet<Integer> seen) {
    if (node.equals(CommonConcepts.THING.getNode(dag_))) {
        dag_.addProperty(node, DEPTH_PROPERTY, "0");
        depthMap_.put(0, node);
        return 0;
    }
    if (seen.contains(node.getID()))
        return 0;
    seen.add(node.getID());

    int depth = 1;
    String depthStr = node.getProperty(DEPTH_PROPERTY);
    if (depthStr == null || depthStr.equals("-1")) {
        Collection<Node> minCol = getMinimumParents(node);
        for (Node superGenls : minCol) {
            depth = Math.max(processNode((DAGNode) superGenls, new HashSet<>(seen)) + 1, depth);
        }
        dag_.addProperty(node, DEPTH_PROPERTY, depth + "");
        depthMap_.put(depth, node);
    } else
        depth = Integer.parseInt(depthStr);
    return depth;
}

From source file:com.helpinput.spring.refresher.SessiontRefresher.java

@SuppressWarnings("unchecked")
ManagedList<Object> getManageList(DefaultListableBeanFactory dlbf, PropertyValue oldPropertyValue) {
    Set<String> oldClasses = null;

    if (oldPropertyValue != null) {
        Object value = oldPropertyValue.getValue();
        if (value != null && value instanceof ManagedList) {
            ManagedList<Object> real = (ManagedList<Object>) value;
            oldClasses = new HashSet<>(real.size() >>> 1);
            ClassLoader parentClassLoader = ClassUtils.getDefaultClassLoader();
            for (Object object : real) {
                TypedStringValue typedStringValue = (TypedStringValue) object;
                String className = typedStringValue.getValue();
                try {
                    parentClassLoader.loadClass(className);
                    oldClasses.add(className);
                } catch (ClassNotFoundException e) {
                }// w  w  w .  ja v  a  2  s . c  o m
            }
        }
    }

    int oldClassSize = (Utils.hasLength(oldClasses) ? oldClasses.size() : 0);
    Map<String, Object> beans = dlbf.getBeansWithAnnotation(Entity.class);
    HashSet<String> totalClasses = new HashSet<>(beans.size() + oldClassSize);
    if (oldClassSize > 0) {
        totalClasses.addAll(oldClasses);
    }

    for (Object entity : beans.values()) {
        String clzName = entity.getClass().getName();
        if (!totalClasses.contains(clzName)) {
            totalClasses.add(clzName);
        }
    }

    ManagedList<Object> list = new ManagedList<>(totalClasses.size());
    for (String clzName : totalClasses) {
        TypedStringValue typedStringValue = new TypedStringValue(clzName);
        list.add(typedStringValue);
    }
    return list;
}

From source file:net.lightbody.bmp.proxy.jetty.http.HashUserRealm.java

/** Check if a user is in a role.
 * @param user The user, which must be from this realm 
 * @param roleName //  w  w w .j  a  va 2 s. c o  m
 * @return True if the user can act in the role.
 */
public synchronized boolean isUserInRole(Principal user, String roleName) {
    if (user instanceof WrappedUser)
        return ((WrappedUser) user).isUserInRole(roleName);

    if (user == null || ((User) user).getUserRealm() != this)
        return false;

    HashSet userSet = (HashSet) _roles.get(roleName);
    return userSet != null && userSet.contains(user.getName());
}

From source file:fr.aliasource.webmail.common.conversation.ListConversationsCommand.java

private boolean allSeen(ConversationReference cr, HashSet<Long> seen, IStoreConnection store)
        throws IOException, StoreException {
    for (MessageId id : cr.getMessageIds()) {
        if (!seen.contains(id.getImapId())) {
            return false;
        }//  w w w.ja  va  2 s  .c  o  m
    }
    return true;
}

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

@Override
protected ResponseValues processRequest(VitroRequest vreq) {

    Map<String, Object> body = new HashMap<String, Object>();
    try {/*from ww w .j ava 2 s. c om*/

        body.put("displayOption", "all");
        body.put("pageTitle", "All Data Properties");
        body.put("propertyType", "data");

        String noResultsMsgStr = "No data properties found";

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

        DataPropertyDao dao = vreq.getUnfilteredWebappDaoFactory().getDataPropertyDao();
        DataPropertyDao dpDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getDataPropertyDao();
        VClassDao vcDao = vreq.getUnfilteredWebappDaoFactory().getVClassDao();
        VClassDao vcDaoLangNeut = vreq.getLanguageNeutralWebappDaoFactory().getVClassDao();
        DatatypeDao dDao = vreq.getUnfilteredWebappDaoFactory().getDatatypeDao();
        PropertyGroupDao pgDao = vreq.getUnfilteredWebappDaoFactory().getPropertyGroupDao();

        List<DataProperty> props = new ArrayList<DataProperty>();
        if (vreq.getParameter("propsForClass") != null) {
            noResultsMsgStr = "There are no data properties that apply to this class.";
            Collection<DataProperty> dataProps = vreq.getLanguageNeutralWebappDaoFactory().getDataPropertyDao()
                    .getDataPropertiesForVClass(vreq.getParameter("vclassUri"));
            Iterator<DataProperty> dataPropIt = dataProps.iterator();
            HashSet<String> propURIs = new HashSet<String>();
            while (dataPropIt.hasNext()) {
                DataProperty dp = dataPropIt.next();
                if (!(propURIs.contains(dp.getURI()))) {
                    propURIs.add(dp.getURI());
                    DataProperty prop = dao.getDataPropertyByURI(dp.getURI());
                    if (prop != null) {
                        props.add(prop);
                    }
                }
            }
        } else {
            props = dao.getAllDataProperties();
        }

        if (ontologyUri != null) {
            List<DataProperty> scratch = new ArrayList<DataProperty>();
            for (DataProperty p : props) {
                if (p.getNamespace().equals(ontologyUri)) {
                    scratch.add(p);
                }
            }
            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 {
                for (DataProperty prop : props) {
                    if (counter > 0) {
                        json += ", ";
                    }

                    String nameStr = prop.getPickListName() == null
                            ? prop.getName() == null ? prop.getURI() == null ? "(no name)" : prop.getURI()
                                    : prop.getName()
                            : prop.getPickListName();

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

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

                    /*                        VClass vc = null;
                                            String domainStr="";
                                            if (prop.getDomainClassURI() != null) {
                    vc = vcDao.getVClassByURI(prop.getDomainClassURI());
                    if (vc != null) {
                        try {
                            domainStr="<a href=\"vclassEdit?uri="+URLEncoder.encode(prop.getDomainClassURI(),"UTF-8")+"\">"+vc.getName()+"</a>";
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                    }
                                            }
                    */
                    DataProperty dpLangNeut = dpDaoLangNeut.getDataPropertyByURI(prop.getURI());
                    if (dpLangNeut == null) {
                        dpLangNeut = prop;
                    }
                    String domainStr = getVClassNameFromURI(dpLangNeut.getDomainVClassURI(), vcDao,
                            vcDaoLangNeut);
                    json += "\"domainVClass\": " + JSONUtils.quote(domainStr) + ", ";

                    Datatype rangeDatatype = dDao.getDatatypeByURI(prop.getRangeDatatypeURI());
                    String rangeDatatypeStr = (rangeDatatype == null) ? prop.getRangeDatatypeURI()
                            : rangeDatatype.getName();
                    json += "\"rangeVClass\": " + JSONUtils.quote(rangeDatatypeStr) + ", ";

                    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:org.slf4j.impl.PiazzaLogger.java

/**
 * //ww w .j av  a  2s .c  om
 * @param severity
 *            Severity codes per syslog rfc-5424 standard
 * @param message
 *            String message of the log
 * @param arguments
 *            Optional log arguments, audit / metric / exception types
 */
public void processLogs(Severity severity, String format, Object... arguments) {
    String message = format;
    LoggerPayload payload = new LoggerPayload();
    HashSet<String> argumentSet = new HashSet<String>();

    for (int i = 0; i < arguments.length; i++) {
        Object obj = arguments[i];

        if (obj instanceof AuditElement && !argumentSet.contains("auditElement")) {
            argumentSet.add("AuditElement");
            payload.setAuditData((AuditElement) obj);
        } else if (obj instanceof MetricElement && !argumentSet.contains("metricElement")) {
            argumentSet.add("MetricElement");
            payload.setMetricData((MetricElement) obj);
        } else if (obj instanceof Throwable && !argumentSet.contains("exception")) {
            argumentSet.add("exception");
            Throwable exception = (Throwable) obj;
            String exceptionStackTrace = ExceptionUtils.getStackTrace(exception);

            System.out.println(exceptionStackTrace);
            message = String.format("%s - %s", message, exceptionStackTrace);
        }
    }

    sendLogs(payload, message, severity);
}

From source file:org.jboss.as.test.integration.management.api.web.ConnectorTestCase.java

@Test
public void testDefaultConnectorList() throws Exception {

    // only http connector present as a default

    HashSet<String> connNames = getConnectorList();

    assertTrue("HTTP connector missing.", connNames.contains("http"));
    assertTrue(connNames.size() == 1);/*  w w  w.  ja v  a2s  .c  o  m*/
}

From source file:com.cyclopsgroup.tornado.hibernate.HqlLargeList.java

/**
 * Overwrite or implement method getSize()
 *
 * @see com.cyclopsgroup.waterview.LargeList#getSize()
 *///from ww w .j a v a 2s.  c o  m
public int getSize() throws Exception {
    String countQuery = "SELECT COUNT(*) " + hql;
    Session s = hibernate.getSession(dataSource);
    Query query = s.createQuery(countQuery);
    HashSet parameterNames = new HashSet();
    CollectionUtils.addAll(parameterNames, query.getNamedParameters());
    for (Iterator i = parameters.values().iterator(); i.hasNext();) {
        Parameter p = (Parameter) i.next();
        if (parameterNames.contains(p.getName())) {
            query.setParameter(p.getName(), p.getValue(), p.getType());
        }
    }
    List result = query.list();
    if (result == null || result.isEmpty()) {
        return -1;
    }
    Integer i = (Integer) result.get(0);
    return i.intValue();
}