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:org.kitodo.data.index.elasticsearch.type.UserGroupTypeTest.java

@Test
public void shouldCreateDocuments() throws Exception {
    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:gsn.wrappers.general.CSVWrapperTest.java

public boolean compare(HashMap<String, Serializable> a, HashMap<String, Serializable> b) {
    if (a.size() != b.size())
        return false;
    for (String key : a.keySet())
        if (!a.get(key).equals(b.get(key)))
            return false;
    return true;//ww w  .  j  a v a2 s.  com
}

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

@Test
public void shouldCreateDocuments() throws Exception {
    TemplateType processType = new TemplateType();

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

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

@Test
public void shouldCreateDocuments() throws Exception {
    WorkpieceType workpieceType = new WorkpieceType();

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

From source file:de.betterform.agent.web.servlet.ErrorServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    WebUtil.nonCachingResponse(response);
    //pick up the exception details
    String xpath = "unknown";
    String cause = "";
    String msg = (String) getSessionAttribute(request, "betterform.exception.message");
    if (msg != null) {
        int start = msg.indexOf("::");
        if (start > 3) {
            xpath = msg.substring(start + 2);
            msg = msg.substring(0, start);
        }//ww  w . j  a v a 2s .c om
        //todo: don't we need an 'else' here?
    }
    Exception ex = (Exception) getSessionAttribute(request, "betterform.exception");
    if (ex != null && ex.getCause() != null && ex.getCause().getMessage() != null) {
        cause = ex.getCause().getMessage();
    }

    //create XML structure for exception details
    Element rootNode = DOMUtil.createRootElement("error");
    DOMUtil.appendElement(rootNode, "context", request.getContextPath());
    DOMUtil.appendElement(rootNode, "url", request.getSession().getAttribute("betterform.referer").toString());
    DOMUtil.appendElement(rootNode, "xpath", xpath);
    DOMUtil.appendElement(rootNode, "message", msg);
    DOMUtil.appendElement(rootNode, "cause", cause);

    //transform is different depending on exception type
    if (ex instanceof XFormsErrorIndication) {
        Object o = ((XFormsErrorIndication) ex).getContextInfo();
        if (o instanceof HashMap) {
            HashMap<String, Object> map = (HashMap) ((XFormsErrorIndication) ex).getContextInfo();
            if (map.size() != 0) {
                Element contextinfo = rootNode.getOwnerDocument().createElement("contextInfo");
                rootNode.appendChild(contextinfo);
                for (Map.Entry<String, Object> entry : map.entrySet()) {
                    DOMUtil.appendElement(rootNode, entry.getKey(), entry.getValue().toString());
                }
            }
        }
        //todo: check -> there are contextInfos containing a simple string but seems to be integrated within above error message already - skip for now
        /*
                    else{
                    }
        */
        Document hostDoc = (Document) getSessionAttribute(request, "betterform.hostDoc");
        String serializedDoc = DOMUtil.serializeToString(hostDoc);
        //reparse
        try {
            byte bytes[] = serializedDoc.getBytes("UTF-8");
            Document newDoc = PositionalXMLReader.readXML(new ByteArrayInputStream(bytes));
            DOMUtil.prettyPrintDOM(newDoc);
            //eval xpath
            Node n = XPathUtil.evaluateAsSingleNode(newDoc, xpath);
            String linenumber = (String) n.getUserData("lineNumber");
            DOMUtil.appendElement(rootNode, "lineNumber", linenumber);

            DOMUtil.prettyPrintDOM(rootNode);

            WebUtil.doTransform(getServletContext(), response, newDoc, "highlightError.xsl", rootNode);
        } catch (Exception e) {
            e.printStackTrace();
        }

    } else {
        WebUtil.doTransform(getServletContext(), response, rootNode.getOwnerDocument(), "error.xsl", null);
    }
}

From source file:com.kenshoo.facts.FactsToJsonFileTest.java

@Test
public void writeFactsFile() throws Exception {
    HashMap<String, String> props = new HashMap<String, String>();
    props.put("Dog", "Labrador");
    props.put("Cat", "Lion");

    factsToJsonFile = prepareMock(props, null);

    String jsonFacts = FileUtils//from   ww  w .j av  a2  s .c  o m
            .readFileToString(factsToJsonFile.toJsonFileFromMapFacts(props, FACTS_JSON_FILE_NAME));
    HashMap<String, String> factsFromFile = new Gson().fromJson(jsonFacts, HashMap.class);

    Assert.assertEquals("Number of facts got from file is wrong", factsFromFile.size(), 2);
    Assert.assertEquals("Fact is different", factsFromFile.get("Dog"), "Labrador");
    Assert.assertEquals("Fact is different", factsFromFile.get("Cat"), "Lion");
    verify(factsToJsonFile, times(1)).getExternalFactsFolder();
    verify(factsToJsonFile, times(1)).toJsonFileFromMapFacts(same(props), same(FACTS_JSON_FILE_NAME));
    verify(factsToJsonFile, times(1)).toJsonFileFromMapFacts(same(props), same(FACTS_JSON_FILE_NAME),
            isNull(Set.class));
}

From source file:kmi.taa.core.SmallSetAnalyser.java

protected void detect(double threshold, String pptytype) {
    if (hm.isEmpty()) {
        return;//from  w  w w . ja  va 2  s.  c o  m
    }

    for (Integer k : hm.keySet()) {
        HashMap<Integer, Double> totalset = hm.get(k);
        if (totalset.size() > 2 && totalset.size() <= 4) {
            double mean = mean(totalset);
            double std = std(totalset);
            for (Integer tid : totalset.keySet()) {
                if (tid == 0)
                    continue;
                double data = totalset.get(tid);
                if (Math.abs(data - mean) <= threshold * std) {
                    notol.add(tid);
                }
            }
        } else {
            for (Integer tid : totalset.keySet()) {
                if (tid == 0)
                    continue;
                notol.add(tid);
            }
        }
    }

}

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

@Test
public void shouldCreateDocuments() {
    UserType userType = new UserType();

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

From source file:com.mobileman.moments.core.security.UserSecurityService.java

private void sanitizeUserCacheInfo(UserCacheInfo userCacheInfo) {
    if (false) {/*from w  ww.j  a  va  2  s  .  c  o  m*/
        HashMap<String, Date> tokens = userCacheInfo.getTokens();
        if (tokens.size() > 10) {
            tokens.clear(); // Protection against too many devices
        }
        // remove older items
        Date now = DateUtils.addSeconds(new Date(), -60 * 10);
        HashSet<String> ks = new HashSet<String>(tokens.keySet());
        for (String key : ks) {
            Date d = tokens.get(key);
            if (now.after(d)) {
                tokens.remove(key);
            }
        }
    }
}

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

/**
 * What does this do? Largely calls CountWeightedAlignmentsHelper
 * @param word1/*from w  w w  .  j av  a2 s .  com*/
 * @param word2
 * @param maxSubstringLength1
 * @param maxSubstringLength2
 * @param probs
 * @param internTable
 * @param normalization
 * @param weightByContextOnly
 * @return
 */
public static HashMap<Production, Double> CountWeightedAlignments(String word1, String word2,
        int maxSubstringLength1, int maxSubstringLength2, HashMap<Production, Double> probs,
        InternDictionary<String> internTable, NormalizationMode normalization, Boolean weightByContextOnly) {
    //HashMap<Pair<String, String>, double> weights = new HashMap<Pair<String, String>, double>();
    //HashMap<Pair<String, String>, double> weightCounts = new HashMap<Pair<String, String>, double>();
    //FindWeightedAlignmentsAverage(1, new List<Pair<String, String>>(), word1, word2, maxSubstringLength1, maxSubstringLength2, probs, weights, weightCounts, new HashMap<Pair<String, String>, Pair<double, double>>(), weightByOthers);
    Pair<HashMap<Production, Double>, Double> Q = CountWeightedAlignmentsHelper(word1, word2,
            maxSubstringLength1, maxSubstringLength2, probs,
            new HashMap<Production, Pair<HashMap<Production, Double>, Double>>());
    HashMap<Production, Double> weights = Q.getFirst();
    double probSum = Q.getSecond(); //the sum of the probabilities of all possible alignments

    // this is where the 1/y normalization happens for this word pair.
    HashMap<Production, Double> weights_norm = new HashMap<>(weights.size());
    for (Production key : weights.keySet()) {
        Double value = weights.get(key);
        if (weightByContextOnly) {
            double originalProb = probs.get(key);
            weights_norm.put(key,
                    value == 0 ? 0 : (value / originalProb) / (probSum - value + (value / originalProb)));
        } else
            weights_norm.put(key, value == 0 ? 0 : value / probSum);
    }

    return Normalize(word1, word2, weights_norm, internTable, normalization);
}