Example usage for java.util HashSet size

List of usage examples for java.util HashSet size

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

From source file:com.l2jfree.gameserver.model.skills.effects.templates.EffectTemplate.java

/**
 * Support for improved buffs, in case it gets overwritten in DP
 * //  w w w . j  ava 2 s  . co m
 * @param skill
 * @param template
 * @return
 */
public boolean merge(L2Skill skill, EffectTemplate template) {
    if (!name.equals(template.name))
        return false;

    if (lambda != 0 || template.lambda != 0)
        return false;

    if (count != template.count || period != template.period)
        return false;

    if (effectPower != template.effectPower || effectType != template.effectType)
        return false;

    if (triggeredSkill != null || template.triggeredSkill != null)
        return false;

    if (chanceCondition != null || template.chanceCondition != null)
        return false;

    abnormalEffect |= template.abnormalEffect;
    specialEffect |= template.specialEffect;

    final HashSet<String> tmp = new HashSet<String>();

    for (String s : stackTypes)
        tmp.add(s);

    for (String s : template.stackTypes)
        tmp.add(s);

    stackTypes = tmp.toArray(new String[tmp.size()]);
    stackOrder = 99;

    showIcon = showIcon || template.showIcon;

    for (FuncTemplate f : template.funcTemplates)
        attach(f);

    _log.info("Effect templates merged for " + skill);
    return true;
}

From source file:org.apache.james.smtpserver.fastfail.URIRBLHandler.java

/**
 * Recursively scans all MimeParts of an email for domain strings. Domain
 * strings that are found are added to the supplied HashSet.
 * /* w  w  w . ja  v a  2 s .  c o m*/
 * @param part
 *            MimePart to scan
 * @param session
 *            not null
 * @return domains The HashSet that contains the domains which were
 *         extracted
 */
private HashSet<String> scanMailForDomains(MimePart part, SMTPSession session)
        throws MessagingException, IOException {
    HashSet<String> domains = new HashSet<String>();
    session.getLogger().debug("mime type is: \"" + part.getContentType() + "\"");

    if (part.isMimeType("text/plain") || part.isMimeType("text/html")) {
        session.getLogger().debug("scanning: \"" + part.getContent().toString() + "\"");
        HashSet<String> newDom = URIScanner.scanContentForDomains(domains, part.getContent().toString());

        // Check if new domains are found and add the domains
        if (newDom != null && newDom.size() > 0) {
            domains.addAll(newDom);
        }
    } else if (part.isMimeType("multipart/*")) {
        MimeMultipart multipart = (MimeMultipart) part.getContent();
        int count = multipart.getCount();
        session.getLogger().debug("multipart count is: " + count);

        for (int index = 0; index < count; index++) {
            session.getLogger().debug("recursing index: " + index);
            MimeBodyPart mimeBodyPart = (MimeBodyPart) multipart.getBodyPart(index);
            HashSet<String> newDomains = scanMailForDomains(mimeBodyPart, session);

            // Check if new domains are found and add the domains
            if (newDomains != null && newDomains.size() > 0) {
                domains.addAll(newDomains);
            }
        }
    }
    return domains;
}

From source file:com.vk.sdk.payments.VKPaymentsServerSender.java

private void requestSaveTransaction() {
    HashSet<String> purchases = VKPaymentsDatabase.getInstance(mAppCtx).getPurchases();

    final Runnable runnableSaveTransaction;
    if (purchases.size() > 0) {
        runnableSaveTransaction = new SaveTransactionRunnable(purchases);
    } else {//from   w  w  w  . j  a  va  2  s .co  m
        runnableSaveTransaction = null;
    }
    if (runnableSaveTransaction != null) {
        mHandler.post(runnableSaveTransaction);
    }
}

From source file:org.docrj.smartcard.reader.AppViewActivity.java

private void updateGroups(HashSet<String> appGroups) {
    String grpText = getString(R.string.none);
    if (appGroups.size() == 0) {
        if (!mReadOnly) {
            grpText += " - " + getString(R.string.edit_to_add_groups);
        }/* w w w.j a v a2 s.  com*/
    } else if (appGroups.size() == 1) {
        grpText = appGroups.toString().replaceAll("[\\[\\]]", "");
        ;
        if (!mReadOnly) {
            grpText += " - " + getString(R.string.edit_to_add_groups);
        }
    } else {
        grpText = appGroups.toString().replaceAll("[\\[\\]]", "");
        grpText = grpText.replace(", ", ",\n");
    }
    mGroups.setText(grpText);
}

