List of usage examples for java.util Map clear
void clear();
From source file:org.jkan997.slingbeans.slingfs.FileSystemServer.java
public void loadFileObjectAttributes(Map<String, FileObjectAttribute> attrsMap, JSONObject json) { attrsMap.clear(); for (Map.Entry<String, Object> me : json.entrySet()) { String key = me.getKey(); Object obj = me.getValue(); String type = null;// w w w .j a v a 2 s. c om String typeKey = null; if (!(obj instanceof JSONObject)) { FileObjectAttribute foa = new FileObjectAttribute(); foa.setJsonValue(json, key); attrsMap.put(key, foa); } } }
From source file:com.glaf.core.todo.util.TodoXlsReader.java
public List<Todo> readXls(java.io.InputStream inputStream) { List<Todo> todos = new java.util.ArrayList<Todo>(); HSSFWorkbook wb = null;// w ww. j a v a 2 s. c om try { wb = new HSSFWorkbook(inputStream); HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row = sheet.getRow(1); Map<Integer, String> keyMap = new java.util.HashMap<Integer, String>(); Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); int cells = row.getPhysicalNumberOfCells(); for (int colIndex = 0; colIndex < cells; colIndex++) { HSSFCell cell = row.getCell(colIndex); keyMap.put(colIndex, cell.getStringCellValue()); } int sortNo = 1; Set<String> keys = new HashSet<String>(); for (int rowIndex = 2; rowIndex < sheet.getPhysicalNumberOfRows(); rowIndex++) { HSSFRow rowx = sheet.getRow(rowIndex); if (rowx == null) { continue; } // System.out.println(); dataMap.clear(); for (int colIndex = 0; colIndex < cells; colIndex++) { String fieldName = keyMap.get(colIndex); HSSFCell cell = rowx.getCell(colIndex); if (cell == null) { continue; } Object cellValue = null; switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_FORMULA: break; case HSSFCell.CELL_TYPE_BOOLEAN: cellValue = cell.getBooleanCellValue(); break; case HSSFCell.CELL_TYPE_NUMERIC: cellValue = cell.getNumericCellValue(); break; case HSSFCell.CELL_TYPE_STRING: if (StringUtils.isNotEmpty(cell.getRichStringCellValue().getString())) { cellValue = cell.getRichStringCellValue().getString(); } break; default: if (StringUtils.isNotEmpty(cell.getStringCellValue())) { cellValue = cell.getStringCellValue(); } break; } if (cellValue != null) { dataMap.put(fieldName, cellValue); // System.out.print("\t" + fieldName + "=" + cellValue); } } if (dataMap.get("code") != null) { String id = ParamUtils.getString(dataMap, "id"); Todo model = new Todo(); dataMap.remove("id"); Tools.populate(model, dataMap); if (!keys.contains(model.getCode())) { model.setSortNo(sortNo++); if (id != null) { model.setId(Long.parseLong(id)); } if (ParamUtils.getDouble(dataMap, "limitDay") > 0) { model.setLimitDay(ParamUtils.getInt(dataMap, "limitDay")); } todos.add(model); keys.add(model.getCode()); } } } } catch (Exception ex) { throw new RuntimeException(ex); } finally { if (wb != null) { try { wb.close(); wb = null; } catch (IOException e) { } } } return todos; }
From source file:edu.uci.ics.hyracks.api.rewriter.ActivityClusterGraphRewriter.java
/** * rewrite an activity cluster graph to eliminate * all one-to-one connections and merge one-to-one connected * DAGs into super activities.// w w w . ja va 2 s . c om * * @param acg * the activity cluster graph */ public void rewrite(ActivityClusterGraph acg) { acg.getActivityMap().clear(); acg.getConnectorMap().clear(); Map<IActivity, SuperActivity> invertedActivitySuperActivityMap = new HashMap<IActivity, SuperActivity>(); for (Entry<ActivityClusterId, ActivityCluster> entry : acg.getActivityClusterMap().entrySet()) { rewriteIntraActivityCluster(entry.getValue(), invertedActivitySuperActivityMap); } for (Entry<ActivityClusterId, ActivityCluster> entry : acg.getActivityClusterMap().entrySet()) { rewriteInterActivityCluster(entry.getValue(), invertedActivitySuperActivityMap); } invertedActivitySuperActivityMap.clear(); }
From source file:com.p2p.peercds.tracker.TrackerService.java
/** * Parse the query parameters using our defined BYTE_ENCODING. * * <p>/*from ww w .ja va2s .c o m*/ * Because we're expecting byte-encoded strings as query parameters, we * can't rely on SimpleHTTP's QueryParser which uses the wrong encoding for * the job and returns us unparsable byte data. We thus have to implement * our own little parsing method that uses BYTE_ENCODING to decode * parameters from the URI. * </p> * * <p> * <b>Note:</b> array parameters are not supported. If a key is present * multiple times in the URI, the latest value prevails. We don't really * need to implement this functionality as this never happens in the * Tracker HTTP protocol. * </p> * * @param request The request's full URI, including query parameters. * @return The {@link AnnounceRequestMessage} representing the client's * announce request. */ private HTTPAnnounceRequestMessage parseQuery(Request request) throws IOException, MessageValidationException { Map<String, BEValue> params = new HashMap<String, BEValue>(); try { String uri = request.getAddress().toString(); for (String pair : uri.split("[?]")[1].split("&")) { String[] keyval = pair.split("[=]", 2); if (keyval.length == 1) { this.recordParam(params, keyval[0], null); } else { this.recordParam(params, keyval[0], keyval[1]); } } } catch (ArrayIndexOutOfBoundsException e) { params.clear(); } // Make sure we have the peer IP, fallbacking on the request's source // address if the peer didn't provide it. if (params.get("ip") == null) { params.put("ip", new BEValue(request.getClientAddress().getAddress().getHostAddress(), BYTE_ENCODING)); } return HTTPAnnounceRequestMessage.parse(BEncoder.bencode(params)); }
From source file:com.boozallen.cognition.lens.CriteriaMatcherTest.java
@Ignore @Test/*from w w w. ja v a2s .com*/ public void testCriteriaMatcher() throws ConfigurationException { Map<Tuple2<String, String>, String> observedValues = new HashMap<>(); Criteria criteria = new Criteria().addKeyword("room"); criteria.useSpaceTokens(false); criteria.setCaseSensitive(true); criteria.addMatch(Field.USER, "twitterUser"); criteria.addMatch(Field.LOCATION, "USA"); criteria.addMatch(Field.LANGUAGE, "en"); criteria.addMatch(Field.KEYWORD, "room"); criteria.addMatch(Field.JSON, "{\"source\": \"TWITTER\""); SchemaAdapter schema = new SchemaAdapter(); schema.loadJson("datasift-twitter-schema.json"); criteria.setSchema(schema); // Test user lookup observedValues.clear(); observedValues.put(new Tuple2<String, String>("twitter.user.name", "twitter"), "twitterUser"); assertTrue(CriteriaMatcher.evaluate(criteria, observedValues)); observedValues.clear(); observedValues.put(new Tuple2<String, String>("twitter.user.name", "twitter"), "otherUser"); assertFalse(CriteriaMatcher.evaluate(criteria, observedValues)); // Test location lookup observedValues.clear(); observedValues.put(new Tuple2<String, String>("pip.location", "twitter"), "USA"); assertTrue(CriteriaMatcher.evaluate(criteria, observedValues)); observedValues.clear(); observedValues.put(new Tuple2<String, String>("pip.location.country", "twitter"), "USA"); assertTrue(CriteriaMatcher.evaluate(criteria, observedValues)); observedValues.clear(); observedValues.put(new Tuple2<String, String>("pip.location", "twitter"), "Mexico"); assertFalse(CriteriaMatcher.evaluate(criteria, observedValues)); observedValues.clear(); observedValues.put(new Tuple2<String, String>("pip.location.country", "twitter"), "Canada"); assertFalse(CriteriaMatcher.evaluate(criteria, observedValues)); // Test language lookup observedValues.clear(); observedValues.put(new Tuple2<String, String>("twitter.lang", "twitter"), "en"); assertTrue(CriteriaMatcher.evaluate(criteria, observedValues)); observedValues.clear(); observedValues.put(new Tuple2<String, String>("language.tag", "twitter"), "en"); assertTrue(CriteriaMatcher.evaluate(criteria, observedValues)); observedValues.clear(); observedValues.put(new Tuple2<String, String>("twitter.lang", "twitter"), "spanish"); assertFalse(CriteriaMatcher.evaluate(criteria, observedValues)); observedValues.clear(); observedValues.put(new Tuple2<String, String>("language.tag", "twitter"), "spanish"); assertFalse(CriteriaMatcher.evaluate(criteria, observedValues)); // Test keyword lookup observedValues.clear(); observedValues.put(new Tuple2<String, String>("interaction.content", "twitter"), "Bianca_Hdz15 .That room brings back memories"); assertTrue(CriteriaMatcher.evaluate(criteria, observedValues)); observedValues.clear(); observedValues.put(new Tuple2<String, String>("interaction.content", "twitter"), "This is not a string I am looking for"); assertFalse(CriteriaMatcher.evaluate(criteria, observedValues)); // Test JSON lookup observedValues.clear(); observedValues.put(new Tuple2<String, String>("data", "cognition.esjson"), "{\"source\": \"TWITTER\""); assertTrue(CriteriaMatcher.evaluate(criteria, observedValues)); observedValues.clear(); observedValues.put(new Tuple2<String, String>("data", "cognition.esjson"), "{\"source\": \"FACEBOOK\"}"); assertFalse(CriteriaMatcher.evaluate(criteria, observedValues)); // Test Case Sensitive criteria.setCaseSensitive(false); observedValues.clear(); observedValues.put(new Tuple2<String, String>("data", "cognition.esjson"), "{\"source\": \"Twitter\""); assertTrue(CriteriaMatcher.evaluate(criteria, observedValues)); criteria.setCaseSensitive(true); assertFalse(CriteriaMatcher.evaluate(criteria, observedValues)); // Test useSpaceTokens criteria.useSpaceTokens(true); criteria.addKeyword("here"); observedValues.clear(); observedValues.put(new Tuple2<String, String>("interaction.content", "twitter"), "There are many ways to skin a cat"); assertFalse(CriteriaMatcher.evaluate(criteria, observedValues)); criteria.useSpaceTokens(false); assertTrue(CriteriaMatcher.evaluate(criteria, observedValues)); }
From source file:com.espertech.esper.core.service.EPRuntimeIsolatedImpl.java
private void processScheduleHandles(ArrayBackedCollection<ScheduleHandle> handles) { if (ThreadLogUtil.ENABLED_TRACE) { ThreadLogUtil.trace("Found schedules for", handles.size()); }//ww w.j a v a2s . c o m if (handles.size() == 0) { return; } // handle 1 result separatly for performance reasons if (handles.size() == 1) { Object[] handleArray = handles.getArray(); EPStatementHandleCallback handle = (EPStatementHandleCallback) handleArray[0]; EPRuntimeImpl.processStatementScheduleSingle(handle, unisolatedServices, isolatedTimeEvalContext); handles.clear(); return; } Object[] matchArray = handles.getArray(); int entryCount = handles.size(); // sort multiple matches for the event into statements Map<EPStatementAgentInstanceHandle, Object> stmtCallbacks = schedulePerStmtThreadLocal.get(); stmtCallbacks.clear(); for (int i = 0; i < entryCount; i++) // need to use the size of the collection { EPStatementHandleCallback handleCallback = (EPStatementHandleCallback) matchArray[i]; EPStatementAgentInstanceHandle handle = handleCallback.getAgentInstanceHandle(); ScheduleHandleCallback callback = handleCallback.getScheduleCallback(); Object entry = stmtCallbacks.get(handle); // This statement has not been encountered before if (entry == null) { stmtCallbacks.put(handle, callback); continue; } // This statement has been encountered once before if (entry instanceof ScheduleHandleCallback) { ScheduleHandleCallback existingCallback = (ScheduleHandleCallback) entry; ArrayDeque<ScheduleHandleCallback> entries = new ArrayDeque<ScheduleHandleCallback>(); entries.add(existingCallback); entries.add(callback); stmtCallbacks.put(handle, entries); continue; } // This statement has been encountered more then once before ArrayDeque<ScheduleHandleCallback> entries = (ArrayDeque<ScheduleHandleCallback>) entry; entries.add(callback); } handles.clear(); for (Map.Entry<EPStatementAgentInstanceHandle, Object> entry : stmtCallbacks.entrySet()) { EPStatementAgentInstanceHandle handle = entry.getKey(); Object callbackObject = entry.getValue(); EPRuntimeImpl.processStatementScheduleMultiple(handle, callbackObject, unisolatedServices, isolatedTimeEvalContext); if ((isPrioritized) && (handle.isPreemptive())) { break; } } }
From source file:de.hybris.platform.order.ZoneDeliveryModeServiceTest.java
/** * Tries to search for the delivery values with the currency in the zone and with the specific delivery mode. * <ul>/* w w w .j av a 2 s .c om*/ * <li>tests there are 3 delivery cost values for EURO in Germany and with dhl,</li> * <li>tests there are 2 delivery cost values for EURO in Europe and with dhl,</li> * <li>tests there are 2 delivery cost values for EURO worldwide and with dhl.</li> * <li>tests there is no delivery cost values for USD in Germany and with dhl,</li> * <li>tests there is exactly one delivery cost value for USD worldwide and with dhl.</li> * </ul> */ @Test public void testGetDeliveryValues() { final Map<Double, Double> deliveryValues = new HashMap<Double, Double>(); final String euroCurrency = "EUR"; final String usdCurrency = "USD"; deliveryValues.put(Double.valueOf(0), Double.valueOf(6)); deliveryValues.put(Double.valueOf(20), Double.valueOf(4)); deliveryValues.put(Double.valueOf(50), Double.valueOf(0)); testGetDeliveryValues(euroCurrency, deZoneCode, dhlDeliveryModeCode, deliveryValues); deliveryValues.clear(); deliveryValues.put(Double.valueOf(0), Double.valueOf(10)); deliveryValues.put(Double.valueOf(100), Double.valueOf(8)); testGetDeliveryValues(euroCurrency, europeZoneCode, dhlDeliveryModeCode, deliveryValues); deliveryValues.clear(); deliveryValues.put(Double.valueOf(0), Double.valueOf(15)); deliveryValues.put(Double.valueOf(100), Double.valueOf(5)); testGetDeliveryValues(euroCurrency, worldZoneCode, dhlDeliveryModeCode, deliveryValues); deliveryValues.clear(); testGetDeliveryValues(usdCurrency, deZoneCode, dhlDeliveryModeCode, deliveryValues); deliveryValues.clear(); deliveryValues.put(Double.valueOf(0), Double.valueOf(25)); testGetDeliveryValues(usdCurrency, worldZoneCode, dhlDeliveryModeCode, deliveryValues); }
From source file:com.moviejukebox.writer.MovieJukeboxXMLWriter.java
/** * Create an element with the codec information in it. * * @param doc//from w ww . ja va 2 s. c o m * @param movieCodecs * @return */ private static Element createCodecsElement(Document doc, Set<Codec> movieCodecs) { Element eCodecs = doc.createElement("codecs"); Element eCodecAudio = doc.createElement("audio"); Element eCodecVideo = doc.createElement("video"); int countAudio = 0; int countVideo = 0; Map<String, String> codecAttribs = new HashMap<>(); for (Codec codec : movieCodecs) { codecAttribs.clear(); codecAttribs.put("format", codec.getCodecFormat()); codecAttribs.put("formatProfile", codec.getCodecFormatProfile()); codecAttribs.put("formatVersion", codec.getCodecFormatVersion()); codecAttribs.put("codecId", codec.getCodecId()); codecAttribs.put("codecIdHint", codec.getCodecIdHint()); codecAttribs.put(SOURCE, codec.getCodecSource().toString()); codecAttribs.put("bitrate", codec.getCodecBitRate()); if (codec.getCodecType() == CodecType.AUDIO) { codecAttribs.put(LANGUAGE, codec.getCodecLanguage()); codecAttribs.put("langugageFull", codec.getCodecFullLanguage()); codecAttribs.put("channels", String.valueOf(codec.getCodecChannels())); DOMHelper.appendChild(doc, eCodecAudio, "codec", codec.getCodec(), codecAttribs); countAudio++; } else { DOMHelper.appendChild(doc, eCodecVideo, "codec", codec.getCodec(), codecAttribs); countVideo++; } } eCodecAudio.setAttribute(COUNT, String.valueOf(countAudio)); eCodecVideo.setAttribute(COUNT, String.valueOf(countVideo)); eCodecs.appendChild(eCodecAudio); eCodecs.appendChild(eCodecVideo); return eCodecs; }
From source file:com.github.jknack.handlebars.internal.Parser.java
boolean reset(final Map<String, Object> map) { map.clear(); return true; }
From source file:com.aurel.track.fieldType.bulkSetters.DateBulkSetter.java
@Override public Object fromDisplayString(Map<String, String> displayStringMap, Locale locale) { if (displayStringMap == null) { return null; }/*from w w w.ja v a2s . c om*/ String value = displayStringMap.get(getKeyPrefix()); if (value == null) { return null; } switch (getRelation()) { case BulkRelations.MOVE_BY_DAYS: Integer intValue = null; try { intValue = Integer.valueOf(value); } catch (Exception e) { //remove the value with the wrong type (if for example the old value, according the old relation was a Date) displayStringMap.clear(); LOGGER.info("Converting the " + value + " to Integer from display string failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } return intValue; case BulkRelations.SET_TO: case BulkRelations.SET_EARLIEST_STARTING_FROM: case BulkRelations.SET_LATEST_ENDING_AT: //Date dateValue = DateTimeUtils.getInstance().parseDateFromCalendarGUI(value, locale); Date dateValue = DateTimeUtils.getInstance().parseGUIDate(value, locale); if (dateValue == null) { //remove the value with the wrong type (if for example the old value, according the old relation was an Integer) displayStringMap.clear(); } return dateValue; } return null; }