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.tremolosecurity.openunison.util.OpenUnisonUtils.java

private static void exportIdPMetadata(Options options, CommandLine cmd, TremoloType tt, KeyStore ks)
        throws Exception, KeyStoreException, CertificateEncodingException, NoSuchAlgorithmException,
        UnrecoverableKeyException, SecurityException, MarshallingException, SignatureException {

    InitializationService.initialize();//from  w w  w. j a va 2s  .  c  o m

    logger.info("Finding IdP...");
    String idpName = loadOption(cmd, "idpName", options);

    ApplicationType idp = null;

    for (ApplicationType app : tt.getApplications().getApplication()) {
        if (app.getName().equalsIgnoreCase(idpName)) {
            idp = app;
        }
    }

    if (idp == null) {
        throw new Exception("IdP '" + idpName + "' not found");
    }

    logger.info("Loading the base URL");
    String baseURL = loadOption(cmd, "urlBase", options);

    String url = baseURL + idp.getUrls().getUrl().get(0).getUri();

    SecureRandom random = new SecureRandom();
    byte[] idBytes = new byte[20];
    random.nextBytes(idBytes);

    StringBuffer b = new StringBuffer();
    b.append('f').append(Hex.encodeHexString(idBytes));
    String id = b.toString();

    EntityDescriptorBuilder edb = new EntityDescriptorBuilder();
    EntityDescriptor ed = edb.buildObject();
    ed.setID(id);
    ed.setEntityID(url);

    IDPSSODescriptorBuilder idpssdb = new IDPSSODescriptorBuilder();
    IDPSSODescriptor sd = idpssdb.buildObject();//ed.getSPSSODescriptor("urn:oasis:names:tc:SAML:2.0:protocol");
    sd.addSupportedProtocol("urn:oasis:names:tc:SAML:2.0:protocol");
    ed.getRoleDescriptors().add(sd);

    HashMap<String, List<String>> params = new HashMap<String, List<String>>();
    for (ParamType pt : idp.getUrls().getUrl().get(0).getIdp().getParams()) {
        List<String> vals = params.get(pt.getName());
        if (vals == null) {
            vals = new ArrayList<String>();
            params.put(pt.getName(), vals);
        }
        vals.add(pt.getValue());
    }

    sd.setWantAuthnRequestsSigned(params.containsKey("requireSignedAuthn")
            && params.get("requireSignedAuthn").get(0).equalsIgnoreCase("true"));

    KeyDescriptorBuilder kdb = new KeyDescriptorBuilder();

    if (params.get("encKey") != null && !params.get("encKey").isEmpty()
            && (ks.getCertificate(params.get("encKey").get(0)) != null)) {
        KeyDescriptor kd = kdb.buildObject();
        kd.setUse(UsageType.ENCRYPTION);
        KeyInfoBuilder kib = new KeyInfoBuilder();
        KeyInfo ki = kib.buildObject();

        X509DataBuilder x509b = new X509DataBuilder();
        X509Data x509 = x509b.buildObject();
        X509CertificateBuilder certb = new X509CertificateBuilder();
        org.opensaml.xmlsec.signature.X509Certificate cert = certb.buildObject();
        cert.setValue(Base64.encode(ks.getCertificate(params.get("encKey").get(0)).getEncoded()));
        x509.getX509Certificates().add(cert);
        ki.getX509Datas().add(x509);
        kd.setKeyInfo(ki);
        sd.getKeyDescriptors().add(kd);

    }

    if (params.get("sigKey") != null && !params.get("sigKey").isEmpty()
            && (ks.getCertificate(params.get("sigKey").get(0)) != null)) {
        KeyDescriptor kd = kdb.buildObject();
        kd.setUse(UsageType.SIGNING);
        KeyInfoBuilder kib = new KeyInfoBuilder();
        KeyInfo ki = kib.buildObject();

        X509DataBuilder x509b = new X509DataBuilder();
        X509Data x509 = x509b.buildObject();
        X509CertificateBuilder certb = new X509CertificateBuilder();
        org.opensaml.xmlsec.signature.X509Certificate cert = certb.buildObject();
        cert.setValue(Base64.encode(ks.getCertificate(params.get("sigKey").get(0)).getEncoded()));
        x509.getX509Certificates().add(cert);
        ki.getX509Datas().add(x509);
        kd.setKeyInfo(ki);
        sd.getKeyDescriptors().add(kd);

    }

    HashSet<String> nameids = new HashSet<String>();

    for (TrustType trustType : idp.getUrls().getUrl().get(0).getIdp().getTrusts().getTrust()) {
        for (ParamType pt : trustType.getParam()) {
            if (pt.getName().equalsIgnoreCase("nameIdMap")) {
                String val = pt.getValue().substring(0, pt.getValue().indexOf('='));
                if (!nameids.contains(val)) {
                    nameids.add(val);
                }
            }
        }
    }

    NameIDFormatBuilder nifb = new NameIDFormatBuilder();

    for (String nidf : nameids) {
        NameIDFormat nif = nifb.buildObject();
        nif.setFormat(nidf);
        sd.getNameIDFormats().add(nif);
    }

    SingleSignOnServiceBuilder ssosb = new SingleSignOnServiceBuilder();
    SingleSignOnService sso = ssosb.buildObject();
    sso.setBinding("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");
    sso.setLocation(url + "/httpPost");
    sd.getSingleSignOnServices().add(sso);

    sso = ssosb.buildObject();
    sso.setBinding("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect");
    sso.setLocation(url + "/httpRedirect");
    sd.getSingleSignOnServices().add(sso);

    String signingKey = loadOptional(cmd, "signMetadataWithKey", options);

    if (signingKey != null && ks.getCertificate(signingKey) != null) {
        BasicX509Credential signingCredential = new BasicX509Credential(
                (X509Certificate) ks.getCertificate(signingKey),
                (PrivateKey) ks.getKey(signingKey, tt.getKeyStorePassword().toCharArray()));

        Signature signature = OpenSAMLUtils.buildSAMLObject(Signature.class);

        signature.setSigningCredential(signingCredential);
        signature.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1);
        signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);

        ed.setSignature(signature);
        try {
            XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(ed).marshall(ed);
        } catch (MarshallingException e) {
            throw new RuntimeException(e);
        }
        Signer.signObject(signature);
    }

    // Get the Subject marshaller
    EntityDescriptorMarshaller marshaller = new EntityDescriptorMarshaller();

    // Marshall the Subject
    Element assertionElement = marshaller.marshall(ed);

    logger.info(net.shibboleth.utilities.java.support.xml.SerializeSupport.nodeToString(assertionElement));
}