From source file:hcm.ssj.creator.dialogs.AddDialog.java

/**
 * @param clazzes Class[]//w  w  w  . j a  v  a2  s .com
 */
public void setOption(ArrayList<Class> clazzes) {
    hashMap = new LinkedHashMap<>();
    //get each package once
    HashSet<Package> hashSet = new HashSet<>();
    for (Class clazz : clazzes) {
        hashSet.add(clazz.getPackage());
    }
    //only show last part of the package name
    String[] packages = new String[hashSet.size()];
    int count = 0;
    for (Package pack : hashSet) {
        String name = pack.getName();
        packages[count++] = name.substring(name.lastIndexOf(".") + 1);
    }
    //sort packages by name and add them to map
    Arrays.sort(packages);
    for (String name : packages) {
        hashMap.put(name, new ArrayList<Class>());
    }
    //sort classes by name
    Collections.sort(clazzes, new Comparator<Class>() {
        @Override
        public int compare(Class lhs, Class rhs) {
            return lhs.getSimpleName().compareTo(rhs.getSimpleName());
        }
    });
    //add every class to its corresponding package
    for (Class clazz : clazzes) {
        String name = clazz.getPackage().getName();
        hashMap.get(name.substring(name.lastIndexOf(".") + 1)).add(clazz);
    }
    //create internal variables to save the state of the list
    itemState = new boolean[hashMap.size()][];
    count = 0;
    allItems = 0;
    allItems += hashMap.size();
    for (Map.Entry<String, ArrayList<Class>> entry : hashMap.entrySet()) {
        itemState[count++] = new boolean[entry.getValue().size()];
        allItems += entry.getValue().size();
    }
}

From source file:org.apache.directory.server.core.authz.AuthorizationServiceAsAdminIT.java

/**
 * Makes sure the admin can see all entries we know of on a subtree search.
 *
 * @throws Exception if there are problems
 *//*from w  w w  . ja va2s.  c o m*/
@Test
public void testSearchSubtreeByAdmin() throws Exception {
    LdapConnection connection = getAdminConnection();

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

    EntryCursor cursor = connection.search("ou=system", "(objectClass=*)", SearchScope.SUBTREE, "*");

    while (cursor.next()) {
        Entry result = cursor.get();
        set.add(result.getDn().getName());
    }

    cursor.close();

    assertEquals(10, set.size());
    assertTrue(set.contains("ou=system"));
    assertTrue(set.contains("ou=configuration,ou=system"));
    assertTrue(set.contains("ou=interceptors,ou=configuration,ou=system"));
    assertTrue(set.contains("ou=partitions,ou=configuration,ou=system"));
    assertTrue(set.contains("ou=services,ou=configuration,ou=system"));
    assertTrue(set.contains("ou=groups,ou=system"));
    assertTrue(set.contains("cn=Administrators,ou=groups,ou=system"));
    assertTrue(set.contains("ou=users,ou=system"));
    assertTrue(set.contains("prefNodeName=sysPrefRoot,ou=system"));
    assertTrue(set.contains("uid=admin,ou=system"));
}

From source file:org.entrystore.rest.util.jdil.JDIL.java

