Example usage for java.util Map clear

List of usage examples for java.util Map clear

Introduction

In this page you can find the example usage for java.util Map clear.

Prototype

void clear();

Source Link

Document

Removes all of the mappings from this map (optional operation).

Usage

From source file:io.wcm.testing.mock.sling.servlet.MockSlingHttpServletRequest.java

private void parseQueryString(final Map<String, String[]> map, final String query)
        throws UnsupportedEncodingException {
    final Map<String, List<String>> queryPairs = new LinkedHashMap<>();
    final String[] pairs = query.split("&");
    for (String pair : pairs) {
        final int idx = pair.indexOf("=");
        final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), CharEncoding.UTF_8) : pair;
        if (!queryPairs.containsKey(key)) {
            queryPairs.put(key, new ArrayList<String>());
        }/*from  www .  ja va  2  s .  co  m*/
        final String value = idx > 0 && pair.length() > idx + 1
                ? URLDecoder.decode(pair.substring(idx + 1), CharEncoding.UTF_8)
                : null;
        queryPairs.get(key).add(value);
    }
    map.clear();
    for (Map.Entry<String, List<String>> entry : queryPairs.entrySet()) {
        map.put(entry.getKey(), entry.getValue().toArray(new String[entry.getValue().size()]));
    }
}

From source file:com.netsteadfast.greenstep.bsc.command.KpiReportBodyCommand.java

private void setImgIconBaseAndKpiInfo(BscStructTreeObj treeObj) throws ServiceException, Exception {
    BscReportSupportUtils.loadExpression();
    List<VisionVO> visions = treeObj.getVisions();
    Map<String, Object> paramMap = new HashMap<String, Object>();
    for (VisionVO vision : visions) {
        for (PerspectiveVO perspective : vision.getPerspectives()) {
            perspective.setImgIcon(BscReportSupportUtils.getHtmlIconBase("PERSPECTIVES",
                    perspective.getTarget(), perspective.getMin(), perspective.getScore(), "", "", 0));
            for (ObjectiveVO objective : perspective.getObjectives()) {
                objective.setImgIcon(BscReportSupportUtils.getHtmlIconBase("OBJECTIVES", objective.getTarget(),
                        objective.getMin(), objective.getScore(), "", "", 0));
                for (KpiVO kpi : objective.getKpis()) {
                    kpi.setImgIcon(BscReportSupportUtils.getHtmlIconBase("KPI", kpi.getTarget(), kpi.getMin(),
                            kpi.getScore(), kpi.getCompareType(), kpi.getManagement(), kpi.getQuasiRange()));
                    BscReportSupportUtils.fillKpiEmployees(kpi);
                    BscReportSupportUtils.fillKpiOrganizations(kpi);

                    // KPI attachment documents
                    paramMap.clear();
                    paramMap.put("kpiId", kpi.getId());
                    List<KpiAttacVO> attacs = kpiAttacService.findListVOByParams(paramMap);
                    for (int i = 0; attacs != null && i < attacs.size(); i++) {
                        KpiAttacVO attac = attacs.get(i);
                        DefaultResult<SysUploadVO> uploadResult = sysUploadService
                                .findForNoByteContent(attac.getUploadOid());
                        if (uploadResult.getValue() != null) {
                            attac.setShowName(uploadResult.getValue().getShowName());
                        } else {
                            attac.setShowName("unknown-" + attac.getUploadOid());
                        }/* w  ww .  j  av  a 2 s .co m*/
                        kpi.getAttachments().add(attac);
                    }

                }
            }
        }
    }
}

From source file:com.wolvereness.overmapped.OverMapped.java