From source file:blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable.java

public Set<Connection> genConnBlockstate() {
    Set<Connection> conns = ImmersiveNetHandler.INSTANCE.getConnections(world, pos);
    if (conns == null)
        return ImmutableSet.of();
    Set<Connection> ret = new HashSet<Connection>() {
        @Override// w  w  w. j a v a  2s . c o m
        public boolean equals(Object o) {
            if (o == this)
                return true;
            if (!(o instanceof HashSet))
                return false;
            HashSet<Connection> other = (HashSet<Connection>) o;
            if (other.size() != this.size())
                return false;
            for (Connection c : this)
                if (!other.contains(c))
                    return false;
            return true;
        }
    };
    //TODO thread safety!
    for (Connection c : conns) {
        IImmersiveConnectable end = ApiUtils.toIIC(c.end, world, false);
        if (end == null)
            continue;
        // generate subvertices
        c.getSubVertices(world);
        ret.add(c);
    }

    return ret;
}

From source file:com.github.alexfalappa.nbspringboot.projects.initializr.BootDependenciesPanel.java

void setSelectedDependencies(List<String> deps) {
    HashSet<String> hs = new HashSet<>(deps);
    for (List<JCheckBox> chList : chkBoxesMap.values()) {
        for (JCheckBox cb : chList) {
            cb.setSelected(hs.contains(cb.getName()));
        }//from   ww  w. ja  v  a 2s  .c o m
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.web.jsptags.OptionsForPropertyTag.java

private List<Individual> removeIndividualsAlreadyInRange(List<Individual> indiviuals,
        List<ObjectPropertyStatement> stmts) {
    log.trace(/* w w w  . j a v a 2  s.c om*/
            "starting to check for duplicate range individuals in OptionsForPropertyTag.removeIndividualsAlreadyInRange() ...");
    HashSet<String> range = new HashSet<String>();

    for (ObjectPropertyStatement ops : stmts) {
        if (ops.getPropertyURI().equals(getPredicateUri()))
            range.add(ops.getObjectURI());
    }

    int removeCount = 0;
    ListIterator<Individual> it = indiviuals.listIterator();
    while (it.hasNext()) {
        Individual ind = it.next();
        if (range.contains(ind.getURI())) {
            it.remove();
            ++removeCount;
        }
    }
    log.trace("removed " + removeCount + " duplicate range individuals");
    return indiviuals;
}

From source file:com.googlesource.gerrit.plugins.github.wizard.AccountController.java

private void setAccoutPublicKeys(IdentifiedUser user, GitHubLogin hubLogin, HttpServletRequest req)
        throws IOException {
    GHMyself myself = hubLogin.getMyself();
    List<GHVerifiedKey> githubKeys = myself.getPublicVerifiedKeys();
    HashSet<String> gerritKeys = Sets.newHashSet(getCurrentGerritSshKeys(user));
    for (GHKey ghKey : githubKeys) {
        String sshKeyCheckedParam = "key_check_" + ghKey.getId();
        String sshKeyWithLabel = ghKey.getKey() + " " + ghKey.getTitle();
        String checked = req.getParameter(sshKeyCheckedParam);
        if (checked != null && checked.equalsIgnoreCase("on") && !gerritKeys.contains(ghKey.getKey())) {
            addSshKey(user, sshKeyWithLabel);
            gerritKeys.add(ghKey.getKey());
        }//from  www. java  2 s  .  c  o  m
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.listing.PropertyWebappsListingController.java

public void doGet(HttpServletRequest request, HttpServletResponse response) {
    if (!isAuthorizedToDisplayPage(request, response, SimplePermission.EDIT_ONTOLOGY.ACTIONS)) {
        return;/*from w ww .  ja v a 2 s.c  o  m*/
    }

    VitroRequest vrequest = new VitroRequest(request);

    String noResultsMsgStr = "No object properties found";

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

    ObjectPropertyDao dao = vrequest.getFullWebappDaoFactory().getObjectPropertyDao();
    PropertyInstanceDao piDao = vrequest.getFullWebappDaoFactory().getPropertyInstanceDao();
    VClassDao vcDao = vrequest.getFullWebappDaoFactory().getVClassDao();
    PropertyGroupDao pgDao = vrequest.getFullWebappDaoFactory().getPropertyGroupDao();

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

    List props = new ArrayList();
    if (request.getParameter("propsForClass") != null) {
        noResultsMsgStr = "There are no 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 propInstIt = propInsts.iterator();
        HashSet propURIs = new HashSet();
        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 = (request.getParameter("iffRoot") != null) ? dao.getRootObjectProperties()
                : dao.getAllObjectProperties();
    }

    OntologyDao oDao = vrequest.getFullWebappDaoFactory().getOntologyDao();
    HashMap<String, String> ontologyHash = new HashMap<String, String>();

    Iterator propIt = props.iterator();
    List<ObjectProperty> scratch = new ArrayList();
    while (propIt.hasNext()) {
        ObjectProperty p = (ObjectProperty) propIt.next();
        if (p.getNamespace() != null) {
            if (!ontologyHash.containsKey(p.getNamespace())) {
                Ontology o = (Ontology) 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) {
        Collections.sort(props, new ObjectPropertyHierarchyListingController.ObjectPropertyAlphaComparator());
    }

    ArrayList results = new ArrayList();
    results.add("XX"); // column 1
    results.add("property public name"); // column 2
    results.add("prefix + local name"); // column 3
    results.add("domain"); // column 4
    results.add("range"); // column 5
    results.add("group"); // column 6
    results.add("display tier"); // column 7
    results.add("display level"); // column 8
    results.add("update level"); // column 9

    if (props != null) {
        if (props.size() == 0) {
            results.add("XX");
            results.add("<strong>" + noResultsMsgStr + "</strong>");
            results.add("");
            results.add("");
            results.add("");
            results.add("");
            results.add("");
            results.add("");
            results.add("");
        } else {
            Iterator propsIt = props.iterator();
            while (propsIt.hasNext()) {
                ObjectProperty prop = (ObjectProperty) propsIt.next();
                results.add("XX");

                String propNameStr = ObjectPropertyHierarchyListingController.getDisplayLabel(prop);
                try {
                    results.add("<a href=\"./propertyEdit?uri=" + URLEncoder.encode(prop.getURI(), "UTF-8")
                            + "\">" + propNameStr + "</a>"); // column 1
                } catch (Exception e) {
                    results.add(propNameStr); // column 2
                }

                results.add(prop.getLocalNameWithPrefix()); // column 3

                VClass vc = (prop.getDomainVClassURI() != null)
                        ? vcDao.getVClassByURI(prop.getDomainVClassURI())
                        : null;
                String domainStr = (vc != null) ? vc.getLocalNameWithPrefix() : "";
                results.add(domainStr); // column 4

                vc = (prop.getRangeVClassURI() != null) ? vcDao.getVClassByURI(prop.getRangeVClassURI()) : null;
                String rangeStr = (vc != null) ? vc.getLocalNameWithPrefix() : "";
                results.add(rangeStr); // column 5

                if (prop.getGroupURI() != null) {
                    PropertyGroup pGroup = pgDao.getGroupByURI(prop.getGroupURI());
                    results.add(pGroup == null ? "unknown group" : pGroup.getName()); // column 6
                } else {
                    results.add("unspecified");
                }
                if (prop.getDomainDisplayTierInteger() != null) {
                    results.add(Integer.toString(prop.getDomainDisplayTierInteger(), BASE_10)); // column 7
                } else {
                    results.add(""); // column 7
                }
                results.add(prop.getHiddenFromDisplayBelowRoleLevel() == null ? "(unspecified)"
                        : prop.getHiddenFromDisplayBelowRoleLevel().getShorthand()); // column 8
                results.add(prop.getProhibitedFromUpdateBelowRoleLevel() == null ? "(unspecified)"
                        : prop.getProhibitedFromUpdateBelowRoleLevel().getShorthand()); // column 9
            }
        }
        request.setAttribute("results", results);
    }

    request.setAttribute("columncount", new Integer(NUM_COLS));
    request.setAttribute("suppressquery", "true");
    request.setAttribute("title", "Object Properties");
    request.setAttribute("bodyJsp", Controllers.HORIZONTAL_JSP);

    // new way of adding more than one button
    List<ButtonForm> buttons = new ArrayList<ButtonForm>();
    HashMap<String, String> newPropParams = new HashMap<String, String>();
    newPropParams.put("controller", "Property");
    ButtonForm newPropButton = new ButtonForm(Controllers.RETRY_URL, "buttonForm", "Add new object property",
            newPropParams);
    buttons.add(newPropButton);
    HashMap<String, String> rootPropParams = new HashMap<String, String>();
    rootPropParams.put("iffRoot", "true");
    String temp;
    if ((temp = vrequest.getParameter("ontologyUri")) != null) {
        rootPropParams.put("ontologyUri", temp);
    }
    ButtonForm rootPropButton = new ButtonForm("showObjectPropertyHierarchy", "buttonForm", "root properties",
            rootPropParams);
    buttons.add(rootPropButton);
    request.setAttribute("topButtons", buttons);

    /* original way of adding 1 button
    request.setAttribute("horizontalJspAddButtonUrl", Controllers.RETRY_URL);
    request.setAttribute("horizontalJspAddButtonText", "Add new object property");
    request.setAttribute("horizontalJspAddButtonControllerParam", "Property");
    */
    RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
    try {
        rd.forward(request, response);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:com.boundary.plugin.sdk.jmx.MBeansTransformer.java

/**
 * Iterates over the attributes of an MBean
 * @param name {@link ObjectName}//from  w w  w  .  ja va  2 s  . com
 */
private void traverseAttributes(ObjectName name) {
    MBeanServerConnection connection = this.client.getMBeanServerConnection();
    MBeanInfo info;
    HashSet<String> checkTypes = new HashSet<String>();
    checkTypes.add("long");
    checkTypes.add("int");
    checkTypes.add("javax.management.openmbean.CompositeData");
    checkTypes.add("[Ljavax.management.openmbean.CompositeData;");
    try {
        info = connection.getMBeanInfo(name);
        MBeanAttributeInfo[] attributes = info.getAttributes();
        for (MBeanAttributeInfo attrInfo : attributes) {
            if (checkTypes.contains(attrInfo.getType())) {
                transform.beginAttribute(name, attrInfo);
                transform.endAttribute();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.github.alexfalappa.nbspringboot.projects.initializr.BootDependenciesPanel.java

void setSelectedDependenciesString(String deps) {
    HashSet<String> hs = new HashSet<>(Arrays.asList(deps.split(",")));
    for (List<JCheckBox> chList : chkBoxesMap.values()) {
        for (JCheckBox cb : chList) {
            cb.setSelected(hs.contains(cb.getName()));
        }/*from www  . j ava 2 s .  c  o m*/
    }
}

From source file:biomine.bmvis2.pipeline.EdgeGoodnessHider.java

public void doOperation(VisualGraph g) throws GraphOperationException {
    HashSet<VisualEdge> hiddenEdges = new HashSet<VisualEdge>();
    hiddenEdges.addAll(g.getHiddenEdges());
    for (VisualEdge e : g.getAllEdges()) {
        if (e.getGoodness() < limit) {
            hiddenEdges.add(e);/*  w ww .j av  a  2 s. co m*/
        }
    }
    ArrayList<VisualNode> hiddenNodes = new ArrayList();
    for (VisualNode n : g.getNodes()) {
        int edgeCount = 0;
        for (VisualEdge e : n.getEdges()) {
            if (!hiddenEdges.contains(e))
                edgeCount++;
        }
        if (edgeCount == 0) {
            hiddenNodes.add(n);
        }
    }
    g.hideNodes(hiddenNodes);
    g.hideEdges(hiddenEdges);
    System.out.println("edgeGoodness update!");
}

From source file:edu.ku.brc.af.core.SchemaI18NService.java

/**
 * @param includeSepLocale/*from  ww  w  . j a  v  a 2s .c  o  m*/
 * @return
 */
public Vector<Locale> getStdLocaleList(final boolean includeSepLocale) {
    /*for (Locale l : locales)
    {
    System.out.println(String.format("%s - %s, %s, %s", l.getDisplayName(), l.getLanguage(), l.getCountry(), l.getVariant()));
    }*/

    Vector<Locale> freqLocales = new Vector<Locale>();
    int i = 0;
    while (i < priorityLocales.length) {
        String lang = priorityLocales[i++];
        String ctry = priorityLocales[i++];
        String vari = priorityLocales[i++];
        Locale l = getLocaleByLangCountry(lang, ctry, vari);
        if (l != null) {
            freqLocales.add(l);
        }
    }
    HashSet<String> freqSet = new HashSet<String>();
    for (Locale l : freqLocales) {
        freqSet.add(l.getDisplayName());
    }
    Vector<Locale> stdLocaleList = new Vector<Locale>();
    for (Locale l : locales) {
        if (!freqSet.contains(l.getDisplayName())) {
            stdLocaleList.add(l);
        }
    }

    if (includeSepLocale) {
        stdLocaleList.insertElementAt(new Locale("-", "-", "-"), 0);
    }

    for (i = freqLocales.size() - 1; i > -1; i--) {
        stdLocaleList.insertElementAt(freqLocales.get(i), 0);
    }
    return stdLocaleList;
}