Example usage for java.util Set size

List of usage examples for java.util Set size

Introduction

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

Prototype

int size();

Source Link

Document

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

Usage

From source file:ddf.security.PropertiesLoader.java

@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> toMap(Properties properties) {
    if (properties != null) {
        final Set<Map.Entry<Object, Object>> entries = properties.entrySet();
        Map<K, V> map = new HashMap<K, V>(entries.size() * 2);
        for (Map.Entry<Object, Object> entry : entries) {
            map.put((K) entry.getKey(), (V) entry.getValue());
        }/*from ww  w.  j ava  2  s.  c om*/

        return map;
    }
    return new HashMap<K, V>();
}

From source file:hudson.security.PAMSecurityRealm.java

private static GrantedAuthority[] toAuthorities(UnixUser u) {
    Set<String> grps = u.getGroups();
    GrantedAuthority[] groups = new GrantedAuthority[grps.size() + 1];
    int i = 0;/*www .jav a2  s  . c  om*/
    for (String g : grps)
        groups[i++] = new GrantedAuthorityImpl(g);
    groups[i++] = AUTHENTICATED_AUTHORITY;
    return groups;
}

From source file:hudson.matrix.MatrixTest.java

private static void expectRejection(MatrixProject project, String combinationFilter, String signature)
        throws IOException {
    ScriptApproval scriptApproval = ScriptApproval.get();
    assertEquals(Collections.emptySet(), scriptApproval.getPendingSignatures());
    try {//from   w w  w  .  ja v  a2 s.c  o m
        project.setCombinationFilter(combinationFilter);
    } catch (RejectedAccessException x) {
        assertEquals(Functions.printThrowable(x), signature, x.getSignature());
    }
    Set<ScriptApproval.PendingSignature> pendingSignatures = scriptApproval.getPendingSignatures();
    assertEquals(1, pendingSignatures.size());
    assertEquals(signature, pendingSignatures.iterator().next().signature);
    scriptApproval.approveSignature(signature);
    assertEquals(Collections.emptySet(), scriptApproval.getPendingSignatures());
}

From source file:com.github.nakamurakj.validator.BeanValidator.java

/**
 * javax.validation????Bean?Validation?//from w  w  w . jav  a2 s .co m
 *
 * @param bean ?Bean
 * @return {@code ValidateMessage}?
 * @throws IllegalArgumentException 
 */
public static <T> List<ValidateMessage<T>> validateBean(final T bean) throws IllegalArgumentException {
    if (bean == null) {
        throw new IllegalArgumentException("bean is null");
    }

    final Set<ConstraintViolation<T>> constraintViolations = getValidator().validate(bean);
    final int size = constraintViolations.size();
    final List<ValidateMessage<T>> messages = new ArrayList<ValidateMessage<T>>(size);
    if (size > 0) {
        final Iterator<ConstraintViolation<T>> ite = constraintViolations.iterator();
        while (ite.hasNext()) {
            messages.add(new ValidateMessage<T>(ite.next()));
        }
    }
    return messages;
}

From source file:com.dell.asm.asmcore.asmmanager.util.DeviceGroupUtil.java

/**
 * Validate Users/* ww w  . j  a v a2  s  . c  o m*/
 * 
 * @param entity - device group entity to be validated
 * 
 * @throws AsmManagerCheckedException
 */
public static void validateUserObject(DeviceGroupEntity entity) throws AsmManagerCheckedException {

    Set<Long> invalidUserIds = invalidGroupUserIds(entity);

    if (invalidUserIds.size() > 0) {
        throw new AsmManagerCheckedException(AsmManagerCheckedException.REASON_CODE.INVALID_ID,
                AsmManagerMessages.userIdsNotFound(invalidUserIds.toString()));
    }

}

From source file:com.nesscomputing.syslog4j.Syslog.java

/**
 * shutdown() gracefully shuts down all defined Syslog protocols,
 * which includes flushing all queues and connections and finally
 * clearing all instances (including those initialized by default).
 *///from  w  ww . j av a2 s . c o  m
