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.yahoo.ycsb.db.PostgreSQLJsonbClient.java

private OrderedFieldInfo getFieldInfo(HashMap<String, ByteIterator> values) {
    String fieldKeys = "";
    List<String> fieldValues = new ArrayList();
    int count = 0;
    for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
        fieldKeys += entry.getKey();//from   www . j a  va  2 s.  co  m
        if (count < values.size() - 1) {
            fieldKeys += ",";
        }
        fieldValues.add(count, entry.getValue().toString());
        count++;
    }

    return new OrderedFieldInfo(fieldKeys, fieldValues);
}

From source file:gov.medicaid.binders.BaseFormBinder.java

/**
 * Maps the model index for the credentials to the license index.
 * @param credentials the credentials//from  w  w  w  . j  a v a  2  s .co  m
 * @param licenses the licenses
 * @return a mapping from the actual index to the subset index
 */
protected Map<Integer, Integer> mapIndexes(List<LicenseType> credentials, List<LicenseType> licenses) {
    HashMap<Integer, Integer> mapping = new HashMap<Integer, Integer>();
    int i = 0;
    for (LicenseType credential : credentials) {
        int j = 0;
        for (LicenseType license : licenses) {
            if (license == credential) {
                mapping.put(i, j);
                break;
            }
            j++;
        }
        if (mapping.size() == licenses.size()) {
            break;
        }
        i++;
    }
    return mapping;
}

From source file:com.dungnv.vfw5.base.service.BaseFWServiceImpl.java

@Override
public boolean isDuplicate(Long id, HashMap<String, String> hashmap) {
    List<ConditionBean> lstCondition = new ArrayList<ConditionBean>();
    if (id != null) {
        lstCondition.add(new ConditionBean(tModel.getColId(), ParamUtils.OP_NOT_EQUAL, String.valueOf(id),
                ParamUtils.TYPE_NUMBER));
    }/* ww w . j  av a 2  s  .c  o m*/
    Field field = null;
    for (int i = 0; i < hashmap.size(); i++) {
        try {
            field = tModel.getClass().getDeclaredField(tModel.getUniqueColumn()[i]);
        } catch (Exception e) {
            System.out.println("ERROR: Wrong declared unique column " + tModel.getUniqueColumn()[i]
                    + " in BO file " + tModel.getModelName());
        }
        String type = ParamUtils.TYPE_STRING;
        if (ParamUtils.TYPE_NUMBER.indexOf(field.getType().getSimpleName().toUpperCase()) >= 0) {
            type = ParamUtils.TYPE_NUMBER;
        }
        lstCondition.add(new ConditionBean(tModel.getUniqueColumn()[i], ParamUtils.OP_EQUAL,
                hashmap.get(tModel.getUniqueColumn()[i]), type));
    }
    return gettDAO().find(tModel.getModelName(), lstCondition).isEmpty() ? false : true;
}

From source file:eu.stratosphere.pact.runtime.task.CombineTaskExternalITCase.java

@Test
public void testSingleLevelMergeCombineTask() {

    int keyCnt = 8192;
    int valCnt = 8;

    super.initEnvironment(3 * 1024 * 1024);
    super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 1);
    super.addOutput(this.outList);

    CombineTask<PactRecord> testTask = new CombineTask<PactRecord>();
    super.getTaskConfig().setLocalStrategy(LocalStrategy.COMBININGSORT);
    super.getTaskConfig().setMemorySize(3 * 1024 * 1024);
    super.getTaskConfig().setNumFilehandles(2);

    final int[] keyPos = new int[] { 0 };
    @SuppressWarnings("unchecked")
    final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class };
    PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(),
            super.getTaskConfig().getPrefixForInputParameters(0), keyPos, keyClasses);

    super.registerTask(testTask, MockCombiningReduceStub.class);

    try {//from   ww  w . j  a v  a2 s  .  c om
        testTask.invoke();
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Invoke method caused exception.");
    }

    int expSum = 0;
    for (int i = 1; i < valCnt; i++) {
        expSum += i;
    }

    // wee need to do the final aggregation manually in the test, because the
    // combiner is not guaranteed to do that
    HashMap<PactInteger, PactInteger> aggMap = new HashMap<PactInteger, PactInteger>();
    for (PactRecord record : this.outList) {
        PactInteger key = new PactInteger();
        PactInteger value = new PactInteger();
        key = record.getField(0, key);
        value = record.getField(1, value);
        PactInteger prevVal = aggMap.get(key);
        if (prevVal != null) {
            aggMap.put(key, new PactInteger(prevVal.getValue() + value.getValue()));
        } else {
            aggMap.put(key, value);
        }
    }

    Assert.assertTrue("Resultset size was " + aggMap.size() + ". Expected was " + keyCnt,
            aggMap.size() == keyCnt);

    for (PactInteger integer : aggMap.values()) {
        Assert.assertTrue("Incorrect result", integer.getValue() == expSum);
    }

    this.outList.clear();

}

