Example usage for java.util Map size

List of usage examples for java.util Map size

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of key-value mappings in this map.

Usage

From source file:com.espertech.esperio.csv.CSVPropertyOrderHelper.java

private static boolean isValidRowLength(String[] row, Map<String, Object> propertyTypes) {
    log.debug(".isValidRowLength");
    if (row == null) {
        return false;
    }//from ww w  . j av a2 s.  c om
    // same row size, or with timestamp column added, or longer due to flatten nested properties
    return (row.length == propertyTypes.size()) || (row.length == propertyTypes.size() + 1)
            || (row.length > propertyTypes.size());
}

From source file:com.thruzero.common.core.utils.StringUtilsExt.java

/**
 * Converts the given Map of {@code keyValuePairs} into a token stream, using the given {@code separator}.
 * <p>//from w  w w  . j a  v a2s.  c om
 * Example: "integerOne=1,booleanTrue=true,longOne=1234567890,booleanFalse=false"
 */
public static String toTokenStream(final Map<String, String> keyValuePairs, final String separator) {
    StringBuilder result = new StringBuilder(keyValuePairs.size() * 16); // assume 16-chars for each k/v token.
    String tokenSeparator = "";
    Map<String, String> parametersToStream = keyValuePairs;

    for (Entry<String, String> entry : parametersToStream.entrySet()) {
        result.append(tokenSeparator);
        result.append(entry.getKey());
        result.append('=');
        result.append(entry.getValue());
        tokenSeparator = separator;
    }

    return result.toString();
}

From source file:com.fizzed.rocker.runtime.Java8Iterator.java

static public <K, V> void forEach(Map<K, V> items, ConsumeMapWithIterator<K, V> consumer)
        throws RenderingException, IOException {
    IndexOnlyForIterator it = new IndexOnlyForIterator(items.size());
    for (Map.Entry<K, V> item : items.entrySet()) {
        it.increment();//w w  w .  ja  va 2 s .c o  m
        consumer.accept(it, item.getKey(), item.getValue());
    }
}

From source file:com.github.gdfm.shobaidogu.StatsUtils.java

/**
 * Normalize with l2 norm.//from   ww  w .  jav a 2  s.c  om
 * 
 * @param vector
 */
public static <K, V extends Number> Map<K, Double> l2Normalize(Map<K, V> vector) {
    if (vector == null || vector.size() == 0)
        throw new IllegalArgumentException("Cannot normalize an empy vector: " + vector);
    Map<K, Double> result = Maps.newHashMap();
    double normalizer = magnitude(vector);
    for (Map.Entry<K, V> entry : vector.entrySet())
        result.put(entry.getKey(), entry.getValue().doubleValue() / normalizer);
    return result;
}

From source file:Main.java

public static <K, V> Map<K, V> valueSortedMap(Map<K, V> map, Comparator<Entry<K, V>> comparator) {
    Set<Entry<K, V>> valueSortedEntries = new TreeSet<Entry<K, V>>(comparator);

    for (Entry<K, V> entry : map.entrySet()) {
        valueSortedEntries.add(entry);//from  w ww .  j  a  v  a 2s .  co  m
    }

    Map<K, V> sortedMap = new LinkedHashMap<K, V>(map.size());
    for (Entry<K, V> entry : valueSortedEntries) {
        sortedMap.put(entry.getKey(), entry.getValue());
    }

    return sortedMap;
}

From source file:com.github.gdfm.shobaidogu.StatsUtils.java

/**
 * Normalize in place with l2 norm.//w ww.ja  v a 2  s.  com
 * 
 * @param vector
 */
public static <K> void l2NormalizeInPlace(Map<K, Double> vector) {
    if (vector == null || vector.size() == 0)
        throw new IllegalArgumentException("Cannot normalize an empy vector: " + vector);
    double normalizer = magnitude(vector);
    for (Map.Entry<K, Double> entry : vector.entrySet())
        vector.put(entry.getKey(), entry.getValue() / normalizer);
}

From source file:com.sugaronrest.restapicalls.ModuleInfoExt.java

/**
 * Gets modules linked information.// w w  w.j a va2 s  .com
 *
 *  @param linkedModules The module linked info list.
 *  @return Dictionary map of linked modules.
 */
public static List<Object> getJsonLinkedInfo(Map<Object, List<String>> linkedModules) throws Exception {
    if ((linkedModules == null) || (linkedModules.size() == 0)) {
        return null;
    }

    Map<String, List<String>> linkedInfo = getLinkedInfo(linkedModules);

    if ((linkedInfo == null) || (linkedInfo.size() == 0)) {
        return null;
    }

    List<Object> jsonLinkedInfoList = new ArrayList<Object>();

    for (Map.Entry<String, List<String>> entry : linkedInfo.entrySet()) {

        Map<String, Object> namevalueMap = new HashMap<String, Object>();
        namevalueMap.put("name", entry.getKey());
        namevalueMap.put("value", entry.getValue());

        jsonLinkedInfoList.add(namevalueMap);
    }

    return jsonLinkedInfoList;
}

