Example usage for java.util Set hashCode

List of usage examples for java.util Set hashCode

Introduction

In this page you can find the example usage for java.util Set hashCode.

Prototype

int hashCode();

Source Link

Document

Returns the hash code value for this set.

Usage

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set<String> set = new HashSet<String>(Arrays.asList(elements));

    System.out.println(set.hashCode());

}

From source file:io.seldon.memcache.MemCacheKeys.java

public static String getExplicitItemsIncluderKey(String client, Set<Long> items) {
    return "" + keys.ExplicitItemsIncluder + ":" + client + ":" + items.hashCode();
}

From source file:Main.java

static <E> Set<E> ungrowableSet(final Set<E> s) {
    return new Set<E>() {

        @Override//  w  ww.  j  ava2s. c o  m
        public int size() {
            return s.size();
        }

        @Override
        public boolean isEmpty() {
            return s.isEmpty();
        }

        @Override
        public boolean contains(Object o) {
            return s.contains(o);
        }

        @Override
        public Object[] toArray() {
            return s.toArray();
        }

        @Override
        public <T> T[] toArray(T[] a) {
            return s.toArray(a);
        }

        @Override
        public String toString() {
            return s.toString();
        }

        @Override
        public Iterator<E> iterator() {
            return s.iterator();
        }

        @Override
        public boolean equals(Object o) {
            return s.equals(o);
        }

        @Override
        public int hashCode() {
            return s.hashCode();
        }

        @Override
        public void clear() {
            s.clear();
        }

        @Override
        public boolean remove(Object o) {
            return s.remove(o);
        }

        @Override
        public boolean containsAll(Collection<?> coll) {
            return s.containsAll(coll);
        }

        @Override
        public boolean removeAll(Collection<?> coll) {
            return s.removeAll(coll);
        }

        @Override
        public boolean retainAll(Collection<?> coll) {
            return s.retainAll(coll);
        }

        @Override
        public boolean add(E o) {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean addAll(Collection<? extends E> coll) {
            throw new UnsupportedOperationException();
        }

    };

}

From source file:org.jasig.cas.support.oauth.token.registry.JpaTokenRegistry.java

@Override
public <T extends Token> Boolean isToken(final TokenType type, final String clientId, final String principalId,
        final Set<String> scopes, final Class<T> clazz) {
    Assert.notNull(clientId, "clientId cannot be null");
    Assert.notNull(principalId, "principalId cannot be null");
    Assert.notNull(scopes, "scopes cannot be null");
    Assert.notNull(clazz, "clazz cannot be null");

    final Class<T> clazzImpl = getClassImplementation(clazz);
    final Collection<T> tokens;
    try {/*w  w  w  .  ja va2  s .com*/
        if (type == null) {
            tokens = entityManager.createQuery("select t from " + clazzImpl.getSimpleName() + " t "
                    + "where t.clientId = :clientId and t.principalId = :principalId and t.scopesHash = :scopesHash",
                    clazzImpl).setParameter("clientId", clientId).setParameter("principalId", principalId)
                    .setParameter("scopesHash", scopes.hashCode()).getResultList();
        } else {
            tokens = entityManager.createQuery("select t from " + clazzImpl.getSimpleName() + " t "
                    + "where t.type = :type and t.clientId = :clientId and t.principalId = :principalId "
                    + "and t.scopesHash = :scopesHash", clazzImpl).setParameter("type", type)
                    .setParameter("clientId", clientId).setParameter("principalId", principalId)
                    .setParameter("scopesHash", scopes.hashCode()).getResultList();
        }
    } catch (final NoResultException e) {
        return Boolean.FALSE;
    }

    for (final Token token : tokens) {
        if (!token.getTicket().isExpired()) {
            return Boolean.TRUE;
        }
    }

    return Boolean.FALSE;
}

From source file:com.google.gwt.emultest.java.util.TreeSetTest.java

/**
 * Test method for 'java.lang.Object.hashCode()'.
 *
 * @see java.util.Set#hashCode()//from  w w  w .jav a2  s.c o  m
 */
public void testHashCode() {
    Set<E> set0 = createSet();
    Set<E> set1 = createSet();

    int hashCode0 = set0.hashCode();
    int hashCode1 = set1.hashCode();
    assertTrue("empty maps have different hash codes", hashCode0 == hashCode1);

    // Check that hashCode changes
    set0.add(getKeys()[0]);
    hashCode0 = set0.hashCode();
    assertTrue("hash code didn't change", hashCode0 != hashCode1);

    Set<String> set2 = new TreeSet<String>();
    set2.add("");
    Set<Integer> set3 = new TreeSet<Integer>();
    set3.add(0);
    int hashCode2 = set2.hashCode();
    int hashCode3 = set3.hashCode();
    assertEquals("empty string/0 hash codes not the same", hashCode2, hashCode3);
}

From source file:org.apache.maven.graph.effective.EProjectCycle.java

@Override
public int hashCode() {
    final Set<ProjectRelationship<?>> cycle = new HashSet<ProjectRelationship<?>>(this.participants);
    final int prime = 31;
    int result = 1;
    result = prime * result + ((cycle == null) ? 0 : cycle.hashCode());
    return result;
}

From source file:org.jahia.services.render.filter.cache.AclCacheKeyPartGenerator.java

/**
 * Get all PrincipalAcl that applies to the current user. The first one of the list is the ACL that applies
 * directly on the current user, the following ones are the ACLs that applies on his groups.
 * @param principal The user/*  w w  w  . jav  a2 s.c  o m*/
 * @return List of PrincipalAcl
 * @throws RepositoryException
 */
private String getGroupsSignature(JahiaUser principal) throws RepositoryException {
    if (principal.isRoot()) {
        return "u:" + principal.getName();
    }

    SortedSet<String> principals = new TreeSet<>();
    Set<String> all = getAllPrincipalsWithAcl();
    addPrincipalIfAcl(principals, all, "u:" + principal.getName());

    List<String> groups = groupManagerService.getMembershipByPath(principal.getLocalPath());
    for (String group : groups) {
        addPrincipalIfAcl(principals, all, "g:" + StringUtils.substringAfterLast(group, "/"));
    }

    // Adds the hashcode of all list to ensure the key is generated with same set of principals having ACE
    return Integer.toString(all.hashCode()) + principals;
}

From source file:org.mindswap.swoop.renderer.entity.ConciseFormatEntityRenderer.java

public void printRepairSOS(Set explanationSet, OWLNamedObject entity, boolean enableHighlights,
        RepairFrame repair) {//w ww.  j  ava  2s  . c  o  m

    Set strikeSet = new HashSet();
    String insFont = "<FONT FACE=\"" + swoopModel.getFontFace() + "\" SIZE=3>";
    String tab = "_____"; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    try {
        if (explanationSet != null && !explanationSet.isEmpty()) {

            println("<b>Axioms causing the problem:</b>");
            // need to sort axioms to explain trace better
            Iterator i = explanationSet.iterator();
            // create instance of object container to check contents of axiom
            OWLObjectContainer owlCont = null;
            owlCont = new OWLObjectContainer(entity);

            Map LHSmap = new HashMap();
            Map RHSmap = new HashMap();
            Map objectCount = new HashMap();
            while (i.hasNext()) {
                OWLObject axiom = (OWLObject) i.next();
                owlCont.reset();
                // visit axiom
                owlCont.visit(axiom);
                // get contained objects, LHS and RHS of axiom
                List objects = owlCont.getContainedObjects();
                List LHS = owlCont.getLHS();
                List RHS = owlCont.getRHS();
                if (LHS.size() == 0 && RHS.size() == 0)
                    LHS = objects;
                LHSmap.put(axiom, LHS);
                RHSmap.put(axiom, RHS);
                List total = new ArrayList(LHS);
                total.addAll(RHS);
                updateCount(objectCount, total);
            }

            // highlight based on entity count
            if (enableHighlights) {
                for (Iterator iter = objectCount.keySet().iterator(); iter.hasNext();) {
                    URI objURI = (URI) iter.next();
                    String valStr = objectCount.get(objURI).toString();
                    int val = Integer.parseInt(valStr);
                    // System.out.println(objURI + ":"+ val);
                    if (val == 1 && !((ConciseFormatVisitor) visitor).highlightMap.containsKey(objURI)) {
                        ((ConciseFormatVisitor) visitor).highlightMap.put(objURI,
                                "<strike><font color=\"red\">");
                        strikeSet.add(objURI);
                    }
                }
            }

            // now call sorting method after computing lhs/rhs of axioms
            URI baseURI = entity.getURI();

            int count = 1;
            sortLevelMap = new HashMap(); // reset map which stores links between sorted axioms in their resp level (recursive depth)
            print("</b><hr><table border=\"1\">");
            print("<tr><td>" + insFont + "<b>Erroneous Axioms</b></td><td>" + insFont
                    + "<b><a href=\":ARITY\">Arity</a></b></td><td>" + insFont
                    + "<b><a href=\":IMPACT\">Impact</a></b></td><td>" + insFont
                    + "<b><a href=\":USAGE\">Usage</a></b></td><td>" + insFont
                    + "<b><a href=\":RANK\">Rank</a></b></td>" + insFont + "<b>Status</b></td></tr>");
            do {
                List axioms = sortAxioms(baseURI, LHSmap, RHSmap, new HashSet(), 0);
                // now print sorted axiom list
                for (Iterator iter = axioms.iterator(); iter.hasNext();) {

                    OWLObject axiom = (OWLObject) iter.next();

                    if (repair.keptAxiomSet.contains(axiom))
                        print("<tr bgcolor=\"C3FDB8\"><td>");
                    else if (repair.removedAxiomSet.contains(axiom))
                        print("<tr bgcolor=\"FFDDDD\"><td>");
                    else
                        print("<tr><td>");
                    print(insFont);

                    int level = Integer.parseInt(sortLevelMap.get(axiom).toString());
                    print("<b>" + (count++) + ")</b> ");
                    for (int ctr = 0; ctr < level * 2; ctr++)
                        print("&nbsp;");
                    if (level > 0)
                        print("|_");

                    int arity = ((HashSet) repair.axiomUnsatClaMap.get(axiom)).size();
                    String color = "FFFFFF";
                    if (arity == 2)
                        color = "FFFF88";
                    else if (arity == 3)
                        color = "FFFF44";
                    else if (arity >= 4)
                        color = "FFFF22";
                    print("<font size = 3 style=\"BACKGROUND-COLOR:" + color + "\">");

                    printObject(axiom);
                    print("</td>");
                    //                   
                    String hash = String.valueOf(repair.axiomUnsatClaMap.get(axiom).hashCode());
                    repair.objectMap.put(hash, repair.axiomUnsatClaMap.get(axiom));
                    print("<td>" + insFont + "<a href=\":HASH:Arity:" + hash + "\">" + String.valueOf(arity)
                            + "</a></td>");

                    int impact = 0;
                    Set impactSet = new HashSet();
                    if (repair.axiomSOSMap.containsKey(axiom))
                        impactSet = (HashSet) repair.axiomSOSMap.get(axiom);
                    impact = impactSet.size();
                    hash = String.valueOf(impactSet.hashCode());
                    repair.objectMap.put(hash, impactSet);
                    print("<td>" + insFont + "<a href=\":HASH:Impact:" + hash + "\">" + String.valueOf(impact)
                            + "</a></td>");

                    int usage = ((HashSet) repair.axiomUsageMap.get(axiom)).size();
                    hash = String.valueOf(repair.axiomUsageMap.get(axiom).hashCode());
                    repair.objectMap.put(hash, repair.axiomUsageMap.get(axiom));
                    print("<td>" + insFont + "<a href=\":HASH:Usage:" + hash + "\">" + String.valueOf(usage)
                            + "</a></td>");

                    String rank = "-";
                    if (repair.axiomRanksMap.containsKey(axiom))
                        rank = repair.axiomRanksMap.get(axiom).toString();
                    print("<td>" + insFont + rank + "</td>");

                    String rem = "R";
                    if (repair.removedAxiomSet.contains(axiom))
                        rem = "Undo";
                    print("<td>" + insFont + "<font color = \"red\">[<a href=\":FORCE:" + axiom.hashCode()
                            + "\">" + rem + "</a>]&nbsp;</font>");

                    String keep = "K";
                    if (repair.keptAxiomSet.contains(axiom))
                        keep = "Undo";
                    print(insFont + "<font color = \"green\">[<a href =\":BLOCK:" + axiom.hashCode() + "\">"
                            + keep + "</a>]&nbsp;</font></td>");
                    print("</tr>");

                    LHSmap.remove(axiom);
                    RHSmap.remove(axiom);
                }
                baseURI = null;
            } while ((count - 1) < explanationSet.size());
            print("</table>");
        }
        print("<hr>");
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        // clear highlight map of all strikes
        ((ConciseFormatVisitor) visitor).highlightMap.keySet().removeAll(strikeSet);
    }
}

From source file:org.onosproject.p4runtime.ctl.P4RuntimeClientImpl.java

@Override
public CompletableFuture<Collection<PiCounterCellData>> readCounterCells(Set<PiCounterCellId> cellIds,
        PiPipeconf pipeconf) {//from w  w  w  . j  a va  2s .  c o m
    return supplyInContext(() -> doReadCounterCells(cellIds, pipeconf),
            "readCounterCells-" + cellIds.hashCode());
}

From source file:org.onosproject.p4runtime.ctl.P4RuntimeClientImpl.java

@Override
public CompletableFuture<Collection<PiCounterCellData>> readAllCounterCells(Set<PiCounterId> counterIds,
        PiPipeconf pipeconf) {//w ww  . j a v a  2  s  . c  o m
    return supplyInContext(() -> doReadAllCounterCells(counterIds, pipeconf),
            "readAllCounterCells-" + counterIds.hashCode());
}