private void reorderEntries(final Map<String, ByteClass> byteClasses) throws WellOrderedException {
    final List<ByteClass> classBuffer = WellOrdered.process(new ArrayList<ByteClass>(), byteClasses.values(),
            new WellOrdered.AbstractInformer<ByteClass>() {
                @Override//  w w  w. ja v a 2 s. c o m
                public void addPrecedingTo(final ByteClass token, final Collection<? super ByteClass> of) {
                    addIfFound(token.getParent(), of);
                    for (final String interfaceName : token.getInterfaces()) {
                        addIfFound(interfaceName, of);
                    }
                }

                private void addIfFound(final String name, final Collection<? super ByteClass> of) {
                    final ByteClass clazz = byteClasses.get(name);
                    if (clazz != null) {
                        of.add(clazz);
                    }
                }
            });
    byteClasses.clear();

    for (final ByteClass clazz : classBuffer) {
        byteClasses.put(clazz.getToken(), clazz);
    }
}

From source file:com.esd.ps.EmployerController.java

/**
 * ??//from   w w w  . j  a va2  s  .co  m
 * 
 * @param packId
 * @param unzip
 * @return
 */
@RequestMapping(value = "/updateUnzip", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updateUnzipPOST(int packId, int unzip) {
    Map<String, Object> map = new HashMap<>();
    packWithBLOBs pack = new packWithBLOBs();
    pack.setPackId(packId);
    pack.setUnzip(unzip);
    pack.setUnzipTime(new Date());
    packService.updateByPrimaryKeySelective(pack);
    map.clear();
    map.put(Constants.REPLAY, 1);
    return map;
}

From source file:de.hybris.platform.webservices.AbstractWebServicesTest.java

protected void createTestCustomers() throws ConsistencyCheckException, JaloBusinessException {

    final Language polishLanguage = C2LManager.getInstance().createLanguage("pl");
    //Create "Czech" language for testing
    C2LManager.getInstance().createLanguage("cs");

    final UserGroup userGroup1 = UserManager.getInstance().createUserGroup("testCustomerGroup1");
    final UserGroup userGroup2 = UserManager.getInstance().createUserGroup("testCustomerGroup2");
    final Customer customer1 = UserManager.getInstance().createCustomer("testCustomer1");
    customer1.setName("name1");
    customer1.setSessionLanguage(polishLanguage);
    customer1.setCustomerID("id1");
    customer1.setGroups(new HashSet(Arrays.asList(userGroup1, userGroup2)));

    final Customer customer2 = UserManager.getInstance().createCustomer("testCustomer2");
    customer2.setName("name2");
    customer2.setSessionLanguage(polishLanguage);
    customer2.setCustomerID("id2");

    final Employee employee1 = UserManager.getInstance().createEmployee("testEmployee1");
    employee1.setName("employee_name1");
    employee1.setSessionLanguage(polishLanguage);

    final Employee employee2 = UserManager.getInstance().createEmployee("testEmployee2");
    employee2.setName("employee_name2");
    employee2.setSessionLanguage(C2LManager.getInstance().getLanguageByIsoCode("cs"));

    final Map<String, String> paramMap = new HashMap<String, String>();
    paramMap.put(User.PASSWORDQUESTION, "My question1");
    paramMap.put(User.PASSWORDANSWER, "My answer1");
    ((User) customer1).setAllAttributes(paramMap);
    paramMap.clear();

    paramMap.put(User.PASSWORDQUESTION, "My question2");
    paramMap.put(User.PASSWORDANSWER, "My answer2");
    ((User) customer2).setAllAttributes(paramMap);
    paramMap.clear();//from w  ww . ja va 2s .c o  m

    paramMap.put(User.PASSWORDQUESTION, "My question3");
    paramMap.put(User.PASSWORDANSWER, "My answer3");
    ((User) employee1).setAllAttributes(paramMap);
    paramMap.clear();

    paramMap.put(User.PASSWORDQUESTION, "My question4");
    paramMap.put(User.PASSWORDANSWER, "My answer4");
    ((User) employee2).setAllAttributes(paramMap);
    paramMap.clear();

    final Address address1 = UserManager.getInstance().createAddress(customer1);
    address1.setAttribute(Address.STREETNAME, "street1");
    final Address address2 = UserManager.getInstance().createAddress(customer1);
    address2.setAttribute(Address.STREETNAME, "street2");
    final Address address3 = UserManager.getInstance().createAddress(employee1);
    address3.setAttribute(Address.STREETNAME, "street3");
    final Address address4 = UserManager.getInstance().createAddress(employee2);
    address4.setAttribute(Address.STREETNAME, "street4");
}

From source file:de.hybris.platform.webservices.AbstractWebServicesTest.java

protected void configureTestUsers() throws ConsistencyCheckException, JaloBusinessException {

    final Language polishLanguage = C2LManager.getInstance().createLanguage("pl");
    //Create "Czech" language for testing
    C2LManager.getInstance().createLanguage("cs");

    final Customer customer1 = (Customer) UserManager.getInstance().getUserByLogin("testCustomer1");
    customer1.setName("name1");
    customer1.setSessionLanguage(polishLanguage);
    customer1.setCustomerID("id1");

    final Customer customer2 = (Customer) UserManager.getInstance().getUserByLogin("testCustomer2");
    customer2.setName("name2");
    customer2.setSessionLanguage(polishLanguage);
    customer2.setCustomerID("id2");

    final Employee employee1 = (Employee) UserManager.getInstance().getUserByLogin("testEmployee1");
    employee1.setName("employee_name1");
    employee1.setSessionLanguage(polishLanguage);

    final Employee employee2 = (Employee) UserManager.getInstance().getUserByLogin("testEmployee2");
    employee2.setName("employee_name2");
    employee2.setSessionLanguage(C2LManager.getInstance().getLanguageByIsoCode("cs"));

    final Map<String, String> paramMap = new HashMap<String, String>();
    paramMap.put(User.PASSWORD_QUESTION, "My question1");
    paramMap.put(User.PASSWORD_ANSWER, "My answer1");
    ((User) customer1).setAllAttributes(paramMap);
    paramMap.clear();

    paramMap.put(User.PASSWORD_QUESTION, "My question2");
    paramMap.put(User.PASSWORD_ANSWER, "My answer2");
    ((User) customer2).setAllAttributes(paramMap);
    paramMap.clear();//w  w w  . ja  v a  2 s  .  c om

    paramMap.put(User.PASSWORD_QUESTION, "My question3");
    paramMap.put(User.PASSWORD_ANSWER, "My answer3");
    ((User) employee1).setAllAttributes(paramMap);
    paramMap.clear();

    paramMap.put(User.PASSWORD_QUESTION, "My question4");
    paramMap.put(User.PASSWORD_ANSWER, "My answer4");
    ((User) employee2).setAllAttributes(paramMap);
    paramMap.clear();

    final Address address1 = UserManager.getInstance().createAddress(customer1);
    address1.setAttribute(Address.STREETNAME, "street1");
    final Address address2 = UserManager.getInstance().createAddress(customer2);
    address2.setAttribute(Address.STREETNAME, "street2");
    final Address address3 = UserManager.getInstance().createAddress(customer2);
    address3.setAttribute(Address.STREETNAME, "street3");
    final Address address4 = UserManager.getInstance().createAddress(employee1);
    address4.setAttribute(Address.STREETNAME, "street4");
    final Address address5 = UserManager.getInstance().createAddress(employee2);
    address5.setAttribute(Address.STREETNAME, "street5");
}

From source file:com.flexive.ejb.beans.configuration.DivisionConfigurationEngineBean.java

/**
 * Get all resource FxString values that match a given key pattern.
 *
 * @param keyPattern        requested keypattern including wildcards ('%')
 * @param defaultLanguage default language to set in the returned FxString, if not available the first found
 *                        translation is the default language
 * @return an ordered (in regards to keys) map containing all found keys and FxString values
 * @throws FxApplicationException on errors
 * @since 3.1.6/*  w  ww  .  j  av  a  2s.c  o m*/
 */
private Map<String, FxString> getResourceValuesLike(String keyPattern, long defaultLanguage)
        throws FxApplicationException {
    Map<String, FxString> ret = new LinkedHashMap<String, FxString>(10, 5.0f);
    if (StringUtils.isBlank(keyPattern) || "%".equals(keyPattern) || "%%".equals(keyPattern)) {
        return ret;
    }

    keyPattern = keyPattern.trim();
    Connection con = null;
    PreparedStatement ps = null;
    try {
        con = Database.getDbConnection();
        ps = con.prepareStatement(
                "SELECT RKEY,LANG,RVAL FROM " + TBL_RESOURCES + "  WHERE RKEY LIKE ? ORDER BY RKEY ASC");

        ps.setString(1, keyPattern);
        ResultSet rs = ps.executeQuery();

        String currKey = null;
        String key;
        Map<Long, String> trans = new HashMap<Long, String>(10);
        long firstLang = -1;

        while (rs != null && rs.next()) {
            key = rs.getString(1);
            if (!key.equals(currKey)) {
                final FxString data = buildFxString(firstLang, defaultLanguage, trans);
                if (data != null)
                    ret.put(currKey, data);
                currKey = key;
                trans.clear();
                firstLang = -1;
            }
            if (firstLang == -1)
                firstLang = rs.getLong(2);
            trans.put(rs.getLong(2), rs.getString(3));
        }
        if (trans.size() > 0) {
            final FxString data = buildFxString(firstLang, defaultLanguage, trans);
            if (data != null)
                ret.put(currKey, data);
        }
        return ret;
    } catch (SQLException e) {
        throw new FxApplicationException(e, "ex.db.sqlError", e.getMessage());
    } finally {
        Database.closeObjects(DivisionConfigurationEngine.class, con, ps);
    }
}

From source file:ch.ralscha.extdirectspring.controller.RouterControllerPollTest.java

@Test
public void pollRequiredHeaderWithValue() throws Exception {
    Map<String, String> params = new LinkedHashMap<String, String>();
    params.put("id", "1");

    HttpHeaders headers = new HttpHeaders();
    headers.add("header", "headerValue");
    headers.add("anotherName", "headerValue1");
    headers.add("anotherName", "headerValue2");

    ExtDirectPollResponse resp = ControllerUtil.performPollRequest(mockMvc, "pollProvider",
            "messageRequestHeader2", "messageRequestHeader2", params, headers);

    assertThat(resp).isNotNull();/*from w w w.  ja  va  2 s  .  c om*/
    assertThat(resp.getType()).isEqualTo("event");
    assertThat(resp.getName()).isEqualTo("messageRequestHeader2");
    assertThat(resp.getData()).isEqualTo("1;headerValue1");
    assertThat(resp.getWhere()).isNull();
    assertThat(resp.getMessage()).isNull();

    params.clear();
    params.put("id", "2");

    resp = ControllerUtil.performPollRequest(mockMvc, "pollProvider", "messageRequestHeader2",
            "messageRequestHeader2", params, null, null, true);

    assertThat(resp).isNotNull();
    assertThat(resp.getType()).isEqualTo("exception");
    assertThat(resp.getName()).isEqualTo("messageRequestHeader2");
    assertThat(resp.getData()).isNull();
    assertThat(resp.getWhere()).isNull();
    assertThat(resp.getMessage()).isEqualTo("Server Error");

    params.clear();
    params.put("id", "3");
    headers = new HttpHeaders();
    headers.add("header", "headerValue");
    resp = ControllerUtil.performPollRequest(mockMvc, "pollProvider", "messageRequestHeader2",
            "messageRequestHeader2", params, headers, null, true);

    assertThat(resp).isNotNull();
    assertThat(resp.getType()).isEqualTo("exception");
    assertThat(resp.getName()).isEqualTo("messageRequestHeader2");
    assertThat(resp.getData()).isNull();
    assertThat(resp.getWhere()).isNull();
    assertThat(resp.getMessage()).isEqualTo("Server Error");
}

From source file:com.facebook.presto.accumulo.tools.RewriteMetricsTask.java

private void writeMetrics(long start, TypedValueCombiner.Encoder<Long> encoder, BatchWriter writer,
        Map<Text, Map<Text, Map<ColumnVisibility, AtomicLong>>> rowMap) throws MutationsRejectedException {
    for (Entry<Text, Map<Text, Map<ColumnVisibility, AtomicLong>>> familyMap : rowMap.entrySet()) {
        Mutation metricMutation = new Mutation(familyMap.getKey());
        for (Entry<Text, Map<ColumnVisibility, AtomicLong>> familyEntry : familyMap.getValue().entrySet()) {
            for (Entry<ColumnVisibility, AtomicLong> visibilityEntry : familyEntry.getValue().entrySet()) {
                if (visibilityEntry.getValue().get() > 0) {
                    metricMutation.put(familyEntry.getKey(), CARDINALITY_CQ_AS_TEXT, visibilityEntry.getKey(),
                            start, new Value(encoder.encode(visibilityEntry.getValue().get())));
                }//  www . j  a  v  a2  s .c  o m
            }
        }

        if (!dryRun) {
            writer.addMutation(metricMutation);
        }
    }
    rowMap.clear();
}

From source file:net.groupbuy.service.impl.StaticServiceImpl.java

@Transactional(readOnly = true)
public int buildSitemap() {
    int buildCount = 0;
    Template sitemapIndexTemplate = templateService.get("sitemapIndex");
    Template sitemapTemplate = templateService.get("sitemap");
    Map<String, Object> model = new HashMap<String, Object>();
    List<String> staticPaths = new ArrayList<String>();
    for (int step = 0, index = 0, first = 0, count = SITEMAP_MAX_SIZE;;) {
        try {/*from w  ww  .j  ava 2  s. com*/
            model.put("index", index);
            String templatePath = sitemapTemplate.getTemplatePath();
            String staticPath = FreemarkerUtils.process(sitemapTemplate.getStaticPath(), model);
            if (step == 0) {
                List<Article> articles = articleDao.findList(first, count, null, null);
                model.put("articles", articles);
                if (articles.size() < count) {
                    step++;
                    first = 0;
                    count -= articles.size();
                } else {
                    buildCount += build(templatePath, staticPath, model);
                    articleDao.clear();
                    articleDao.flush();
                    staticPaths.add(staticPath);
                    model.clear();
                    index++;
                    first += articles.size();
                    count = SITEMAP_MAX_SIZE;
                }
            } else if (step == 1) {
                List<Product> products = productDao.findList(first, count, null, null);
                model.put("products", products);
                if (products.size() < count) {
                    step++;
                    first = 0;
                    count -= products.size();
                } else {
                    buildCount += build(templatePath, staticPath, model);
                    productDao.clear();
                    productDao.flush();
                    staticPaths.add(staticPath);
                    model.clear();
                    index++;
                    first += products.size();
                    count = SITEMAP_MAX_SIZE;
                }
            } else if (step == 2) {
                List<Brand> brands = brandDao.findList(first, count, null, null);
                model.put("brands", brands);
                if (brands.size() < count) {
                    step++;
                    first = 0;
                    count -= brands.size();
                } else {
                    buildCount += build(templatePath, staticPath, model);
                    brandDao.clear();
                    brandDao.flush();
                    staticPaths.add(staticPath);
                    model.clear();
                    index++;
                    first += brands.size();
                    count = SITEMAP_MAX_SIZE;
                }
            } else if (step == 3) {
                List<Promotion> promotions = promotionDao.findList(first, count, null, null);
                model.put("promotions", promotions);
                buildCount += build(templatePath, staticPath, model);
                promotionDao.clear();
                promotionDao.flush();
                staticPaths.add(staticPath);
                if (promotions.size() < count) {
                    model.put("staticPaths", staticPaths);
                    buildCount += build(sitemapIndexTemplate.getTemplatePath(),
                            sitemapIndexTemplate.getStaticPath(), model);
                    break;
                } else {
                    model.clear();
                    index++;
                    first += promotions.size();
                    count = SITEMAP_MAX_SIZE;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return buildCount;
}