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.liferay.util.Http.java

public static String parameterMapToStringNoEncode(Map parameterMap) {

    StringBuffer sb = new StringBuffer();

    if (parameterMap.size() > 0) {

        sb.append(StringPool.QUESTION);//from www  .j a  v a  2  s  . com

        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(values[i]);
                sb.append(StringPool.AMPERSAND);
            }
        }

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

    return sb.toString();
}

From source file:com.netsteadfast.greenstep.bsc.util.PerformanceScoreChainUtils.java

public static void createOrUpdateMonitorItemScoreCurrentDateForEmployees(String frequency)
        throws ServiceException, Exception {
    Map<String, String> employeeMap = employeeService.findForMap(false);
    if (null == employeeMap || employeeMap.size() < 1) {
        return;/*w w  w . java 2s .c om*/
    }
    Map<String, Object> paramMap = new HashMap<String, Object>();
    for (Map.Entry<String, String> emp : employeeMap.entrySet()) {
        EmployeeVO employee = BscBaseLogicServiceCommonSupport.findEmployeeData(employeeService, emp.getKey());
        paramMap.put("empId", employee.getEmpId());
        if (kpiEmplService.countByParams(paramMap) < 1) {
            continue;
        }
        try {
            createOrUpdateMonitorItemScoreCurrentDate(frequency, "employee", "", employee.getOid());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:io.wcm.config.core.management.util.TypeConversion.java

/**
 * Converts a OSGi configuration property value to an object with the given parameter type.
 * @param value String value (not null)/*from  w ww  .  j a va  2s  .c  o m*/
 * @param type Parameter type
 * @param defaultValue Default value is used if not OSGi configuration value is set
 * @return Converted value
 * @throws IllegalArgumentException If type is not supported
 */
@SuppressWarnings("unchecked")
public static <T> T osgiPropertyToObject(Object value, Class<T> type, T defaultValue) {
    // only selected parameter types are supported
    if (type == String.class) {
        return (T) PropertiesUtil.toString(value, (String) defaultValue);
    }
    if (type == String[].class) {
        return (T) PropertiesUtil.toStringArray(value, (String[]) defaultValue);
    } else if (type == Integer.class) {
        Integer defaultIntValue = (Integer) defaultValue;
        if (defaultIntValue == null) {
            defaultIntValue = 0;
        }
        return (T) (Integer) PropertiesUtil.toInteger(value, defaultIntValue);
    } else if (type == Long.class) {
        Long defaultLongValue = (Long) defaultValue;
        if (defaultLongValue == null) {
            defaultLongValue = 0L;
        }
        return (T) (Long) PropertiesUtil.toLong(value, defaultLongValue);
    } else if (type == Double.class) {
        Double defaultDoubleValue = (Double) defaultValue;
        if (defaultDoubleValue == null) {
            defaultDoubleValue = 0d;
        }
        return (T) (Double) PropertiesUtil.toDouble(value, defaultDoubleValue);
    } else if (type == Boolean.class) {
        Boolean defaultBooleanValue = (Boolean) defaultValue;
        if (defaultBooleanValue == null) {
            defaultBooleanValue = false;
        }
        return (T) (Boolean) PropertiesUtil.toBoolean(value, defaultBooleanValue);
    } else if (type == Map.class) {
        Map<?, ?> defaultMap = (Map) defaultValue;
        String[] defaultMapValue;
        if (defaultMap == null) {
            defaultMapValue = new String[0];
        } else {
            defaultMapValue = new String[defaultMap.size()];
            Map.Entry<?, ?>[] entries = Iterators.toArray(defaultMap.entrySet().iterator(), Map.Entry.class);
            for (int i = 0; i < entries.length; i++) {
                defaultMapValue[i] = Objects.toString(entries[i].getKey(), "") + KEY_VALUE_DELIMITER
                        + Objects.toString(entries[i].getValue(), "");
            }
        }
        return (T) PropertiesUtil.toMap(value, defaultMapValue);
    }
    throw new IllegalArgumentException("Unsupported type: " + type.getName());
}

From source file:com.lightbox.android.network.HttpHelper.java

public static List<NameValuePair> mapToNameValueList(Map<?, ?> map) throws UnsupportedEncodingException {
    List<NameValuePair> nameValueList = new ArrayList<NameValuePair>(map.size());
    for (Map.Entry<?, ?> param : map.entrySet()) {
        NameValuePair nameValuePair = new BasicNameValuePair(param.getKey().toString(),
                param.getValue().toString());
        nameValueList.add(nameValuePair);
    }/*from  w  w  w  . ja  v a2  s . c o m*/
    return nameValueList;
}

From source file:com.mingsoft.util.proxy.Proxy.java

/**
 * get??/*from   w  ww  . ja v a 2s.  com*/
 * 
 * @param url
 *            ?<br>
 * @param fileUrl
 *            ????<br>
 * @param header
 *            ?Header new Header()<br>
 */
public static void getRandCode(String url, com.mingsoft.util.proxy.Header header, String fileUrl) {
    DefaultHttpClient client = new DefaultHttpClient();

    //log.info("?" + url);
    // get
    HttpGet get = new HttpGet(url);
    // cookie?()
    get.getParams().setParameter("http.protocol.cookie-policy", CookiePolicy.BROWSER_COMPATIBILITY);
    Map _headers = header.getHeaders();
    // ?
    if (null != header && _headers.size() > 0) {
        get.setHeaders(Proxy.assemblyHeader(_headers));
    }
    HttpResponse response;
    try {
        response = client.execute(get);

        // ?
        // Header[] h = (Header[]) response.getAllHeaders();
        // for (int i = 0; i < h.length; i++) {
        // Header a = h[i];
        // }

        HttpEntity entity = response.getEntity();
        InputStream in = entity.getContent();
        // cookie???cookie
        header.setCookie(assemblyCookie(client.getCookieStore().getCookies()));
        int temp = 0;
        // 
        File file = new File(fileUrl);
        // ??
        FileOutputStream out = new FileOutputStream(file);
        while ((temp = in.read()) != -1) {
            out.write(temp);
        }
        in.close();
        out.close();

    } catch (ClientProtocolException e) {
        e.printStackTrace();
        log.error(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        log.error(e.getMessage());
    }
}

From source file:com.zxy.commons.mongodb.MongodbUtils.java

/**
 * ?//from w ww.  j a  v a2s  . co m
 *
 * @param params params
 * @return Query
 */
public static Query getQuery(Map<String, Object> params) {
    if (params == null || params.isEmpty()) {
        return null;
    }
    List<Criteria> criterias = new ArrayList<>();
    for (Map.Entry<String, Object> entry : params.entrySet()) {
        criterias.add(Criteria.where(entry.getKey()).is(entry.getValue()));
    }
    return new Query(new Criteria().andOperator(criterias.toArray(new Criteria[params.size()])));

}

From source file:com.aliyun.openservices.odps.console.common.JobDetailInfo.java

protected static String deduceTaskName(Instance inst) throws ODPSConsoleException, OdpsException {
    Map<String, Instance.TaskStatus> ss = inst.getTaskStatus();
    if (ss.size() == 1) {
        for (String key : ss.keySet()) {
            return key;
        }// w  w w .ja v  a2s.  c o  m
    } else {
        throw new ODPSConsoleException(
                "Please specify one of these tasks with option '-t': " + StringUtils.join(ss.keySet(), ','));
    }
    return null;
}

From source file:Main.java

public static String mergeUri(String uri, Object[] args, SparseArray<String> paramKeys,
        Map<String, String> methodStaticUri, Map<String, String> globalParamKeys) {

    if (paramKeys != null && paramKeys.size() > 0 && args != null && args.length > 0) {
        for (int i = 0, key = paramKeys.keyAt(i); i < paramKeys.size(); key = paramKeys.keyAt(++i)) {
            uri = uri.replaceFirst(":" + paramKeys.get(key), String.valueOf(args[key]));
        }//w  ww .ja  v a 2s  . c  o m
    }
    if (methodStaticUri != null && methodStaticUri.size() > 0) {
        for (Map.Entry<String, String> e : methodStaticUri.entrySet()) {
            uri = uri.replaceFirst(":" + e.getKey(), e.getValue());
        }
    }
    if (globalParamKeys != null && globalParamKeys.size() > 0) {
        for (Map.Entry<String, String> e : globalParamKeys.entrySet()) {
            uri = uri.replaceFirst(":" + e.getKey(), e.getValue());
        }
    }

    return uri;
}

From source file:org.apache.camel.component.box.internal.BoxClientHelper.java

@SuppressWarnings("deprecation")
public static CachedBoxClient createBoxClient(final BoxConfiguration configuration) {

    final String clientId = configuration.getClientId();
    final String clientSecret = configuration.getClientSecret();

    final IAuthSecureStorage authSecureStorage = configuration.getAuthSecureStorage();
    final String userName = configuration.getUserName();
    final String userPassword = configuration.getUserPassword();

    if ((authSecureStorage == null && ObjectHelper.isEmpty(userPassword)) || ObjectHelper.isEmpty(userName)
            || ObjectHelper.isEmpty(clientId) || ObjectHelper.isEmpty(clientSecret)) {
        throw new IllegalArgumentException("Missing one or more required properties "
                + "clientId, clientSecret, userName and either authSecureStorage or userPassword");
    }/*from   w  w w . j av a 2s .c o m*/
    LOG.debug("Creating BoxClient for login:{}, client_id:{} ...", userName, clientId);

    // if set, use configured connection manager builder
    final BoxConnectionManagerBuilder connectionManagerBuilder = configuration.getConnectionManagerBuilder();
    final BoxConnectionManagerBuilder connectionManager = connectionManagerBuilder != null
            ? connectionManagerBuilder
            : new BoxConnectionManagerBuilder();

    // create REST client for BoxClient
    final ClientConnectionManager[] clientConnectionManager = new ClientConnectionManager[1];
    final IBoxRESTClient restClient = new BoxRESTClient(connectionManager.build()) {
        @Override
        public HttpClient getRawHttpClient() {
            final HttpClient httpClient = super.getRawHttpClient();
            clientConnectionManager[0] = httpClient.getConnectionManager();

            // set custom HTTP params
            final Map<String, Object> configParams = configuration.getHttpParams();
            if (configParams != null && !configParams.isEmpty()) {
                LOG.debug("Setting {} HTTP Params", configParams.size());

                final HttpParams httpParams = httpClient.getParams();
                for (Map.Entry<String, Object> param : configParams.entrySet()) {
                    httpParams.setParameter(param.getKey(), param.getValue());
                }
            }

            return httpClient;
        }
    };
    final BoxClient boxClient = new BoxClient(clientId, clientSecret, null, null, restClient,
            configuration.getBoxConfig());

    // enable OAuth auto-refresh
    boxClient.setAutoRefreshOAuth(true);

    // wrap the configured storage in a caching storage
    final CachingSecureStorage storage = new CachingSecureStorage(authSecureStorage);

    // set up a listener to notify secure storage and user provided listener, store it in configuration!
    final OAuthHelperListener listener = new OAuthHelperListener(storage, configuration.getRefreshListener());
    boxClient.addOAuthRefreshListener(listener);

    final CachedBoxClient cachedBoxClient = new CachedBoxClient(boxClient, userName, clientId, storage,
            listener, clientConnectionManager);
    LOG.debug("BoxClient created {}", cachedBoxClient);
    return cachedBoxClient;
}

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

private static boolean checkValueParams(Map<String, Object> params) throws Exception {
    boolean status = false;
    if (params == null || params.size() < 1) {
        return status;
    }/*w w w .ja va  2  s  .co m*/
    for (Map.Entry<String, Object> entry : params.entrySet()) {
        if (entry.getValue() != null) {
            status = true;
        }
    }
    return status;
}