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:Main.java

public static String getCreateTableSql(String name, Map<String, String> columns) {
    String ret = "CREATE TABLE " + name + " (";
    int counter = 0;
    for (String key : columns.keySet()) {
        counter++;//from w ww. jav  a  2s  .c  om
        ret += key + " " + columns.get(key);
        if (counter < columns.size()) {
            ret += ", ";
        }
    }
    ret += ")";

    return ret;
}

From source file:Main.java

/**
 * assert the two map whether equals or not?
 * first: if two maps all null , return true.
 * second: if one of maps is null return false;
 * three : if the two maps' s size are not ==, return false;
 * four : every value with the key in map1,and with the key to 
 * search the map2, if map2'value is null or not equals , 
 * return false;/*www . ja  v  a2s.com*/
 * 
 * @param map1
 * @param map2
 * @return
 */
public static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2) {
    if (map1 == null && map2 == null) {
        return true;
    }
    if (map1 == null || map2 == null) {
        return false;
    }
    if (map1.size() != map2.size()) {
        return false;
    }
    for (Map.Entry<?, ?> entry : map1.entrySet()) {
        Object key = entry.getKey();
        Object value1 = entry.getValue();
        Object value2 = map2.get(key);
        if (!objectEquals(value1, value2)) {
            return false;
        }

    }
    return true;
}

From source file:Main.java

public static <K, V> Map<K, V> merge(Map<K, V> c1, Map<K, V> c2) {
    if (c1 == null || c1.size() == 0) {
        return c2;
    }/*w  ww .  j  ava 2s.c  o  m*/
    if (c2 == null || c2.size() == 0) {
        return c1;
    }
    Map<K, V> all = new HashMap<K, V>(c1.size() + c2.size());
    all.putAll(c1);
    all.putAll(c2);
    return all;
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step7bConvArgRankProducer.java

@SuppressWarnings("unchecked")
public static void prepareData(String[] args) throws Exception {
    String inputDir = args[0];//from ww  w. j  ava 2s .c  o m
    File outputDir = new File(args[1]);

    if (!outputDir.exists()) {
        outputDir.mkdirs();
    }

    List<File> files = IOHelper.listXmlFiles(new File(inputDir));

    // take only the gold data for this task
    String prefix = "all_DescendingScoreArgumentPairListSorter";
    Iterator<File> iterator = files.iterator();
    while (iterator.hasNext()) {
        File file = iterator.next();

        if (!file.getName().startsWith(prefix)) {
            iterator.remove();
        }
    }

    int totalArgumentsCounter = 0;

    DescriptiveStatistics statsPerTopic = new DescriptiveStatistics();

    for (File file : files) {
        List<AnnotatedArgumentPair> argumentPairs = (List<AnnotatedArgumentPair>) XStreamTools.getXStream()
                .fromXML(file);

        String name = file.getName().replaceAll(prefix, "").replaceAll("\\.xml", "");

        PrintWriter pw = new PrintWriter(new File(outputDir, name + ".csv"), "utf-8");
        pw.println("#id\trank\targument");

        Graph graph = buildGraphFromPairs(argumentPairs);

        Map<String, Argument> arguments = collectArguments(argumentPairs);

        int argumentsPerTopicCounter = arguments.size();

        PageRank pageRank = new PageRank();
        pageRank.setVerbose(true);
        pageRank.init(graph);

        for (Node node : graph) {
            String id = node.getId();
            double rank = pageRank.getRank(node);

            System.out.println(id);

            Argument argument = arguments.get(id);

            String text = Step7aLearningDataProducer.multipleParagraphsToSingleLine(argument.getText());

            pw.printf(Locale.ENGLISH, "%s\t%.5f\t%s%n", argument.getId(), rank, text);
        }

        totalArgumentsCounter += argumentsPerTopicCounter;
        statsPerTopic.addValue(argumentsPerTopicCounter);

        pw.close();
    }

    System.out.println("Total gold arguments: " + totalArgumentsCounter);
    System.out.println(statsPerTopic);
}

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

/**
 * make content/*w ww.j  a v  a  2 s  .  c  o m*/
 * 
 * @param tableName
 * @param rsDAO
 * @param intLimitCnt
 * @return
 */
public static String makeContent(boolean isAddHead, String tableName, QueryExecuteResultDTO rsDAO,
        char seprator, int intLimitCnt) throws Exception {
    StringBuffer sbReturn = new StringBuffer();
    List<Map<Integer, Object>> dataList = rsDAO.getDataList().getData();
    List<String[]> listCsvData = new ArrayList<String[]>();
    String[] strArrys = null;

    if (isAddHead) {
        // column .
        Map<Integer, String> mapLabelName = rsDAO.getColumnLabelName();
        strArrys = new String[mapLabelName.size() - 1];
        for (int i = 1; i < mapLabelName.size(); i++) {
            strArrys[i - 1] = mapLabelName.get(i);
        }
        listCsvData.add(strArrys);
        String strTitle = CSVFileUtils.makeData(listCsvData, seprator);
        sbReturn.append(strTitle);
    }
    listCsvData.clear();

    // data
    for (int i = 0; i < dataList.size(); i++) {
        Map<Integer, Object> mapColumns = dataList.get(i);

        strArrys = new String[mapColumns.size() - 1];
        for (int j = 1; j < mapColumns.size(); j++) {
            strArrys[j - 1] = mapColumns.get(j) == null ? "" : "" + mapColumns.get(j); //$NON-NLS-1$
        }
        listCsvData.add(strArrys);

        sbReturn.append(CSVFileUtils.makeData(listCsvData, seprator));
        listCsvData.clear();
        if (intLimitCnt == i)
            break;
    }

    return sbReturn.toString();
}

From source file:cn.ligoo.part.util.Servlets.java

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

    if (prefix == null) {
        prefix = "";
    }

    StringBuilder queryStringBuilder = new StringBuilder();
    Iterator<Entry<String, Object>> it = params.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, Object> entry = it.next();
        queryStringBuilder.append(prefix).append(entry.getKey()).append('=').append(entry.getValue());
        if (it.hasNext()) {
            queryStringBuilder.append('&');
        }
    }
    return queryStringBuilder.toString();
}

