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:net.sf.morph.util.TransformerUtils.java

/**
 * Get the set of source classes available from the specified Transformer for the specified destination type.
 * @param transformer//from www  . ja  v  a 2 s.com
 * @param destinationType
 * @return Class[]
 */
public static Class[] getSourceClasses(Transformer transformer, Class destinationType) {
    if (!ClassUtils.inheritanceContains(transformer.getDestinationClasses(), destinationType)) {
        return CLASS_NONE;
    }
    Class[] sourceTypes = transformer.getSourceClasses();
    if (transformer instanceof ExplicitTransformer) {
        Set result = ContainerUtils.createOrderedSet();
        for (int i = 0; i < sourceTypes.length; i++) {
            if (((ExplicitTransformer) transformer).isTransformable(destinationType, sourceTypes[i])) {
                result.add(sourceTypes[i]);
            }
        }
        return result.isEmpty() ? CLASS_NONE : (Class[]) result.toArray(new Class[result.size()]);
    }
    return sourceTypes;
}

From source file:de.christianseipl.utilities.maputils.MapMath.java

/**
 * Erzeugt eine Map, deren Schlssel aus den bergebenen Werten bestehen und
 * auf die eine Transformationsfunktion angewendet wird, deren Verteilung
 * ebenfalls bergeben wird./*from  w  ww  .ja v a 2 s. c o m*/
 * 
 * @param <K>  ein beliebiger Objekttyp
 * @param <T> Ein von {@link Number} abgeleiteter Typ
 * @param _keys
 * @param _dist
 * @param _transformer
 * @return
 */
public static <K, T extends Number> Map<K, T> createWithSamples(Set<? extends K> _keys, StochasticDist<T> _dist,
        DistributionTransformer<K, T> _transformer) {
    Map<K, T> result = new HashMap<K, T>(_keys.size());
    for (K key : _keys) {
        result.put(key, _transformer.transform(key, _dist));
    }
    return result;
}

From source file:net.sf.jabref.model.DuplicateCheck.java

public static double compareEntriesStrictly(BibEntry one, BibEntry two) {
    Set<String> allFields = new HashSet<>();
    allFields.addAll(one.getFieldNames());
    allFields.addAll(two.getFieldNames());

    int score = 0;
    for (String field : allFields) {
        Optional<String> stringOne = one.getFieldOptional(field);
        Optional<String> stringTwo = two.getFieldOptional(field);
        if (stringOne.equals(stringTwo)) {
            score++;//from  w  w  w  .  j av a2  s. c om
        }
    }
    if (score == allFields.size()) {
        return 1.01; // Just to make sure we can
        // use score>1 without
        // trouble.
    }
    return (double) score / allFields.size();
}

From source file:net.sf.morph.util.TransformerUtils.java

/**
 * Get the set of destination classes available from the specified Transformer for the specified source type.
 * @param transformer//from  w  w w . j  a  va 2s.  c  o m
 * @param sourceType
 * @return Class[]
 * @since Morph 1.1
 */
public static Class[] getDestinationClasses(Transformer transformer, Class sourceType) {
    if (!ClassUtils.inheritanceContains(transformer.getSourceClasses(), sourceType)) {
        return CLASS_NONE;
    }
    Class[] destinationTypes = transformer.getDestinationClasses();
    if (transformer instanceof ExplicitTransformer) {
        Set result = ContainerUtils.createOrderedSet();
        for (int i = 0; i < destinationTypes.length; i++) {
            if (((ExplicitTransformer) transformer).isTransformable(destinationTypes[i], sourceType)) {
                result.add(destinationTypes[i]);
            }
        }
        return result.isEmpty() ? CLASS_NONE : (Class[]) result.toArray(new Class[result.size()]);
    }
    return destinationTypes;
}

From source file:com.ibm.mf.geofence.GeofencingJSONUtils.java

/**
 * Parse a list of geofences./*  w  ww . j a  va2 s.  c  o m*/
 * @param json json object representing the list of fences.
 * @return a list of {@link MFGeofence} instances.
 * @throws Exception if a parsing error occurs.
 */
static GeofenceList parseGeofences(JSONObject json) throws Exception {
    Set<PersistentGeofence> localGeofences = new HashSet<>(
            PersistentGeofence.listAll(PersistentGeofence.class));
    List<PersistentGeofence> result = new ArrayList<>();
    JSONArray features = json.getJSONArray("features");
    for (int i = 0; i < features.length(); i++) {
        JSONObject feature = features.getJSONObject(i);
        result.add(parseGeofence(feature));
    }
    int totalFeatures = result.size();
    // shoud now contain only the fences to delete
    localGeofences.removeAll(result);
    int n = localGeofences.size();
    List<String> deletedCodes = null;
    if (n > 0) {
        deletedCodes = new ArrayList<>(n);
        for (PersistentGeofence fence : localGeofences) {
            deletedCodes.add(fence.getCode());
            fence.delete();
        }
        log.debug(String.format("deleted %d geofences from local DB", n));
    }
    /*
    if (json.has("properties")) {
    JSONObject properties = json.getJSONObject("properties");
    List<String> deletedCodes = null;
    if (properties.has("deleted")) {
        JSONArray deletedCodesJson = properties.getJSONArray("deleted");
        deletedCodes = new ArrayList<>(deletedCodesJson.length());
        for (int i=0; i<deletedCodesJson.length(); i++) {
            deletedCodes.add(deletedCodesJson.getString(i));
        }
        if (!deletedCodes.isEmpty()) {
            n = GeofencingUtils.deleteGeofences(deletedCodes);
            log.debug(String.format("deleted %d geofences from local DB", n));
        }
    }
    int totalGeofences = properties.has("totalFeatures") ? properties.getInt("totalFeatures") : -1;
    return new GeofenceList(result, totalGeofences, deletedCodes);
    }
    */
    return new GeofenceList(result, totalFeatures, deletedCodes);
}

