Example usage for java.util HashMap size

List of usage examples for java.util HashMap size

Introduction

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

Prototype

int size

To view the source code for java.util HashMap size.

Click Source Link

Document

The number of key-value mappings contained in this map.

Usage

From source file:com.apatar.core.ApatarHttpClient.java

public String sendPostHttpQuery(String url, HashMap<String, String> params) throws IOException {
    int size = params.size();
    Part[] parts = new Part[size];
    int i = 0;/*w  w w.j av a 2  s.c om*/
    for (String param : params.keySet()) {
        parts[i++] = new StringPart(param, params.get(param));
    }

    PostMethod method = new PostMethod(url);

    method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));

    return sendHttpQuery(method);

}

From source file:org.kitodo.data.index.elasticsearch.type.DocketTypeTest.java

@Test
public void shouldCreateDocuments() throws Exception {
    DocketType docketType = new DocketType();

    List<Docket> dockets = prepareData();
    HashMap<Integer, HttpEntity> documents = docketType.createDocuments(dockets);
    assertEquals("HashMap of documents doesn't contain given amount of elements!", 2, documents.size());
}

From source file:org.kitodo.data.elasticsearch.index.type.FilterTypeTest.java

@Test
public void shouldCreateDocuments() throws Exception {
    FilterType filterType = new FilterType();

    List<Filter> filters = prepareData();
    HashMap<Integer, HttpEntity> documents = filterType.createDocuments(filters);
    assertEquals("HashMap of documents doesn't contain given amount of elements!", 2, documents.size());
}

From source file:org.kitodo.data.index.elasticsearch.type.RulesetTypeTest.java

@Test
public void shouldCreateDocuments() throws Exception {
    RulesetType rulesetType = new RulesetType();

    List<Ruleset> rulesets = prepareData();
    HashMap<Integer, HttpEntity> documents = rulesetType.createDocuments(rulesets);
    assertEquals("HashMap of documents doesn't contain given amount of elements!", 2, documents.size());
}

From source file:org.pentaho.platform.platform.osgi.requirejs.bindings.RequireJsConfigTest.java

@Test
public void testModuleMapping() throws Exception {

    RequireJsConfig requireJsConfig = mapper.readValue(new File("src/test/resources/testConfig.js"),
            RequireJsConfig.class);

    assertEquals("/Public/js", requireJsConfig.getBaseUrl());
    assertEquals(3, requireJsConfig.getWaitSeconds());
    HashMap<String, String> paths = requireJsConfig.getPaths();
    assertNotNull(paths);//w  w w .ja v a 2 s. com
    assertTrue(paths.size() > 0);
    assertTrue(paths.containsKey("jqueryui"));
    assertTrue(paths.containsKey("jquery"));
    assertEquals("../../Scripts/jquery-ui-1.10.2.min", paths.get("jqueryui"));
    assertEquals("../../Scripts/jquery-1.10.2.min", paths.get("jquery"));

    HashMap<String, Shim> shim = requireJsConfig.getShim();
    assertNotNull(shim);
    assertEquals(1, shim.size());

    Shim jqueryui = shim.get("jqueryui");
    assertNotNull(jqueryui);
    assertEquals(1, jqueryui.getDeps().length);
    assertEquals("jquery", jqueryui.getDeps()[0]);

    // Serialize it back out and then in again to compare.
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    mapper.writeValue(outputStream, requireJsConfig);

    String serialized = new String(outputStream.toByteArray(), "UTF-8");

    RequireJsConfig configRoundTripped = mapper.readValue(serialized, RequireJsConfig.class);

    assertEquals(requireJsConfig, configRoundTripped);

}

From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java

/**
 * This normalizes the raw counts by the counts of the source strings in each production.
 * Example:/*from   ww w .j  av a  2  s  . c om*/
 *    Raw counts={ Prod("John", "Yon")=>4, Prod("John","Jon")=>1 }
 *    Normalized={ Prod("John", "Yon")=>4/5, Prod("John","Jon")=>1/5}
 *
 * If source strings only ever show up for one target string, then this does nothing.
 *
 * @param counts raw counts
 * @param internTable
 * @return
 */