From source file:com.androidwhy.modules.web.Servlets.java

/**
 * ?Parameters?Query StringParameter, paramter nameprefix.
 * /*from ww  w.  j av a 2 s  .c o  m*/
 * @see #getParametersStartingWith
 */
public static String encodeParameterStringWithPrefix(Map<String, Object> params, String prefix) {
    if (params == null || params.size() == 0) {
        return "";
    }

    if (prefix == null) {
        prefix = "";
    }

    StringBuilder queryStringBuilder = new StringBuilder();
    Iterator<Entry<String, Object>> it = params.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, Object> entry = it.next();
        //queryStringBuilder.append(prefix).append(entry.getKey()).append('=').append(entry.getValue());
        queryStringBuilder.append(prefix).append(entry.getKey().replace(".", "__")).append('=')
                .append(entry.getValue());
        if (it.hasNext()) {
            queryStringBuilder.append('&');
        }
    }
    return queryStringBuilder.toString();
}

From source file:net.grinder.util.GrinderUtils.java

/**
 * Convert nvpair map to array. With this user can create NVPair array using
 * following code./*from ww  w  .java 2 s .c  om*/
 *
 *
 * <code>
 * import static net.ngrinder.util.GrinderUtil.*
 * ...
 * request1.POST("http://www.google.com", nvs(["key1":"value1", "key2":"value2"]))
 * </code>
 *
 * @param nvpairMap map of the
 * @return converted array
 */
public static NVPair[] nvs(Map<Object, Object> nvpairMap) {
    NVPair[] result = new NVPair[nvpairMap.size()];
    int i = 0;
    for (Entry<Object, Object> each : nvpairMap.entrySet()) {
        result[i++] = new NVPair(each.getKey().toString(), each.getValue().toString());
    }
    return result;
}

From source file:cn.wm.sum.utils.Servlets.java

/**
 * ?Parameters?Query StringParameter, paramter nameprefix.
 * //from   w w  w .j  a va  2 s.  com
 * @see #getParametersStartingWith
 */
public static String encodeParameterStringWithPrefix(Map<String, Object> params, String prefix) {
    if ((params == null) || (params.size() == 0)) {
        return "";
    }
    if (prefix == null) {
        prefix = "";
    }
    StringBuilder queryStringBuilder = new StringBuilder();
    Iterator<Entry<String, Object>> it = params.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, Object> entry = it.next();
        if ("page".equals(entry.getKey())) {
            continue;
        }
        queryStringBuilder.append(prefix).append(entry.getKey()).append('=').append(entry.getValue());
        if (it.hasNext()) {
            queryStringBuilder.append('&');
        }
    }
    return queryStringBuilder.toString();
}

From source file:com.tlabs.eve.HttpClientTest.java

public static List<NameValuePair> toNameValuePair(Map<String, String> params) {
    List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
    for (String p : params.keySet()) {
        pairs.add(new BasicNameValuePair(p, params.get(p)));
    }/*w  w w.  j  a  v  a2s.co  m*/
    return pairs;
}