From source file:com.vmware.photon.controller.rootscheduler.simulator.CloudStoreLoader.java

/**
 * Creates host documents in cloudstore.
 *
 * @param cloudstore CloudStore test environment to create documents in.
 * @param numHosts The number of host documents to create.
 * @param hostConfigurations A map from {@link HostConfiguration} to the probability that this
 *                           host configuration is used in the deployment. The sum of all the
 *                           values of this map must be 1.
 * @param numDatastores The number of datastores.
 * @param numDatastoresDistribution Distribution for number of datastores on each host. This
 *                                  distribution is expected to generate samples in the range
 *                                  [0, numDatastores].
 * @throws Throwable/*w w w  . j a  va2  s.  co  m*/
 */
public static void loadHosts(TestEnvironment cloudstore, int numHosts,
        Map<HostConfiguration, Double> hostConfigurations, int numDatastores,
        IntegerDistribution numDatastoresDistribution) throws Throwable {
    int[] indices = new int[hostConfigurations.size()];
    HostConfiguration[] configs = new HostConfiguration[hostConfigurations.size()];
    double[] probabilities = new double[hostConfigurations.size()];
    int i = 0;
    for (Map.Entry<HostConfiguration, Double> entry : hostConfigurations.entrySet()) {
        indices[i] = i;
        configs[i] = entry.getKey();
        probabilities[i] = entry.getValue();
        i++;
    }
    EnumeratedIntegerDistribution configDistribution = new EnumeratedIntegerDistribution(indices,
            probabilities);
    for (i = 0; i < numHosts; i++) {
        HostService.State host = new HostService.State();
        host.hostAddress = "host" + i;
        host.state = HostState.READY;
        host.userName = "username";
        host.password = "password";
        host.reportedDatastores = new HashSet<>();
        int numDatastoresPerHost = numDatastoresDistribution.sample();
        assertThat(numDatastoresPerHost >= 0, is(true));
        assertThat(numDatastoresPerHost <= numDatastores, is(true));
        while (host.reportedDatastores.size() < numDatastoresPerHost) {
            int randomInt = random.nextInt(numDatastores);
            host.reportedDatastores.add(new UUID(0, randomInt).toString());
        }
        host.reportedNetworks = new HashSet<>();
        host.usageTags = new HashSet<>(Arrays.asList(UsageTag.CLOUD.name()));
        int configIndex = configDistribution.sample();
        host.cpuCount = configs[configIndex].numCpus;
        host.memoryMb = configs[configIndex].memoryMb;
        host.documentSelfLink = new UUID(0, i).toString();
        // TODO(mmutsuzaki) Support availability zones.
        Operation result = cloudstore.sendPostAndWait(HostServiceFactory.SELF_LINK, host);
        assertThat(result.getStatusCode(), is(200));
        logger.debug("Created a host document: {}", Utils.toJson(true, false, host));
    }
}

From source file:com.erudika.para.utils.ValidationUtils.java

/**
 * Returns the JSON object containing all validation constraints for all the core Para classes and classes defined
 * by the given app.// w w w. ja  v  a2  s . c om
 *
 * @param app an app
 * @return JSON string
 */
public static String getAllValidationConstraints(App app) {
    String json = "{}";
    try {
        ObjectNode parentNode = Utils.getJsonMapper().createObjectNode();
        for (String type : RestUtils.getAllTypes(app).values()) {
            Map<?, ?> constraintsNode = getValidationConstraints(app, type);
            if (constraintsNode.size() > 0) {
                parentNode.putPOJO(StringUtils.capitalize(type), constraintsNode);
            }
        }
        json = Utils.getJsonWriter().writeValueAsString(parentNode);
    } catch (IOException ex) {
        logger.error(null, ex);
    }
    return json;
}

From source file:com.feilong.core.bean.BeanUtilTemp.java

/**
 * To dyna property array.//ww  w.j  a v  a 2  s .c  o m
 *
 * @param typeMap
 *            the type map
 * @return the dyna property[]
 * @since 1.8.0
 */
private static DynaProperty[] toDynaPropertyArray(Map<String, Class<?>> typeMap) {
    DynaProperty[] dynaPropertys = new DynaProperty[typeMap.size()];
    int i = 0;
    for (Map.Entry<String, Class<?>> entry : typeMap.entrySet()) {
        dynaPropertys[i] = new DynaProperty(entry.getKey(), entry.getValue());
        i++;
    }
    return dynaPropertys;
}