From source file:com.espertech.esper.epl.spec.PatternStreamSpecRaw.java

private static int[] getIndexesForTags(LinkedHashSet<String> allTagNamesOrdered, Set<String> arrayTags) {
    if (arrayTags == null || arrayTags.isEmpty()) {
        return new int[0];
    }/*from  w  w  w  . ja  v  a 2s.c  om*/
    int[] indexes = new int[arrayTags.size()];
    int count = 0;
    for (String arrayTag : arrayTags) {
        int index = 0;
        int found = findTagNumber(arrayTag, allTagNamesOrdered);
        indexes[count] = found;
        count++;
    }
    return indexes;
}

From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.DockerService.java

private static String[] environmentFrom(CreateAgentRequest request, PluginSettings settings,
        String containerName) {//from   www .  ja  v a 2 s . com
    Set<String> env = new HashSet<>();

    env.addAll(settings.getEnvironmentVariables());
    if (StringUtils.isNotBlank(request.properties().get("Environment"))) {
        env.addAll(splitIntoLinesAndTrimSpaces(request.properties().get("Environment")));
    }

    env.addAll(Arrays.asList("GO_EA_MODE=" + mode(), "GO_EA_SERVER_URL=" + settings.getGoServerUrl(),
            "GO_EA_GUID=" + "docker-swarm." + containerName));

    env.addAll(request.autoregisterPropertiesAsEnvironmentVars(containerName));

    return env.toArray(new String[env.size()]);
}

From source file:com.qmetry.qaf.automation.testng.report.ReporterUtil.java

private static int getSkipCnt(ITestContext context) {
    if ((context != null) && (context.getSkippedTests() != null)) {
        if (context.getSkippedTests().getAllResults() != null) {
            Collection<ITestNGMethod> skippedTest = context.getSkippedTests().getAllMethods();
            Set<ITestNGMethod> set = new HashSet<ITestNGMethod>(skippedTest);
            if (ApplicationProperties.RETRY_CNT.getIntVal(0) > 0) {
                set.removeAll(context.getPassedTests().getAllMethods());
                set.removeAll(context.getFailedTests().getAllMethods());
                return set.size();
            }//w  w  w .ja  v a  2s.  co  m
            return context.getSkippedTests().getAllResults().size();
        }
        return context.getSkippedTests().size();
    }
    return 0;
}

From source file:com.netxforge.oss2.config.DefaultDataCollectionConfigDao.java

private static void validateResourceTypes(final FileReloadContainer<DatacollectionConfig> container,
        final Set<String> allowedResourceTypes) {
    final String configuredString;
    if (allowedResourceTypes.size() == 0) {
        configuredString = "(none)";
    } else {/*  www . ja v  a 2  s  .c  o  m*/
        configuredString = StringUtils.join(allowedResourceTypes, ", ");
    }

    final String allowableValues = "any positive number, 'ifIndex', or any of the configured resourceTypes: "
            + configuredString;
    for (final SnmpCollection collection : container.getObject().getSnmpCollectionCollection()) {
        final Groups groups = collection.getGroups();
        if (groups != null) {
            for (final Group group : groups.getGroupCollection()) {
                for (final MibObj mibObj : group.getMibObjCollection()) {
                    final String instance = mibObj.getInstance();
                    if (instance == null)
                        continue;
                    if (MibObject.INSTANCE_IFINDEX.equals(instance))
                        continue;
                    if (allowedResourceTypes.contains(instance))
                        continue;
                    try {
                        // Check to see if the value is a non-negative integer
                        if (Integer.parseInt(instance.trim()) >= 0) {
                            continue;
                        }
                    } catch (NumberFormatException e) {
                    }

                    // XXX this should be a better exception
                    throw new IllegalArgumentException("instance '" + instance
                            + "' invalid in mibObj definition for OID '" + mibObj.getOid() + "' in collection '"
                            + collection.getName() + "' for group '" + group.getName()
                            + "'.  Allowable instance values: " + allowableValues);
                }
            }
        }
    }
}

From source file:net.geoprism.ontology.Classifier.java

@Transaction
public static String[] restoreSynonym(String synonymId) {
    ClassifierSynonym synonym = ClassifierSynonym.get(synonymId);
    Classifier[] classifiers = synonym.restore();

    Set<String> ids = new TreeSet<String>();

    for (Classifier classifier : classifiers) {
        ids.add(classifier.getId());/*from  ww  w. j a v a  2 s.  c  o m*/
    }

    return ids.toArray(new String[ids.size()]);
}