From source file:com.esri.gpt.server.openls.provider.services.route.DetermineRouteProvider.java

/**
 * Executes route request/*from  ww w  . ja va2  s . c o  m*/
 * @param context
 * @throws Throwable
 */
private void executeRequest(OperationContext context) throws Throwable {
    long t1 = System.currentTimeMillis();

    String srvCfg = context.getRequestContext().getApplicationConfiguration().getCatalogConfiguration()
            .getParameters().getValue("openls.determineRoute");

    String srvCfgMapService = context.getRequestContext().getApplicationConfiguration()
            .getCatalogConfiguration().getParameters().getValue("openls.determineRoute.mapService");

    DetermineRouteParams routeParams = context.getRequestOptions().getDetermineRouteParams();

    RoutePlan rtPlan = routeParams.getRoutePlan();
    HashMap<String, Point> barriers = rtPlan.getAvoidPointList();
    GeocodedAddress[] avoidAddr = null;
    if (barriers != null) {
        avoidAddr = new GeocodedAddress[barriers.size()];
        Set<String> keys = barriers.keySet();
        Iterator<String> iter = keys.iterator();
        int cnt = 0;
        while (iter.hasNext()) {
            String key = iter.next();
            Point barrier = (Point) barriers.get(key);
            GeocodedAddress ga = new GeocodedAddress();
            ga.setX(barrier.getX());
            ga.setY(barrier.getY());
            avoidAddr[cnt] = ga;
            cnt++;
        }
    }

    HashMap<String, Point> points = rtPlan.getWayPointList();
    GeocodedAddress[] gcAddr = new GeocodedAddress[points.size()];
    Point start = points.get("start");
    GeocodedAddress gaStart = new GeocodedAddress();
    gaStart.setX(start.getX());
    gaStart.setY(start.getY());
    gcAddr[0] = gaStart;

    Point via = points.get("via");
    GeocodedAddress gaVia = new GeocodedAddress();
    gaVia.setX(via.getX());
    gaVia.setY(via.getY());
    gcAddr[1] = gaVia;

    Point end = points.get("start");
    GeocodedAddress gaEnd = new GeocodedAddress();
    gaEnd.setX(end.getX());
    gaEnd.setY(end.getY());
    gcAddr[2] = gaEnd;

    String sRouteRequest = makeRouteRequest(gcAddr, avoidAddr);

    // SUBMIT THE REQUEST
    String sUrl = srvCfg + "/solve?" + sRouteRequest;

    LOGGER.info("REQUEST=\n" + sUrl);

    URL url = new URL(sUrl);
    URLConnection conn = url.openConnection();

    // Get the response
    String line = "";
    String sResponse = "";

    InputStream is = conn.getInputStream();

    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader rd = new BufferedReader(isr);
    while ((line = rd.readLine()) != null) {
        sResponse += line;
    }
    rd.close();
    url = null;

    DetermineRouteParams determineRouteParams = parseRouteResponse(sResponse);

    if (routeParams.getRouteInstructions().getFormat().equals("text/plain")) {

        // rte.setInstSwitch(true);
    }

    determineRouteParams.setRouteMap(routeParams.getRouteMap());
    makeExportMapRequest(determineRouteParams, srvCfgMapService);

    context.getRequestOptions().setDetermineRouteParams(determineRouteParams);
    long t2 = System.currentTimeMillis();
    LOGGER.info("PERFORMANCE: " + (t2 - t1) + " ms required to perform service");
}

From source file:com.hin.hl7messaging.InvoiceSvgService.java

