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:edu.msu.cme.rdp.seqmatch.cli.SeqmatchCheckRevSeq.java

/**
 * For each query, compares the S_ab scores of the original
 * sequence and the reversed but not complemented sequence. If the score differs above a threshold, the sequence is then
 * marked as bad seq. There are three output files: the seqmatch results of the good sequences, the seqmatch results of the bad sequences, 
 * and a fasta file of the corrected sequence strings of the bad sequences.
 * @param inFileName/*from   w w w  .j a va 2  s  .c  o m*/
 * @param traineeFile
 * @param outFileName
 * @param revOutFileName
 * @param correctedQueryOut
 * @param diffScoreCutoff
 * @param trainset_no
 * @throws IOException 
 */
public void checkRevSeq(String inFileName, String traineeFile, String outFileName, PrintWriter revOutputWriter,
        PrintStream correctedQueryOut, float diffScoreCutoff, String format, String traineeDesc)
        throws IOException {
    CheckReverseSeq checker = new CheckReverseSeq(traineeFile, traineeDesc);
    BufferedWriter writer = new BufferedWriter(new FileWriter(outFileName));

    Map<String, SeqMatchResultSet> resultMap = new HashMap();
    Sequence seq;

    SequenceReader reader = new SequenceReader(new File(inFileName));

    while ((seq = reader.readNextSequence()) != null) {
        ArrayList<SeqMatchResultSet> result = checker.check(seq);
        SeqMatchResultSet resultSet = result.get(0);
        float origScore = resultSet.iterator().next().getScore();

        // check the reverse without complement
        SeqMatchResultSet revResultSet = result.get(1);
        float revScore = revResultSet.iterator().next().getScore();

        if ((revScore - origScore) < diffScoreCutoff) {
            resultMap.put(seq.getSeqName(), resultSet);
            printResult(resultMap, format, writer, traineeDesc);
        } else { // this sequence is possibly a bad sequence
            resultMap.put(seq.getSeqName(), revResultSet);
            printResult(resultMap, format, revOutputWriter, traineeDesc);
            correctedQueryOut.print(">" + seq.getSeqName() + "\t" + seq.getDesc() + "\t" + revScore + "\t"
                    + origScore + "\n" + IUBUtilities.reverse(seq.getSeqString()) + "\n");
        }

        resultMap.clear();
    }

    reader.close();
    writer.close();
    revOutputWriter.close();
}

From source file:de.hybris.platform.order.CartServiceTest.java