public static HashMap<Production, Double> NormalizeBySourceSubstring(HashMap<Production, Double> counts,
        InternDictionary<String> internTable) {
    // gets counts by source strings
    HashMap<String, Double> totals = GetAlignmentTotals1(counts);

    HashMap<Production, Double> result = new HashMap<>(counts.size());

    for (Production key : counts.keySet()) {
        Double value = counts.get(key);
        result.put(new Production(internTable.Intern(key.getFirst()), internTable.Intern(key.getSecond())),
                value / totals.get(key.getFirst()));
    }

    return result;
}

From source file:com.o2d.pkayjava.editor.data.migrations.migrators.VersionMigTo009.java

private void fixLibraryItemsLocation(HashMap<String, JsonValue> libraryItems) {
    if (libraryItems.size() == 0)
        return;// w ww.  j a  va 2 s.c om
    //creating libraryArrayJsonString
    String libraryArrayJsonString = "{";
    for (JsonValue entry : libraryItems.values()) {
        libraryArrayJsonString += "\"" + entry.name + "\": " + entry.prettyPrint(JsonWriter.OutputType.json, 1)
                + ", ";
    }
    libraryArrayJsonString = libraryArrayJsonString.substring(0, libraryArrayJsonString.length() - 2) + "}";

    //ProjectInfo data
    String prjInfoFilePath = projectPath + "/project.dt";
    FileHandle projectInfoFile = Gdx.files.internal(prjInfoFilePath);
    try {
        String projectInfoContents = FileUtils.readFileToString(projectInfoFile.file());
        JsonValue value = jsonReader.parse(projectInfoContents);
        JsonValue newVal = jsonReader.parse(libraryArrayJsonString);
        newVal.name = "libraryItems";
        newVal.prev = value.get("scenes");
        newVal.next = newVal.prev.next;
        newVal.prev.next = newVal;

        String content = value.prettyPrint(JsonWriter.OutputType.json, 1);
        FileUtils.writeStringToFile(new File(prjInfoFilePath), content, "utf-8");

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:contrail.correct.TestFlashExtension.java

public void testMap() throws IOException {
    File temp = getTempDirectory();
    File outputFile = new File(temp, "output");
    File flashInput = new File(temp, "flashInput.avro");
    runFlashTest(temp, flashInput, outputFile);
    File outputAvroFile = new File(outputFile, "part-00000.avro");
    Schema schema = (new fastqrecord()).getSchema();
    DatumReader<fastqrecord> datum_reader = new SpecificDatumReader<fastqrecord>(schema);
    DataFileReader<fastqrecord> reader = new DataFileReader<fastqrecord>(outputAvroFile, datum_reader);
    int numberOfFastqReads = 0;
    ArrayList<fastqrecord> output = new ArrayList<fastqrecord>();
    while (reader.hasNext()) {
        fastqrecord record = reader.next();
        output.add(record);//from  w  w  w.j  a  va  2  s.c o  m
        numberOfFastqReads++;
    }
    HashMap<String, String> expectedHashMap = getExpectedHashMap();
    assertEquals(expectedHashMap.size(), numberOfFastqReads);
    assertMapOutput(output, expectedHashMap);
    if (temp.exists()) {
        FileUtils.deleteDirectory(temp);
    }
}

From source file:org.kitodo.data.elasticsearch.index.type.UserGroupTypeTest.java

@Test
public void shouldCreateDocuments() {
    UserGroupType UserGroupType = new UserGroupType();

    List<UserGroup> batches = prepareData();
    HashMap<Integer, HttpEntity> documents = UserGroupType.createDocuments(batches);
    assertEquals("HashMap of documents doesn't contain given amount of elements!", 2, documents.size());
}

From source file:org.kitodo.data.index.elasticsearch.type.BatchTypeTest.java

@Test
public void shouldCreateDocuments() throws Exception {
    BatchType batchType = new BatchType();

    List<Batch> batches = prepareData();
    HashMap<Integer, HttpEntity> documents = batchType.createDocuments(batches);
    assertEquals("HashMap of documents doesn't contain given amount of elements!", 3, documents.size());
}