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:it.geosolutions.unredd.StatsTests.java

@BeforeClass
public static void computeStats() {

    RasterClassifiedStatistics rcs = new RasterClassifiedStatistics();

    //load the test params
    Map<String, File> prop = loadTestParams();
    //create the classification layers array
    List<DataFile> classificatorsList = new ArrayList<DataFile>();
    for (int i = 0; i < prop.size() - 1; i++) {
        classificatorsList.add(new DataFile(prop.get(CLASSIFICATOR_PREFIX + (i + 1))));
    }/*from   www  . j av a2  s .c  o  m*/
    OutputStatsTest ost = null;
    Map<MultiKey, List<Result>> results = null;
    try {
        // run the stats
        DataFile df = new DataFile(prop.get(DATA));
        Range r = new Range();
        r.setRange("[1;1]");
        r.setIsAnExcludeRange(true);
        List<Range> arrList = new ArrayList<Range>();
        arrList.add(r);
        df.setRanges(arrList);
        results = rcs.execute(true, df, classificatorsList, Arrays.asList(STATS));
        LOGGER.info(results.toString());
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    StatsTests.results = results;
}

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

/**
 *  dyna bean.//from   ww w.  jav  a2  s. c  om
 * 
 * <h3>:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * 
 * Map{@code <String, Class<?>>} typeMap = new HashMap<>();
 * typeMap.put("address", java.util.Map.class);
 * typeMap.put("firstName", String.class);
 * typeMap.put("lastName", String.class);
 * 
 * Map{@code <String, Object>} valueMap = new HashMap<>();
 * valueMap.put("address", new HashMap());
 * valueMap.put("firstName", "Fred");
 * valueMap.put("lastName", "Flintstone");
 * 
 * DynaBean dynaBean = BeanUtil.newDynaBean(typeMap, valueMap);
 * LOGGER.debug(JsonUtil.format(dynaBean));
 * 
 * </pre>
 * 
 * <b>:</b>
 * 
 * <pre class="code">
 * {
 *         "lastName": "Flintstone",
 *         "address": {},
 *         "firstName": "Fred"
 *     }
 * </pre>
 * 
 * </blockquote>
 *
 * @param typeMap
 *            ??  map
 * @param valueMap
 *            ??   map
 * @return the dyna bean
 * @throws NullPointerException
 *              <code>typeMap </code>  <code>valueMap</code> null
 * @throws IllegalArgumentException
 *              <code>typeMap.size() != valueMap.size()</code>
 * @since 1.8.1 change name
 */
public static DynaBean newDynaBean(Map<String, Class<?>> typeMap, Map<String, Object> valueMap) {
    Validate.notNull(typeMap, "typeMap can't be null!");
    Validate.notNull(valueMap, "valueMap can't be null!");
    Validate.isTrue(typeMap.size() == valueMap.size(), "typeMap size:[%s] != valueMap size:[%s]",
            typeMap.size(), valueMap.size());

    //*********************************************************************************
    try {
        DynaClass dynaClass = new BasicDynaClass(null, null, toDynaPropertyArray(typeMap));

        DynaBean dynaBean = dynaClass.newInstance();
        for (Map.Entry<String, Object> entry : valueMap.entrySet()) {
            dynaBean.set(entry.getKey(), entry.getValue());
        }
        return dynaBean;
    } catch (IllegalAccessException | InstantiationException e) {
        LOGGER.error("", e);
        throw new BeanUtilException(e);
    }
}

From source file:fr.pasteque.client.utils.URLTextGetter.java

public static void getBinary(final String url, final Map<String, String> getParams, final Handler h) {
    new Thread() {
        @Override//from  w  w  w  .  java2 s . co  m
        public void run() {
            try {
                String fullUrl = url;
                if (getParams != null && getParams.size() > 0) {
                    fullUrl += "?";
                    for (String param : getParams.keySet()) {
                        fullUrl += URLEncoder.encode(param, "utf-8") + "="
                                + URLEncoder.encode(getParams.get(param), "utf-8") + "&";
                    }
                }
                if (fullUrl.endsWith("&")) {
                    fullUrl = fullUrl.substring(0, fullUrl.length() - 1);
                }
                HttpClient client = new DefaultHttpClient();
                HttpResponse response = null;
                HttpGet req = new HttpGet(fullUrl);
                response = client.execute(req);
                int status = response.getStatusLine().getStatusCode();
                if (status == HttpStatus.SC_OK) {
                    // Get http response
                    byte[] content = null;
                    try {
                        final int size = 10240;
                        ByteArrayOutputStream bos = new ByteArrayOutputStream(size);
                        byte[] buffer = new byte[size];
                        BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent(),
                                size);
                        int read = bis.read(buffer, 0, size);
                        while (read != -1) {
                            bos.write(buffer, 0, read);
                            read = bis.read(buffer, 0, size);
                        }
                        content = bos.toByteArray();
                    } catch (IOException ioe) {
                        ioe.printStackTrace();
                    }
                    if (h != null) {
                        Message m = h.obtainMessage();
                        m.what = SUCCESS;
                        m.obj = content;
                        m.sendToTarget();
                    }
                } else {
                    if (h != null) {
                        Message m = h.obtainMessage();
                        m.what = STATUS_NOK;
                        m.obj = new Integer(status);
                        m.sendToTarget();
                    }
                }
            } catch (IOException e) {
                if (h != null) {
                    Message m = h.obtainMessage();
                    m.what = ERROR;
                    m.obj = e;
                    m.sendToTarget();
                }
            }
        }
    }.start();
}