public synchronized static void shutdown() {
    Set<String> protocols = instances.keySet();

    if (protocols.size() > 0) {
        Iterator<String> i = protocols.iterator();

        SyslogUtility.sleep(SyslogConstants.THREAD_LOOP_INTERVAL_DEFAULT);

        while (i.hasNext()) {
            String protocol = i.next();

            SyslogIF syslog = instances.get(protocol);

            syslog.shutdown();
        }

        instances.clear();
    }
}

From source file:edu.wpi.checksims.testutil.AlgorithmUtils.java

/**
 * Ensure that every pair in a set of pairs is representing in algorithm results
 *
 * @param results Collection of algorithm results to check in
 * @param pairs Pairs of submissions to search for in the results
 *///from  www.j  ava  2s  .  co m
public static void checkResultsContainsPairs(Collection<AlgorithmResults> results,
        Set<Pair<Submission, Submission>> pairs) {
    assertNotNull(results);
    assertNotNull(pairs);

    assertEquals(results.size(), pairs.size());

    for (Pair<Submission, Submission> pair : pairs) {
        long numWithResult = results.stream().filter((result) -> {
            return (result.a.equals(pair.getLeft()) && result.b.equals(pair.getRight()))
                    || (result.a.equals(pair.getRight()) && result.b.equals(pair.getLeft()));
        }).count();

        assertEquals(1, numWithResult);
    }
}

From source file:com.dell.asm.asmcore.asmmanager.util.DeviceGroupUtil.java

/**
 * Delete association between device group users by ids
 * /*from   ww w  .ja  v a 2 s.  co  m*/
 * @param ids - set of user ids
 * 
 * @throws AsmManagerCheckedException
 */
public static void deleteGroupUsersAssociationFromDB(Set<Long> ids) throws AsmManagerCheckedException {

    if (null == ids || ids.size() <= 0)
        return;
    DeviceGroupDAO.getInstance().deleteGroupUsersAssociation(ids);
}

From source file:org.eclipse.virgo.ide.jdt.internal.core.classpath.ServerClasspathContainerUpdateJob.java

/**
 * Helper method to schedule a new {@link ServerClasspathContainerUpdateJob}
 * ./*from   w  w w.j a v  a 2  s .  c om*/
 * 
 * @param javaProject
 *            the {@link IJavaProject} the class path container should be
 *            updated for
 * @param types
 *            the change types of the manifest
 */
public static void scheduleClasspathContainerUpdateJob(IJavaProject javaProject, Set<Type> types) {
    if (javaProject != null && !SCHEDULED_PROJECTS.contains(javaProject) && types.size() > 0
            && ClasspathUtils.hasClasspathContainer(javaProject)) {
        newClasspathContainerUpdateJob(javaProject, types);
    }
}

From source file:edu.snu.dolphin.dnn.util.NeuralNetworkUtils.java

/**
 * De-serializes a set of serialized layer configurations to an array of layer configurations.
 * @param configurationSerializer a configuration serializer to deserialize the specified configuration set.
 * @param serializedLayerConfSet a set of serialized layer configurations.
 * @return an array of layer configurations.
 *//*from   w w  w.j  a  v  a 2 s .com*/
public static Configuration[] deserializeLayerConfSetToArray(
        final ConfigurationSerializer configurationSerializer, final Set<String> serializedLayerConfSet) {
    final Configuration[] layerConfigurations = new Configuration[serializedLayerConfSet.size()];
    for (final String serializedLayerConfiguration : serializedLayerConfSet) {
        try {
            final Configuration layerConfiguration = configurationSerializer
                    .fromString(serializedLayerConfiguration);
            final int index = Tang.Factory.getTang().newInjector(layerConfiguration)
                    .getNamedInstance(LayerConfigurationParameters.LayerIndex.class);
            layerConfigurations[index] = layerConfiguration;
        } catch (final IOException exception) {
            throw new RuntimeException("IOException while de-serializing layer configuration", exception);
        } catch (final InjectionException exception) {
            throw new RuntimeException("InjectionException", exception);
        }
    }
    return layerConfigurations;
}