public Element createServiceElement(Document document, Element subG, HashMap<String, String> serviceMap,
        HashMap<String, String> xCoordinatesMap, String y, String style) {
    List<String> sortedKeys = new ArrayList<String>(serviceMap.size());
    sortedKeys.addAll(serviceMap.keySet());
    Collections.sort(sortedKeys, Collections.reverseOrder());

    int xService = 115;
    int xCost = 1150;

    for (String key : sortedKeys) {
        Element text = document.createElement("text");
        text.setAttribute("x", "223.8");
        text.setAttribute("y", "781.76");
        text.setAttribute("id", "legendTitle");
        Element tspan = document.createElement("tspan");
        tspan.setAttribute("id", "optimumTitle");
        tspan.setAttribute("x", String.valueOf(xService));
        tspan.setAttribute("y", y);
        tspan.setAttribute("style", style);
        tspan.setTextContent((String) key);
        text.appendChild(tspan);//from w  w w  . j a v a2  s .  c  o m
        subG.appendChild(text);

        Element text1 = document.createElement("text");
        text1.setAttribute("x", "223.8");
        text1.setAttribute("y", "781.76");
        text1.setAttribute("id", "legendTitle");
        Element tspan1 = document.createElement("tspan");
        tspan1.setAttribute("id", "optimumTitle");
        tspan1.setAttribute("x", String.valueOf(xCost));
        tspan1.setAttribute("y", y);
        tspan1.setAttribute("style", style);
        tspan1.setTextContent((String) serviceMap.get(key));
        text1.appendChild(tspan1);
        subG.appendChild(text1);

        int yAxis = Integer.parseInt(y);
        y = String.valueOf(yAxis + 30);
    }

    return subG;
}

From source file:edu.csupomona.nlp.tool.crawler.Facebook.java

/**
 * Start crawling Facebook using keyword.
 * Crawled data includes information for Posts and their Comments.
 * Will be stored in the file for each Page.
 * @param keyword               Keyword for searching
 * @throws JSONException/*from  ww w .j  a v  a2  s.  co m*/
 * @throws IOException
 */
public void crawl(String keyword) throws JSONException, IOException {
    //trace
    System.out.println("Start crawling with keyword=" + keyword);

    // get pages according to keyword
    HashMap<String, Page> pages = getPages(keyword, true);

    // crawl each page
    for (String pageId : pages.keySet()) {
        String filename = pageId + "_" + pages.get(pageId).getName().replaceAll(" ", "_") + "_"
                + pages.get(pageId).getLikes().toString() + ".txt";

        String fullPath = BASE_DIR_ + keyword + "/" + filename;
        System.out.println(fullPath);

        // start writing
        FileWriter fw = new FileWriter(fullPath);
        try (BufferedWriter bw = new BufferedWriter(fw)) {
            // get posts from the page
            HashMap<String, Post> posts = getPosts(pages.get(pageId));

            for (String postId : posts.keySet()) {
                Post post = posts.get(postId);

                // get likes
                HashMap<String, Like> likes = getLikes(post);

                int shareCount = (post.getSharesCount() != null ? post.getSharesCount() : 0);
                // write post information
                String line = "[P][" // type
                        + post.getCreatedTime().toString() + "][" // date
                        + post.getId() + "][" // id
                        + likes.size() + "][" // number of likes
                        + shareCount + "]:" // number of shares
                        + post.getMessage() // content
                        + "\n";
                System.out.println(line);
                bw.write(line);

                // get comments
                HashMap<String, Comment> comments = getComments(post);

                // write comment information
                for (String comId : comments.keySet()) {
                    Comment comment = comments.get(comId);

                    line = "[C][" // type
                            + comment.getCreatedTime().toString() + "][" // date
                            + comment.getId() + "][" // id
                            + comment.getLikeCount().toString() + "]:" // number of likes
                            + comment.getMessage() + "\n";
                    System.out.println(line);
                    bw.write(line);
                }
            }

            // save the time stamp
            DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
            bw.write("#### Finished at: " + df.format(Calendar.getInstance().getTime()) + " ####\n");
        }
    }
}

From source file:edu.ucla.stat.SOCR.analyses.gui.AnovaOneWay.java