From source file:com.liferay.util.Http.java

public static String parameterMapToString(Map parameterMap, boolean addQuestion) {

    StringBuffer sb = new StringBuffer();

    if (parameterMap.size() > 0) {
        if (addQuestion) {
            sb.append(StringPool.QUESTION);
        }/* ww  w .j av  a 2  s .  c o m*/

        Iterator itr = parameterMap.entrySet().iterator();

        while (itr.hasNext()) {
            Map.Entry entry = (Map.Entry) itr.next();

            String name = (String) entry.getKey();
            String[] values = (String[]) entry.getValue();

            for (int i = 0; i < values.length; i++) {
                sb.append(name);
                sb.append(StringPool.EQUAL);
                sb.append(Http.encodeURL(values[i]));
                sb.append(StringPool.AMPERSAND);
            }
        }

        sb.deleteCharAt(sb.length() - 1);
    }

    return sb.toString();
}

From source file:org.zenoss.zep.impl.PluginServiceImpl.java

/**
 * Sorts plug-ins in the order of their dependencies, so all dependencies
 * come before the plug-in which depends on them.
 *
 * @param <T>/*from  www .  j a v  a  2 s.  co  m*/
 *            The type of {@link EventPlugin}.
 * @param plugins
 *            Map of plug-ins keyed by the plug-in ID.
 * @return A sorted list of plug-ins in order based on their dependencies.
 */
static <T extends EventPlugin> List<T> sortPluginsByDependencies(Map<String, T> plugins) {
    List<T> sorted = new ArrayList<T>(plugins.size());
    Map<String, T> mutablePlugins = new HashMap<String, T>(plugins);
    while (!mutablePlugins.isEmpty()) {
        for (Iterator<T> it = mutablePlugins.values().iterator(); it.hasNext();) {
            T plugin = it.next();
            boolean allDependenciesResolved = true;
            final Set<String> pluginDependencies = plugin.getDependencies();
            if (pluginDependencies != null) {
                for (String dep : pluginDependencies) {
                    T depPlugin = mutablePlugins.get(dep);
                    if (depPlugin != null) {
                        allDependenciesResolved = false;
                        break;
                    }
                }
            }
            if (allDependenciesResolved) {
                sorted.add(plugin);
                it.remove();
            }
        }
    }
    return sorted;
}

From source file:com.netsteadfast.greenstep.base.model.SqlGenerateUtil.java

private static Map<String, Object> getByUK(String fieldName, Object entityObject) throws Exception {
    String tableName = getTableName(entityObject);
    Map<String, Object> ukMap = getUKParameter(entityObject);
    if ("".equals(tableName.trim()) || ukMap == null || ukMap.size() < 1) {
        throw new java.lang.IllegalArgumentException(NOT_ENTITY_BEAN);
    }/* w w w .jav a  2  s  .  c  o m*/
    int field = 0;
    StringBuilder sql = new StringBuilder();
    Object params[] = new Object[ukMap.size()];
    sql.append(" select " + fieldName + " from " + tableName + " where 1=1 ");
    for (Map.Entry<String, Object> entry : ukMap.entrySet()) {
        params[field] = entry.getValue();
        sql.append(" and ").append(entry.getKey()).append("=? ");
        field++;
    }
    Map<String, Object> queryMap = new HashMap<String, Object>();
    queryMap.put(RETURN_SQL, sql.toString());
    queryMap.put(RETURN_PARAMS, params);
    return queryMap;
}

From source file:com.segment.analytics.internal.Utils.java

/** Returns true if the map is null or empty, false otherwise. */
public static boolean isNullOrEmpty(Map map) {
    return map == null || map.size() == 0;
}

From source file:com.windigo.RestApiMethodMetadata.java

/**
 * Convert parameters map to {@link NameValuePair} list
 *
 * @param queryParams//from  w ww  .j ava2  s  . com
 * @param args
 * @return {@link List} of {@link NameValuePair}
 */