@Test
public void testChangeSomeQuantitiesInCart() throws InvalidCartException, CalculationException {
    final ProductModel product0 = productService.getProduct("testProduct0");
    final ProductModel product1 = productService.getProduct("testProduct1");
    final ProductModel product2 = productService.getProduct("testProduct2");
    final ProductModel product3 = productService.getProduct("testProduct3");
    assertNotNull(product0);//  ww  w .ja va  2  s .  c o  m
    assertNotNull(product1);
    assertNotNull(product2);
    assertNotNull(product3);

    final CartModel cart = cartService.getSessionCart();
    cartService.addNewEntry(cart, product0, 10, null);
    cartService.addNewEntry(cart, product1, 15, null);
    cartService.addNewEntry(cart, product2, 1, null);
    cartService.addNewEntry(cart, product3, 18, null);
    modelService.save(cart);

    assertEquals("Number of entries", 4, cart.getEntries().size());
    calculationService.calculate(cart);
    assertEquals("Number of entries", 4, cart.getEntries().size());

    assertEquals(Long.valueOf(10), cartService.getEntryForNumber(cart, 0).getQuantity());
    assertEquals(Long.valueOf(15), cartService.getEntryForNumber(cart, 1).getQuantity());
    assertEquals(Long.valueOf(1), cartService.getEntryForNumber(cart, 2).getQuantity());
    assertEquals(Long.valueOf(18), cartService.getEntryForNumber(cart, 3).getQuantity());

    final Map<Integer, Long> newQuantities = new HashMap<Integer, Long>();
    newQuantities.put(Integer.valueOf(0), Long.valueOf(5));
    newQuantities.put(Integer.valueOf(1), Long.valueOf(0));
    newQuantities.put(Integer.valueOf(2), Long.valueOf(0));
    newQuantities.put(Integer.valueOf(3), Long.valueOf(10));
    cartService.updateQuantities(cart, newQuantities);

    //zero values
    assertEquals("Number of entries", 2, cart.getEntries().size());
    calculationService.calculate(cart);
    assertEquals("Number of entries", 2, cart.getEntries().size());

    assertEquals(Long.valueOf(5), cartService.getEntryForNumber(cart, 0).getQuantity());
    assertEquals(Long.valueOf(10), cartService.getEntryForNumber(cart, 3).getQuantity());

    newQuantities.clear();
    newQuantities.put(Integer.valueOf(3), Long.valueOf(30));

    cartService.updateQuantities(cart, newQuantities);
    assertEquals("Number of entries", 2, cart.getEntries().size());

    calculationService.calculate(cart);
    assertEquals("Number of entries", 2, cart.getEntries().size());

    assertEquals(Long.valueOf(5), cartService.getEntryForNumber(cart, 0).getQuantity());
    assertEquals(Long.valueOf(30), cartService.getEntryForNumber(cart, 3).getQuantity());

    newQuantities.clear();
    newQuantities.put(Integer.valueOf(0), Long.valueOf(-5)); // means: remove since it's < 1
    newQuantities.put(Integer.valueOf(3), Long.valueOf(5));

    cartService.updateQuantities(cart, newQuantities);
    assertEquals("Number of entries", 1, cart.getEntries().size());

    calculationService.calculate(cart);
    assertEquals("Number of entries", 1, cart.getEntries().size());

    assertEquals(Long.valueOf(5), cartService.getEntryForNumber(cart, 3).getQuantity());
}

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

/**
 * workerdown pack??//w  w w .  j a  v  a 2  s  .c o m
 * 
 * @param session
 * @param page
 * @param downPackName
 * @return
 */
