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.networknt.light.server.DbService.java

public static String getWhereClause(Map<String, Object> criteria) {
    String wc = null;//from w w  w.j a  va 2 s.c o m
    boolean firstFilter = true;
    if (criteria.size() > 0) {
        // get the filter
        Iterator<String> it = criteria.keySet().iterator();
        StringBuilder sb = new StringBuilder();
        while (it.hasNext()) {
            String key = it.next();
            if (("pageNo").equals(key) || "pageSize".equals(key) || ("sortDir").equals(key)
                    || "sortedBy".equals(key)) {
                continue;
            } else {
                Object filterValue = criteria.get(key);
                if (filterValue != null && filterValue.toString().length() > 0) {
                    if (firstFilter) {
                        sb.append(" WHERE ");
                        firstFilter = false;
                    } else {
                        sb.append(" AND ");
                    }
                    if (filterValue instanceof String) {
                        // if key ends with DateFrom or DateTo then we need to treat it as Date
                        if (key.endsWith("DateFrom")) {
                            sb.append(key.substring(0, key.length() - 4));
                            sb.append(" >= date('").append(filterValue).append("')");
                        } else if (key.endsWith("DateTo")) {
                            sb.append(key.substring(0, key.length() - 2));
                            sb.append(" <= date('").append(filterValue).append("')");
                        } else {
                            sb.append(key);
                            sb.append(" = '").append(filterValue).append("'");
                        }
                    } else {
                        sb.append(key);
                        sb.append(" = ").append(filterValue);
                    }
                }
                continue;
            }
        }
        wc = sb.toString();
    }
    return wc;
}

From source file:com.hangum.tadpole.engine.sql.util.export.JsonExpoter.java

public static JsonArray makeMetaArray(QueryExecuteResultDTO rsDAO) throws SQLException {
    Map<Integer, String> mapLabelName = rsDAO.getColumnLabelName();

    //ResultSetMetaData rsm = rsDAO.getColumnMetaData();   

    JsonArray jsonMetaArry = new JsonArray();
    for (int j = 1; j < mapLabelName.size(); j++) {

        JsonObject jsonMetaObj = new JsonObject();
        jsonMetaObj.addProperty("position", j);
        jsonMetaObj.addProperty("column_name", mapLabelName.get(j));
        //            jsonMetaObj.addProperty("data_type", rsm.getColumnTypeName(j));
        jsonMetaObj.addProperty("data_type", rsDAO.getColumnType().get(j));
        //            jsonMetaObj.addProperty("column_size", rsm.getColumnDisplaySize(j));

        if (!RDBTypeToJavaTypeUtils.isNumberType(rsDAO.getColumnType().get(j))) {
            jsonMetaObj.addProperty("column_size", 90);
        } else {//from ww w  .ja v a  2  s . c  o  m
            jsonMetaObj.addProperty("column_size", 150);
        }

        jsonMetaArry.add(jsonMetaObj);
    }

    return jsonMetaArry;

}

From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java

/** Insert the plugin settings into the database. */
private static int saveProviderSettings(ContentResolver cr, long providerId, Map<String, String> config) {
    ContentValues[] settingValues = new ContentValues[config.size()];
    int index = 0;
    for (Map.Entry<String, String> entry : config.entrySet()) {
        ContentValues settingValue = new ContentValues();
        settingValue.put(Imps.ProviderSettings.PROVIDER, providerId);
        settingValue.put(Imps.ProviderSettings.NAME, entry.getKey());
        settingValue.put(Imps.ProviderSettings.VALUE, entry.getValue());
        settingValues[index++] = settingValue;
    }/* www .  j a  va 2 s.  c om*/
    return cr.bulkInsert(Imps.ProviderSettings.CONTENT_URI, settingValues);
}

From source file:Main.java

private static Marshaller getJaxbMarshaller(Class<?> classesToBeBound, Map<String, Object> marshallerProps)
        throws Exception {
    Marshaller marshaller = JAXB_MARSHALLER_CACHE.get(classesToBeBound);
    if (marshaller == null) {
        JAXBContext jaxbContext = JAXBContext.newInstance(classesToBeBound);
        marshaller = jaxbContext.createMarshaller();
        if (marshallerProps != null && marshallerProps.size() > 0) {
            for (Map.Entry<String, Object> prop : marshallerProps.entrySet()) {
                marshaller.setProperty(prop.getKey(), prop.getValue());
            }//  w  w  w. j  a  va2 s.  c  om
        }
        JAXB_MARSHALLER_CACHE.put(classesToBeBound, marshaller);
    }
    return marshaller;
}

From source file:dm_p2.KMEANS.java