public JSONObject exportGraphToJDIL(Graph graph, Resource root) {
    try {/*from w  w w .  j a v  a 2 s.  co m*/
        HashMap<Resource, JSONObject> res2Jdil = new HashMap<Resource, JSONObject>();
        HashSet<Resource> notRoots = new HashSet<Resource>();

        for (Statement statement : graph) {
            JSONObject subj = getOrCreateSubject(statement.getSubject(), res2Jdil);
            String predicate = namespaces.abbreviate(statement.getPredicate().stringValue());
            notRoots.add(statement.getPredicate());
            Value value = statement.getObject();

            if (value instanceof Resource) {
                /*
                 * Create a new JDIL value to accumulate to the subject.
                 */
                JSONObject JDILValueObject = getOrCreateObject((Resource) value, res2Jdil);

                subj.accumulate(predicate, JDILValueObject);
                notRoots.add((Resource) value);

            } else {
                Literal lit = (Literal) value;
                String language = lit.getLanguage();
                URI datatype = lit.getDatatype();
                JSONObject object = new JSONObject();
                object.accumulate("@value", value.stringValue());
                if (language != null) {
                    object.accumulate("@language", language);
                } else if (datatype != null) {
                    object.accumulate("@datatype", datatype.stringValue());
                }
                subj.accumulate(predicate, object);
            }
        }
        if (root != null) {
            JSONObject obj = res2Jdil.get(root);
            cutLoops(obj, new HashSet());
            return obj;
        }
        HashSet<Resource> roots = new HashSet<Resource>(res2Jdil.keySet());
        roots.removeAll(notRoots);
        if (roots.size() == 1) {
            JSONObject obj = res2Jdil.get(roots.iterator().next());
            cutLoops(obj, new HashSet());
            return obj;
        }
    } catch (JSONException jse) {
        log.error(jse.getMessage());
    }
    return null;
}

From source file:com.haulmont.timesheets.global.ValidationTools.java

public ResultAndCause validateTags(TimeEntryBase timeEntry) {
    Preconditions.checkNotNullArgument(timeEntry);
    Preconditions.checkNotNullArgument(timeEntry.getTask());
    Preconditions.checkNotNullArgument(timeEntry.getTask().getRequiredTagTypes());

    HashSet<TagType> remainingRequiredTagTypes = new HashSet<>(timeEntry.getTask().getRequiredTagTypes());
    if (CollectionUtils.isNotEmpty(timeEntry.getTags())) {
        for (Tag tag : timeEntry.getTags()) {
            remainingRequiredTagTypes.remove(tag.getTagType());
        }//  www.  j a  v  a2s.  c om
    }

    if (remainingRequiredTagTypes.size() > 0) {
        StringBuilder stringBuilder = new StringBuilder();
        for (TagType remainingRequiredTagType : remainingRequiredTagTypes) {
            stringBuilder.append(remainingRequiredTagType.getName()).append(",");
        }
        if (stringBuilder.length() > 0) {
            stringBuilder.deleteCharAt(stringBuilder.length() - 1);//remove last comma
        }

        return ResultAndCause.negative(
                messages.formatMessage(getClass(), "notification.requiredTagTypesNotPresent", stringBuilder));
    }

    return ResultAndCause.positive();
}

From source file:org.cloudgraph.hbase.mutation.Update.java

private void collectSingular(EdgeWriter edgeWriter, PlasmaDataObject dataObject,
        HashSet<PlasmaDataObject> oldValues, PlasmaProperty property, Object value) throws IOException {

    PlasmaNode dataNode = (PlasmaNode) dataObject;
    List<PlasmaEdge> edges = dataNode.getEdges(property);

    PlasmaDataObject oldDataObject = null;
    if (oldValues.size() > 0) {
        if (oldValues.size() == 1) {
            oldDataObject = (PlasmaDataObject) oldValues.iterator().next();
        } else//  ww  w  .  j  a v  a  2  s . co m
            throw new GraphServiceException(
                    "unexpected List as old value for property, " + property.toString());
    }
    // if has a new value
    PlasmaDataObject newDataObject = null;
    if (value != null) {
        PlasmaEdge edge = edges.get(0);

        newDataObject = edge.getOpposite(dataNode).getDataObject();
        if (oldDataObject != null)
            edgeWriter.replace(oldDataObject, newDataObject);
        else
            // add the new one
            edgeWriter.add(newDataObject);
    } else {
        if (oldDataObject != null)
            edgeWriter.remove(oldDataObject);
    }
}

From source file:org.cloudgraph.hbase.mutation.Update.java

private void collectMulti(EdgeWriter edgeWriter, PlasmaDataObject dataObject,
        HashSet<PlasmaDataObject> oldValues, PlasmaProperty property, Object value) throws IOException {

    PlasmaNode dataNode = (PlasmaNode) dataObject;
    List<PlasmaEdge> updatedEdges = dataNode.getEdges(property);
    if (log.isDebugEnabled())
        log.debug("merging " + String.valueOf(oldValues.size()) + " old and "
                + String.valueOf(updatedEdges.size()) + " current values");
    edgeWriter.merge(dataNode, oldValues, updatedEdges);
}