@RequestMapping(value = "/workerHistoryPack", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> workerHistoryPackPOST(HttpSession session, int page, String downPackName) {
    Map<String, Object> map = new HashMap<String, Object>();

    int workerId = workerService
            .getWorkerIdByUserId(Integer.parseInt(session.getAttribute(Constants.USER_ID).toString()));

    //SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT);
    int totle = workerRecordService.getDownPackNameCountByworkerIdGroupByDownPackName(workerId, downPackName);
    //List<WorkerDownPackHistoryTrans> list = new ArrayList<>();
    int totlePage = 0;
    if (totle == 0) {
        map.clear();
        map.put(Constants.TOTLE, totle);
        map.put(Constants.TOTLE_PAGE, totlePage);
        map.put(Constants.LIST, null);
        return map;
    }
    List<Map<String, Object>> list = workerRecordService.getWorkerHis(workerId, page, Constants.ROW);
    //      List<workerRecord> workerRecordList = workerRecordService.getWorkerRecordLikeDownPackName(workerId, page, downPackName, Constants.ROW);
    //      logger.debug("workerRecordList:{}", workerRecordList);
    //      for (Iterator<workerRecord> iterator = workerRecordList.iterator(); iterator.hasNext();) {
    //         workerRecord workerRecord = (workerRecord) iterator.next();
    //         WorkerDownPackHistoryTrans workerDownPackHistoryTrans = new WorkerDownPackHistoryTrans();
    //         workerDownPackHistoryTrans.setTaskCount(workerRecordService.getTaskCountByDownPackName(workerRecord.getDownPackName()));
    //         workerDownPackHistoryTrans.setDownPackName(workerRecord.getDownPackName());
    //         logger.debug("status:{}", workerRecordService.getPackStatuByDownPackName(workerRecord.getDownPackName()));
    //         if (workerRecordService.getPackStatuByDownPackName(workerRecord.getDownPackName()) > 0) {
    //            workerDownPackHistoryTrans.setPackStatu(Constants.ZERO);
    //         } else {
    //            workerDownPackHistoryTrans.setPackStatu(Constants.ONE);
    //         }
    //
    //         if (workerRecord.getTaskDownTime() == null) {
    //            workerDownPackHistoryTrans.setDownTime(Constants.EMPTY);
    //         } else {
    //            workerDownPackHistoryTrans.setDownTime(sdf.format(workerRecord.getTaskDownTime()));
    //         }
    //         list.add(workerDownPackHistoryTrans);
    //      }
    map.clear();
    totlePage = (int) Math.ceil((double) totle / (double) Constants.ROW);
    map.put(Constants.TOTLE, totle);
    map.put(Constants.TOTLE_PAGE, totlePage);
    map.put(Constants.LIST, list);
    return map;
}

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

/**
 * //from ww  w .  ja va2s .  c  om
 * 
 * @param packId
 * @param taskLvl
 * @return
 */
@RequestMapping(value = "/updateTaskLvl", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updateTaskLvlPOST(int packId, int taskLvl) {
    Map<String, Object> map = new HashMap<>();
    packWithBLOBs pack = new packWithBLOBs();
    pack.setPackId(packId);
    pack.setPackLvl(taskLvl);
    packService.updateByPrimaryKeySelective(pack);
    task task = new task();
    task.setPackId(packId);
    task.setTaskLvl(taskLvl);
    taskService.updateByPackId(task);
    map.clear();
    map.put(Constants.REPLAY, 1);
    return map;
}

From source file:at.tugraz.sss.servs.dataexport.impl.SSDataExportImpl.java

@Override
public void dataExportUsersEntitiesTagsCategoriesTimestampsFileFromCircle(
        final SSDataExportUsersEntitiesTagsCategoriesTimestampsFileFromCirclePar par) throws SSErr {

    CSVWriter fileWriter = null;//from w w w  . ja va 2s . c o m
    FileOutputStream out = null;
    OutputStreamWriter writer = null;

    try {

        final Map<String, List<String>> tagsPerEntities = new HashMap<>();
        final Map<String, List<String>> categoriesPerEntities = new HashMap<>();
        final List<String> lineParts = new ArrayList<>();
        String resourceString;

        out = SSFileU.openOrCreateFileWithPathForWrite(SSConf.getSssWorkDirDataCsv() + par.fileName);
        writer = new OutputStreamWriter(out, Charset.forName(SSEncodingU.utf8.toString()));
        fileWriter = new CSVWriter(writer, SSStrU.semiColon.charAt(0));

        final SSCircle circle = ((SSEntityServerI) SSServReg.getServ(SSEntityServerI.class))
                .circleGet(new SSCircleGetPar(par, par.user, par.circle, null, //entityTypesToIncludeOnly
                        false, //setTags
                        null, //tagSpace
                        true, //setEntities,
                        false, //setUsers
                        false, //withUserRestriction
                        false)); //invokeEntityHandlers

        tagsPerEntities.clear();
        categoriesPerEntities.clear();

        tagsPerEntities.putAll(getTagsOfUserPerEntities(par, par.user, null, null, par.circle));

        categoriesPerEntities.putAll(getCategoriesPerEntities(par, par.user, //forUser
                null, //forUser
                null, par.circle));

        for (SSEntity entity : circle.entities) {

            resourceString = SSStrU.toStr(entity.id);

            lineParts.clear();

            lineParts.add(SSStrU.toStr(circle.id)); //user
            lineParts.add(resourceString);
            lineParts.add(SSStrU.toStr(SSDateU.dateAsLong() / 1000)); //TODO: provide tag time stamps for tags

            if (tagsPerEntities.containsKey(resourceString)) {
                lineParts.add(StringUtils.join(tagsPerEntities.get(resourceString), SSStrU.comma));
            } else {
                lineParts.add(SSStrU.empty);
            }

            if (categoriesPerEntities.containsKey(resourceString)) {
                lineParts.add(StringUtils.join(categoriesPerEntities.get(resourceString), SSStrU.comma));
            } else {
                lineParts.add(SSStrU.empty);
            }

            fileWriter.writeNext((String[]) lineParts.toArray(new String[lineParts.size()]));

            fileWriter.flush();
        }
    } catch (Exception error) {
        SSServErrReg.regErrThrow(error);
    } finally {

        if (out != null) {

            try {
                out.close();
            } catch (IOException ioError) {
                SSLogU.warn(SSWarnE.outputStreamCloseFailed, ioError);
            }
        }
    }
}

From source file:com.github.dozermapper.core.MappingProcessor.java

private Object mapMap(Object srcObj, Map srcMapValue, FieldMap fieldMap, Object destObj) {
    Map result;
    Map destinationMap = (Map) fieldMap.getDestValue(destObj);
    if (destinationMap == null) {
        result = destBeanCreator.create(srcMapValue.getClass());
    } else {//from   ww w.j a v  a2 s  .c o m
        result = destinationMap;
        if (fieldMap.isRemoveOrphans()) {
            result.clear();
        }
    }

    for (Entry<?, Object> srcEntry : ((Map<?, Object>) srcMapValue).entrySet()) {
        Object srcEntryValue = srcEntry.getValue();

        if (srcEntryValue == null) { // overwrites with null in any case
            result.put(srcEntry.getKey(), null);
            continue;
        }

        Object destEntryValue = mapOrRecurseObject(srcObj, srcEntryValue, srcEntryValue.getClass(), fieldMap,
                destObj);
        Object obj = result.get(srcEntry.getKey());
        if (obj != null && obj.equals(destEntryValue) && fieldMap.isNonCumulativeRelationship()) {
            mapToDestObject(null, srcEntryValue, obj, false, null);
        } else {
            result.put(srcEntry.getKey(), destEntryValue);
        }
    }
    return result;
}

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

/**
 * ?//ww w .  j  a  v  a  2 s  .  c om
 * 
 * @param oldPassWord
 * @param newPassWord
 * @param session
 * @return
 */
@RequestMapping(value = "/updatePassWord", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updatePassWordPOST(String oldPassWord, String newPassWord, String username,
        HttpSession session) {
    Map<String, Object> map = new HashMap<String, Object>();
    if (passWord(oldPassWord, session) == 1) {
        int userId = Integer.parseInt(session.getAttribute(Constants.USER_ID).toString());
        user user = new user();
        UsernameAndPasswordMd5 md5 = new UsernameAndPasswordMd5();
        String md5Password = md5.getMd5(username, newPassWord);
        user.setPassword(md5Password);
        user.setUserId(userId);
        StackTraceElement[] items = Thread.currentThread().getStackTrace();
        user.setUpdateMethod(items[1].toString());
        userService.updateByPrimaryKeySelective(user);
        map.clear();
        map.put(Constants.MESSAGE, MSG_UPDATE_SUCCESS);
        map.put(Constants.REPLAY, 1);
        return map;
    }
    map.clear();
    map.put(Constants.MESSAGE, MSG_OLD_PASSWORD_ERROR);
    map.put(Constants.REPLAY, 0);
    return map;
}

From source file:com.wso2telco.dep.mediator.RequestExecutor.java

/**
 * Removes the headers./*from w w w  .  jav a 2s  . c o m*/
 *
 * @param context
 *            the context
 */
public void removeHeaders(MessageContext context) {
    Object headers = ((Axis2MessageContext) context).getAxis2MessageContext()
            .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    if (headers != null && headers instanceof Map) {
        Map headersMap = (Map) headers;
        headersMap.clear();
    }
}

From source file:finderbots.recommenders.hadoop.WriteToSolrJob.java

@Override
public int run(String[] args) throws Exception {
    options = new Options();
    CmdLineParser parser = new CmdLineParser(options);
    String s = options.toString();// for debuging ease

    try {//from   www.  j av a2  s  . c  o  m
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        parser.printUsage(System.err);
        return -1;
    }
    fs = FileSystem.get(getConf());

    cleanOutputDirs();

    Path itemIndexPath = new Path(options.getItemIndexFilePath());
    Path userIndexPath = new Path(options.getUserIndexFilePath());
    Map fields = new HashMap<String, String>();

    //inputs
    Path bTransposeByMatrixPath = new Path(options.getBTransposeBMatrixDir());
    Path bUserHistoryMatrixPath = new Path(options.getBUserHistoryMatrixDir());

    //outputs
    Path solrItemsLinksDocsFilesPath = new Path(options.getSolrItemLinksDocsDir());
    Path solrUserHistoryDocsFilesPath = new Path(options.getSolrUserHistoryDir());

    if (options.getBTransposeAMatrixDir() != null && options.getAUserHistoryMatrixDir() != null) {
        //optional inputs
        Path bTransposeAMatrixPath = new Path(options.getBTransposeAMatrixDir());
        Path aUserHistoryMatrixPath = new Path(options.getAUserHistoryMatrixDir());

        fields.put("iD1", options.getItemIdFieldName());
        fields.put("dRM1FieldName", options.getBTranposeBFieldName());
        fields.put("dRM2FieldName", options.getBTransposeAFieldName());
        WriteDRMsToSolr join = new WriteDRMsToSolr(fields);
        join.joinDRMsWriteToSolr(itemIndexPath, itemIndexPath, bTransposeByMatrixPath, bTransposeAMatrixPath,
                solrItemsLinksDocsFilesPath);

        fields.clear();
        fields.put("iD1", options.getUserIdFieldName());
        fields.put("dRM1FieldName", options.getBUserHistoryFieldName());
        fields.put("dRM2FieldName", options.getAUserHistoryFieldName());
        join = new WriteDRMsToSolr(fields);
        join.joinDRMsWriteToSolr(userIndexPath, itemIndexPath, bUserHistoryMatrixPath, aUserHistoryMatrixPath,
                solrUserHistoryDocsFilesPath);
    } else { //only using B actions so no CoGroup join required
        fields.put("iD1", options.getItemIdFieldName());
        fields.put("dRM1FieldName", options.getBTranposeBFieldName());
        WriteDRMsToSolr join = new WriteDRMsToSolr(fields);
        join.writeDRMToSolr(itemIndexPath, itemIndexPath, bTransposeByMatrixPath, solrItemsLinksDocsFilesPath);

        fields.clear();
        fields.put("iD1", options.getUserIdFieldName());
        fields.put("dRM1FieldName", options.getBUserHistoryFieldName());
        join = new WriteDRMsToSolr(fields);
        join.writeDRMToSolr(userIndexPath, itemIndexPath, bUserHistoryMatrixPath, solrUserHistoryDocsFilesPath);
    }
    return 0;
}

From source file:com.meltmedia.cadmium.servlets.ClassLoaderLeakPreventor.java

/**
 * Clean the cache of BeanELResolver//ww  w . ja  v  a2s. com
 */
protected void clearBeanELResolverCache() {
    final Class beanElResolverClass = findClass("javax.el.BeanELResolver");
    if (beanElResolverClass != null) {
        boolean cleared = false;
        try {
            final Method purgeBeanClasses = beanElResolverClass.getDeclaredMethod("purgeBeanClasses",
                    ClassLoader.class);
            purgeBeanClasses.setAccessible(true);
            purgeBeanClasses.invoke(beanElResolverClass.newInstance(), getWebApplicationClassLoader());
            cleared = true;
        } catch (NoSuchMethodException e) {
            // Version of javax.el probably > 2.2; no real need to clear
        } catch (Exception e) {
            error(e);
        }

        if (!cleared) {
            // Fallback, if purgeBeanClasses() could not be called
            final Field propertiesField = findField(beanElResolverClass, "properties");
            if (propertiesField != null) {
                try {
                    final Map properties = (Map) propertiesField.get(null);
                    properties.clear();
                } catch (Exception e) {
                    error(e);
                }
            }
        }
    }
}