private static List<NameValuePair> convertToNameValuePairs(Map<Integer, String> queryParams, Object[] args) {

    List<NameValuePair> params = new ArrayList<NameValuePair>();

    if (queryParams.size() > 0) {
        for (Entry<Integer, String> queryParamEntry : queryParams.entrySet()) {
            Object parameterValue = args[queryParamEntry.getKey()];
            if (parameterValue != null) {
                String valueString = Uri.encode(parameterValue.toString());
                params.add(new BasicNameValuePair(queryParamEntry.getValue(), valueString));
            }
        }
    }

    return params;

}

From source file:com.liferay.util.portlet.PortletRequestUtil.java

private static boolean _isValidAttributeValue(Object obj) {
    if (obj == null) {
        return false;
    } else if (obj instanceof Collection<?>) {
        Collection<?> col = (Collection<?>) obj;

        if (col.size() == 0) {
            return false;
        } else {//from   w  w w .  j a v  a  2 s  . c o m
            return true;
        }
    } else if (obj instanceof Map<?, ?>) {
        Map<?, ?> map = (Map<?, ?>) obj;

        if (map.size() == 0) {
            return false;
        } else {
            return true;
        }
    } else {
        String objString = String.valueOf(obj);

        if (Validator.isNull(objString)) {
            return false;
        }

        String hashCode = StringPool.AT.concat(StringUtil.toHexString(obj.hashCode()));

        if (objString.endsWith(hashCode)) {
            return false;
        }

        return true;
    }
}

From source file:com.sirma.itt.cmf.integration.workflow.WorkflowUtil.java

/**
 * Prepares the given node for persistence in the workflow engine.
 *
 * @param node/*w  w  w .  j a va2  s.c  o  m*/
 *            The node to package up for persistence
 * @return The map of data representing the node
 */
@SuppressWarnings("unchecked")
public static Map<QName, Serializable> prepareTaskParams(Node node) {
    Map<QName, Serializable> params = new HashMap<QName, Serializable>();

    // marshal the properties and associations captured by the property
    // sheet
    // back into a Map to pass to the workflow service

    // go through all the properties in the transient node and add them to
    // params map
    Map<String, Object> props = node.getProperties();
    for (String propName : props.keySet()) {
        QName propQName = resolveToQName(propName);
        params.put(propQName, (Serializable) props.get(propName));
    }

    // go through any associations that have been added to the start task
    // and build a list of NodeRefs representing the targets
    Map<String, Map<String, AssociationRef>> assocs = node.getAddedAssociations();
    for (String assocName : assocs.keySet()) {
        QName assocQName = resolveToQName(assocName);

        // get the associations added and create list of targets
        Map<String, AssociationRef> addedAssocs = assocs.get(assocName);
        List<AssociationRef> originalAssocRefs = (List<AssociationRef>) node.getAssociations().get(assocName);
        List<NodeRef> targets = new ArrayList<NodeRef>(addedAssocs.size());

        if (originalAssocRefs != null) {
            for (AssociationRef assoc : originalAssocRefs) {
                targets.add(assoc.getTargetRef());
            }
        }

        for (AssociationRef assoc : addedAssocs.values()) {
            targets.add(assoc.getTargetRef());
        }

        params.put(assocQName, (Serializable) targets);
    }

    // go through the removed associations and either setup or adjust the
    // parameters map accordingly
    assocs = node.getRemovedAssociations();

    for (String assocName : assocs.keySet()) {
        QName assocQName = resolveToQName(assocName);

        // get the associations removed and create list of targets
        Map<String, AssociationRef> removedAssocs = assocs.get(assocName);
        List<NodeRef> targets = (List<NodeRef>) params.get(assocQName);

        if (targets == null) {
            // if there weren't any assocs of this type added get the
            // current
            // set of assocs from the node
            List<AssociationRef> originalAssocRefs = (List<AssociationRef>) node.getAssociations()
                    .get(assocName);
            targets = new ArrayList<NodeRef>(originalAssocRefs.size());

            for (AssociationRef assoc : originalAssocRefs) {
                targets.add(assoc.getTargetRef());
            }
        }

        // remove the assocs the user deleted
        for (AssociationRef assoc : removedAssocs.values()) {
            targets.remove(assoc.getTargetRef());
        }

        params.put(assocQName, (Serializable) targets);
    }

    // TODO: Deal with child associations if and when we need to support
    // them for workflow tasks, for now warn that they are being used
    Map<?, ?> childAssocs = node.getAddedChildAssociations();
    if (childAssocs.size() > 0) {
        if (logger.isWarnEnabled())
            logger.warn("Child associations are present but are not supported for workflow tasks, ignoring...");
    }

    return params;
}