public static void normalize(Map<Integer, List<Double>> lhm) {
    Double[][] mydata = new Double[lhm.size()][lhm.get(1).size()];
    Double[] min = new Double[lhm.get(1).size()];
    Double[] max = new Double[lhm.get(1).size()];
    for (int i = 1; i <= lhm.size(); i++) {
        List<Double> eachrow = lhm.get(i);
        for (int k = 0; k < eachrow.size(); k++) {
            mydata[i - 1][k] = eachrow.get(k);
        }// w  w w  .  j a  v a  2  s . co  m
    }
    for (int i = 0; i < lhm.get(1).size(); i++) {
        min[i] = 1000.0;
        max[i] = -1000.0;
        for (int k = 0; k < lhm.size(); k++) {
            if (mydata[k][i] < min[i]) {
                min[i] = mydata[k][i];
            }
            if (mydata[k][i] > max[i]) {
                max[i] = mydata[k][i];
            }
        }
    }
    for (int i = 1; i <= lhm.size(); i++) {
        for (int k = 0; k < lhm.get(1).size(); k++) {
            mydata[i - 1][k] = (mydata[i - 1][k] - min[k]) / (max[k] - min[k]);
        }
    }
    for (int i = 1; i <= lhm.size(); i++) {
        //DBSCAN.gene g=new DBSCAN.gene();
        ArrayList<Double> expval = new ArrayList<Double>();
        for (int k = 0; k < lhm.get(1).size(); k++) {
            expval.add(mydata[i - 1][k]);
            //mydata[i-1][k]=(mydata[i-1][k]-min[k])/(max[k]-min[k]);
        }
        //g.add(i, expval);
        linkedHashMap.put(i, expval);
        //genelist.add(g);
    }

}

From source file:Main.java

public static boolean setProperty(String filePath, String fileName, String propertyName,
        Map<String, String> propertyValueMap) {
    try {/*from w  w  w  . j  a  v  a 2s. c om*/
        Properties p = loadPropertyInstance(filePath, fileName);
        StringBuilder propertyValue = new StringBuilder();
        if (propertyValueMap != null && propertyValueMap.size() > 0) {
            for (String key : propertyValueMap.keySet()) {
                propertyValue.append(key.replaceAll("\\\\", "\\\\\\\\").replaceAll("(\\\\)+$", "")
                        .replaceAll("\\,", "\\\\,").replaceAll(";", "\\\\;") + ","
                        + propertyValueMap.get(key).replaceAll("(\\\\)+$", "").replaceAll("\\\\", "\\\\\\\\")
                                .replaceAll("\\,", "\\\\,").replaceAll(";", "\\\\;")
                        + ";");
            }
        }
        p.setProperty(propertyName, propertyValue.toString());
        String comment = "Update '" + propertyName + "' value";
        return storePropertyInstance(filePath, fileName, p, comment);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:dm_p2.KMEANS.java

public static void internalValidation(Map<Integer, List<Double>> linkedMap, Map<Integer, Integer> ourMap) {
    int size = linkedMap.size();
    int n = ((size - 1) * (size)) / 2;

    double incidenceMatrix[] = new double[n];
    double distanceMatrix[] = new double[n];
    int k = 0;//from   w  w w .  j ava 2s  .c o m
    for (int i = 1; i <= size; i++) {
        for (int j = i + 1; j <= size; j++) {
            if (ourMap.get(i) == ourMap.get(j)) {
                incidenceMatrix[k] = 1;
            } else {
                incidenceMatrix[k] = 0;
            }

            distanceMatrix[k] = euclidianDistance(linkedMap.get(i), linkedMap.get(j));
            k++;
        }
    }
    PearsonsCorrelation pc = new PearsonsCorrelation();

    System.out.println(
            "Internal Index Validation : Correlation = " + pc.correlation(incidenceMatrix, distanceMatrix));

}

From source file:Main.java

private static Unmarshaller getJaxbUnmarshaller(Class<?> classesToBeBound,
        Map<String, Object> unmarshallerProps) throws Exception {
    Unmarshaller unmarshaller = JAXB_UNMARSHALLER_CACHE.get(classesToBeBound);
    if (unmarshaller == null) {
        JAXBContext jaxbContext = JAXBContext.newInstance(classesToBeBound);
        unmarshaller = jaxbContext.createUnmarshaller();
        if (unmarshallerProps != null && unmarshallerProps.size() > 0) {
            for (Map.Entry<String, Object> prop : unmarshallerProps.entrySet()) {
                unmarshaller.setProperty(prop.getKey(), prop.getValue());
            }//from   w  w w. j ava2  s  .co  m
        }
        JAXB_UNMARSHALLER_CACHE.put(classesToBeBound, unmarshaller);
    }
    return unmarshaller;
}

From source file:com.android.volley.toolbox.http.HttpClientStack.java

@SuppressWarnings("unused")
private static List<NameValuePair> getPostParameterPairs(Map<String, String> postParams) {
    List<NameValuePair> result = new ArrayList<NameValuePair>(postParams.size());
    if (postParams != null) {
        for (String key : postParams.keySet()) {
            result.add(new BasicNameValuePair(key, postParams.get(key)));
        }//w  w  w.java2  s . com
    }
    return result;
}

From source file:com.soolr.core.web.Servlets.java

/**
 * ?Parameters?Query StringParameter, paramter nameprefix.
 * /*  www.  ja v  a  2 s . co  m*/
 * @see #getParametersStartingWith
 */
public static String encodeParameterStringWithPrefix(Map<String, Object> params, String prefix) {
    if ((params == null) || (params.size() == 0)) {
        return "";
    }

    String prefix_ = prefix == null ? "" : prefix;
    List<String> list = Lists.newArrayList();
    Iterator<Entry<String, Object>> it = params.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, Object> entry = it.next();
        Object values = entry.getValue();
        if (values instanceof String[]) {
            for (String v : (String[]) values) {
                list.add(String.format("%s%s=%s", prefix_, entry.getKey(), v));
            }
        } else if (values instanceof String) {
            list.add(String.format("%s%s=%s", prefix_, entry.getKey(), values));
        }
    }

    return Collections3.convertToString(list, "&");
}