public void mapToArray(HashMap<String, ArrayList<String>> map) { // used by AnovaTwoWay too??
    ////////System.out.println("GUI AnovaOneWay start mapToArray map = "+ map);

    int rowSize = map.size();
    ////////System.out.println("GUI AnovaOneWay rowSize = "+ rowSize);

    //int colSize = 1; // no column actually.
    yValue = new double[rowSize][categoryCount][];
    seriesName = new String[rowSize];
    int rowIndex = 0;
    Set<String> xKeySet = map.keySet();
    Iterator<String> xIterator = xKeySet.iterator();
    String xKey = null;//from   ww  w .  ja v a 2 s  .c om

    ArrayList<String> xArrayList = null; //( (ArrayList) xMap.get(xKey) );
    //xKeyInt = Integer.parseInt(xKey);
    //int groupIndex = 0;
    int arraySize = 0;
    while (xIterator.hasNext()) {
        xKey = (String) xIterator.next();
        seriesName[rowIndex] = xKey;
        xArrayList = ((ArrayList<String>) map.get(xKey));
        arraySize = xArrayList.size();
        ////////System.out.println("GUI AnovaOneWay arraySize = "+ arraySize);
        yValue[rowIndex][categoryIndex] = new double[arraySize];
        ////////System.out.println("GUI AnovaOneWayValue = "+ yValue[rowIndex][categoryIndex]);
        for (int j = 0; j < arraySize; j++) {
            //////////System.out.println("GUI AnovaOneWay in xArrayList.get(j) = " + Double.parseDouble( (String) xArrayList.get(j) ) );
            yValue[rowIndex][categoryIndex][j] = Double.parseDouble((String) xArrayList.get(j));

            ////////System.out.println("GUI AnovaOneWay " + " In mapToArray current entry[" +j + "] = " +Double.parseDouble((String) xArrayList.get(j)));

        }
        rowIndex++;
        ////////System.out.println("Model AnovaOneWay rowIndex = " + rowIndex);
    }
    //return yValue;
}

From source file:com.arm.connector.bridge.coordinator.processors.arm.GenericMQTTProcessor.java

protected boolean hasSubscriptions(String ep_name) {
    try {//from   ww w  .  ja  v  a2s.c o  m
        if (this.m_endpoints.get(ep_name) != null) {
            HashMap<String, Object> topic_data = (HashMap<String, Object>) this.m_endpoints.get(ep_name);
            if (topic_data != null && topic_data.size() > 0) {
                return true;
            }
        }
    } catch (Exception ex) {
        //silent
    }
    return false;
}

From source file:com.clustercontrol.jobmanagement.factory.FullJob.java

public static void initJobInfoCache() {
    long startTime = System.currentTimeMillis();
    HashMap<String, Map<String, JobInfo>> jobInfoCache = new HashMap<String, Map<String, JobInfo>>();

    Map<String, Map<String, JobMstEntity>> jobMstCache = getJobMstCache();

    for (Map.Entry<String, Map<String, JobMstEntity>> jobunitEntry : jobMstCache.entrySet()) {
        String jobunitId = jobunitEntry.getKey();
        Map<String, JobInfo> jobunitMap = new HashMap<String, JobInfo>();
        for (Map.Entry<String, JobMstEntity> jobEntry : jobunitEntry.getValue().entrySet()) {
            String jobId = jobEntry.getKey();
            try {
                jobunitMap.put(jobId, createJobInfo(jobEntry.getValue()));
            } catch (InvalidRole | JobMasterNotFound | HinemosUnknown e) {
                m_log.warn("failed initCache jobunitId=" + jobunitId + " jobId=" + jobId + ". "
                        + e.getClass().getSimpleName() + ", " + e.getMessage());
            }/*from   ww w.j a v a2 s .co m*/
        }
        jobInfoCache.put(jobunitId, jobunitMap);
    }

    m_log.info("init jobInfoCache " + (System.currentTimeMillis() - startTime) + "ms. size="
            + jobInfoCache.size());
    for (String jobunitId : jobMstCache.keySet()) {
        m_log.info("jobInfoCache key(jobunitId)=" + jobunitId + " size=" + jobInfoCache.get(jobunitId).size());
    }

    storeJobInfoCache(jobInfoCache);
}