List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:in.sc.main.CategoryController.java
private HashMap generateRequestMap(String filterQ, HashMap fMap) { HashMap reqMap = new HashMap(); String[] split = filterQ.split(","); ArrayList filterList = null;/* www.j a v a 2 s . c om*/ for (int i = 0; i < split.length; i++) { String data = split[i].split("=")[0]; String val = split[i].split("=")[1]; if (reqMap.containsKey(data)) { filterList = (ArrayList) reqMap.get(data); } else { filterList = new ArrayList(); } filterList.add(val); reqMap.put(data, filterList); } if (reqMap.containsKey("price")) { ArrayList<String> priceList = (ArrayList) reqMap.get("price"); int minPrice = 1000000000, maxPrice = 0, tMin = 0, tMax = 0; for (String o : priceList) { String t[] = o.split("-"); tMin = Integer.parseInt(t[0]); tMax = Integer.parseInt(t[2]); if (tMin < minPrice) { minPrice = tMin; } if (tMax > maxPrice) { maxPrice = tMax; } } reqMap.put(ProductHelper.minprice, minPrice); reqMap.put(ProductHelper.maxprice, maxPrice); } StringBuilder whereC = new StringBuilder(); for (int i = 1; i < 16; i++) { if (reqMap.containsKey("f" + i)) { FeatureBean fBean = (FeatureBean) fMap.get("f" + i); ArrayList<String> fList = fBean.getFilterVals(); whereC.append(" AND ("); ArrayList<String> selfList = (ArrayList) reqMap.get("f" + i); int putOr = 0; for (String o : fList) { for (String o1 : selfList) { if (o.contains(o1)) { if (putOr > 0) { whereC.append(" OR "); } whereC.append(o.split("#")[1]); putOr++; } } } whereC.append(" ) "); } reqMap.put(ProductHelper.whereclause, whereC.toString()); } return reqMap; }
From source file:cn.edu.thss.iise.bpmdemo.statistics.actions.ModelReusePanel.java
private void createDataSet() throws IOException { BufferedReader reader = new BufferedReader(new FileReader(new File(this.filePath))); String line = null;/* w w w.j a va 2 s . co m*/ String name = null; int number = 0; HashMap<Integer, String> map = new HashMap<Integer, String>(); String[][] tempS = new String[100][2]; int lineNo = 0; while ((line = reader.readLine()) != null) { String[] sg = line.split(","); name = sg[0]; number = Integer.parseInt(sg[1]); tempS[lineNo][0] = name; tempS[lineNo][1] = sg[1]; // if (map.containsKey(number)) { String temp = map.get(number); map.remove(number); map.put(number, temp + ", " + name); } else { map.put(number, name); } lineNo++; } // load pie data data1 = new DefaultPieDataset(); Set<Integer> keys = map.keySet(); for (Integer key : keys) { data1.setValue(key + " times: " + map.get(key), key); } // load table data data2 = new String[lineNo + 1][2]; data2[0][0] = "Name"; data2[0][1] = "Reuse Times"; for (int i = 0; i < lineNo; i++) { data2[i + 1] = tempS[i]; } reader.close(); }
From source file:com.oneops.ops.dao.PerfHeaderDao.java
@SuppressWarnings("unchecked") public void createHeader(String key, String metricsJson) throws IOException { PerfHeader header = new PerfHeader(); header.setStep(60);/*from w ww.j a va 2 s.co m*/ PerfArchive.setDefaultArchives(header); logger.info("createHeader:" + key); // write info header List<HColumn<String, String>> columns = Arrays.asList(HFactory.createStringColumn(UPDATED, "0"), HFactory.createStringColumn(STEP, new Integer(header.getStep()).toString()), HFactory.createStringColumn(IP, "")); Mutator<byte[]> mutator = createMutator(keyspace, bytesSerializer); mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(INFO, columns, stringSerializer, stringSerializer, stringSerializer)); logger.debug("write INFO :: UPDATED:" + new Long(header.getUpdated()).toString() + " STEP:" + new Integer(header.getStep()).toString() + " IP:" + header.getIp()); String keysPending = "info"; // update datasource headers HashMap<String, HashMap<String, String>> metricMap = mapper.readValue(metricsJson, new TypeReference<Map<String, Map<String, String>>>() { }); for (String metricKey : metricMap.keySet()) { HashMap<String, String> attrs = metricMap.get(metricKey); String dsType = PerfDatasource.GAUGE; if (attrs.containsKey(DS_TYPE)) { dsType = attrs.get(DS_TYPE); } columns = Arrays.asList(HFactory.createStringColumn(TYPE, dsType), HFactory.createStringColumn(HEARTBEAT, "300"), HFactory.createStringColumn(MIN, NAN), HFactory.createStringColumn(MAX, NAN), HFactory.createStringColumn(LAST, NAN), HFactory.createStringColumn(INPUT, NAN), HFactory.createStringColumn(PDP, NAN)); mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(metricKey, columns, stringSerializer, stringSerializer, stringSerializer)); keysPending += ", " + metricKey; } Map<String, PerfArchive> rraMap = header.getRraMap(); for (String rraKey : rraMap.keySet()) { PerfArchive rra = rraMap.get(rraKey); columns = Arrays.asList(HFactory.createStringColumn(CF, rra.getConsolidationFunction()), HFactory.createStringColumn(XFF, new Double(rra.getXff()).toString()), HFactory.createStringColumn(STEPS, new Integer(rra.getSteps()).toString()), HFactory.createStringColumn(ROWS, new Integer(rra.getRows()).toString())); mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(rraKey, columns, stringSerializer, stringSerializer, stringSerializer)); keysPending += ", " + rraKey; } logger.debug("write keys:" + keysPending); // perform the insert mutator.execute(); }
From source file:it.cnr.icar.eric.client.xml.registry.infomodel.ExtrinsicObjectImpl.java
public ExtrinsicObjectImpl(LifeCycleManagerImpl lcm, ExtrinsicObjectType ebExtrinsicObj) throws JAXRException { super(lcm, ebExtrinsicObj); mimeType = ebExtrinsicObj.getMimeType(); opaque = ebExtrinsicObj.isIsOpaque(); contentVersionInfo = ebExtrinsicObj.getContentVersionInfo(); try {/* ww w. j a v a2 s. c o m*/ HashMap<String, Serializable> slotsMap = BindingUtility.getInstance() .getSlotsFromRegistryObject(ebExtrinsicObj); @SuppressWarnings("static-access") String slotName = BindingUtility.getInstance().CANONICAL_SLOT_EXTRINSIC_OBJECT_REPOSITORYITEM_URL; if (slotsMap.containsKey(slotName)) { String riURLStr = (String) slotsMap.get(slotName); File riFile = new File(riURLStr); repositoryItem = new DataHandler(new FileDataSource(riFile)); //Remove transient slot this.removeSlot(slotName); } } catch (JAXBException e) { throw new JAXRException(e); } }
From source file:com.oneops.ops.dao.PerfHeaderDao.java
@SuppressWarnings("unchecked") public String createSingleHeader(String key, String step, String metricsJson) throws IOException { logger.info("createHeader: " + key + " step: " + step + " metrics: " + metricsJson); PerfHeader header = new PerfHeader(); header.setStep(60);//from w w w .java2 s .c o m PerfArchive.setDefaultArchives(header); // write info header List<HColumn<String, String>> columns = Arrays.asList(HFactory.createStringColumn(UPDATED, "0"), HFactory.createStringColumn(STEP, "60"), HFactory.createStringColumn(IP, "")); Mutator<byte[]> mutator = createMutator(keyspace, bytesSerializer); mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(INFO, columns, stringSerializer, stringSerializer, stringSerializer)); logger.debug("write INFO :: UPDATED:" + new Long(header.getUpdated()).toString() + " STEP:" + new Integer(header.getStep()).toString() + " IP:" + header.getIp()); String keysPending = "info"; //"metrics":"{\"WriteOperations\":{\"display\":true,\"unit\":\"Per Second\",\"dstype\":\"DERIVE\",\"description\":\"Write Operations\"}}" //"metrics":"{\"ReadOperations\":{\"display\":true,\"unit\":\"per second\",\"dstype\":\"DERIVE\",\"description\":\"Read Operations\"}}" HashMap<String, HashMap<String, String>> metricMap = mapper.readValue(metricsJson, new TypeReference<Map<String, Map<String, String>>>() { }); for (String metricKey : metricMap.keySet()) { HashMap<String, String> attrs = metricMap.get(metricKey); String dsType = PerfDatasource.GAUGE; if (attrs.containsKey(DS_TYPE)) { dsType = attrs.get(DS_TYPE); } columns = Arrays.asList(HFactory.createStringColumn(TYPE, dsType), HFactory.createStringColumn(HEARTBEAT, "300"), HFactory.createStringColumn(MIN, NAN), HFactory.createStringColumn(MAX, NAN), HFactory.createStringColumn(LAST, NAN), HFactory.createStringColumn(INPUT, NAN), HFactory.createStringColumn(PDP, NAN)); mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(metricKey, columns, stringSerializer, stringSerializer, stringSerializer)); keysPending += ", " + metricKey; } Map<String, PerfArchive> rraMap = header.getRraMap(); for (String rraKey : rraMap.keySet()) { PerfArchive rra = rraMap.get(rraKey); columns = Arrays.asList(HFactory.createStringColumn(CF, rra.getConsolidationFunction()), HFactory.createStringColumn(XFF, new Double(rra.getXff()).toString()), HFactory.createStringColumn(STEPS, new Integer(rra.getSteps()).toString()), HFactory.createStringColumn(ROWS, new Integer(rra.getRows()).toString())); mutator.insert(key.getBytes(), HEADER, HFactory.createSuperColumn(rraKey, columns, stringSerializer, stringSerializer, stringSerializer)); keysPending += ", " + rraKey; } logger.debug("write keys:" + keysPending); // perform the insert mutator.execute(); return "{\"result_code\":200}\n"; }
From source file:com.intellectualcrafters.plot.commands.FlagCmd.java
@Override public boolean execute(final PlotPlayer player, final String... args) { /*/*w w w . ja v a2 s .co m*/ * plot flag set fly true * plot flag remove fly * plot flag remove use 1,3 * plot flag add use 2,4 * plot flag list */ if (args.length == 0) { MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>"); return false; } final Location loc = player.getLocation(); final Plot plot = MainUtil.getPlot(loc); if (plot == null) { MainUtil.sendMessage(player, C.NOT_IN_PLOT); return false; } if (!plot.hasOwner()) { sendMessage(player, C.PLOT_NOT_CLAIMED); return false; } if (!plot.isAdded(player.getUUID()) && !Permissions.hasPermission(player, "plots.set.flag.other")) { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other"); return false; } if (args.length > 1 && FlagManager.isReserved(args[1])) { MainUtil.sendMessage(player, C.NOT_VALID_FLAG); return false; } switch (args[0].toLowerCase()) { case "info": { if (!Permissions.hasPermission(player, "plots.set.flag")) { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.info"); return false; } if (args.length != 2) { MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>"); return false; } final AbstractFlag af = FlagManager.getFlag(args[1]); if (af == null) { MainUtil.sendMessage(player, C.NOT_VALID_FLAG); MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>"); return false; } // flag key MainUtil.sendMessage(player, C.FLAG_KEY, af.getKey()); // flag type MainUtil.sendMessage(player, C.FLAG_TYPE, af.value.getClass().getSimpleName()); // Flag type description MainUtil.sendMessage(player, C.FLAG_DESC, af.getValueDesc()); return true; } case "set": { if (!Permissions.hasPermission(player, "plots.set.flag")) { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag"); return false; } if (args.length < 3) { MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag set <flag> <value>"); return false; } final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase()); if (af == null) { MainUtil.sendMessage(player, C.NOT_VALID_FLAG); return false; } if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase()); return false; } final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " "); final Object parsed = af.parseValueRaw(value); if (parsed == null) { MainUtil.sendMessage(player, "&c" + af.getValueDesc()); return false; } final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed); final boolean result = FlagManager.addPlotFlag(plot, flag); if (!result) { MainUtil.sendMessage(player, C.FLAG_NOT_ADDED); return false; } MainUtil.sendMessage(player, C.FLAG_ADDED); APlotListener.manager.plotEntry(player, plot); return true; } case "remove": { if (!Permissions.hasPermission(player, "plots.flag.remove")) { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove"); return false; } if ((args.length != 2) && (args.length != 3)) { MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove <flag> [values]"); return false; } final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase()); if (af == null) { MainUtil.sendMessage(player, C.NOT_VALID_FLAG); return false; } if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase()); return false; } final Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase()); if (flag == null) { MainUtil.sendMessage(player, C.FLAG_NOT_IN_PLOT); return false; } if ((args.length == 3) && flag.getAbstractFlag().isList()) { final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " "); ((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value); DBFunc.setFlags(plot.world, plot, plot.settings.flags.values()); } else { final boolean result = FlagManager.removePlotFlag(plot, flag.getKey()); if (!result) { MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED); return false; } } MainUtil.sendMessage(player, C.FLAG_REMOVED); APlotListener.manager.plotEntry(player, plot); return true; } case "add": { if (!Permissions.hasPermission(player, "plots.flag.add")) { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.add"); return false; } if (args.length < 3) { MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag add <flag> <values>"); return false; } final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase()); if (af == null) { MainUtil.sendMessage(player, C.NOT_VALID_FLAG); return false; } if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase()); return false; } final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " "); final Object parsed = af.parseValueRaw(value); if (parsed == null) { MainUtil.sendMessage(player, "&c" + af.getValueDesc()); return false; } Flag flag = FlagManager.getPlotFlag(plot, args[1].toLowerCase()); if ((flag == null) || !flag.getAbstractFlag().isList()) { flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed); } else { ((FlagValue.ListValue) flag.getAbstractFlag().value).add(flag.getValue(), value); } final boolean result = FlagManager.addPlotFlag(plot, flag); if (!result) { MainUtil.sendMessage(player, C.FLAG_NOT_ADDED); return false; } DBFunc.setFlags(plot.world, plot, plot.settings.flags.values()); MainUtil.sendMessage(player, C.FLAG_ADDED); APlotListener.manager.plotEntry(player, plot); return true; } case "list": { if (!Permissions.hasPermission(player, "plots.flag.list")) { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.list"); return false; } if (args.length != 1) { MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag list"); return false; } final HashMap<String, ArrayList<String>> flags = new HashMap<>(); for (final AbstractFlag af : FlagManager.getFlags()) { final String type = af.value.getClass().getSimpleName().replaceAll("Value", ""); if (!flags.containsKey(type)) { flags.put(type, new ArrayList<String>()); } flags.get(type).add(af.getKey()); } String message = ""; String prefix = ""; for (final String flag : flags.keySet()) { message += prefix + "&6" + flag + ": &7" + StringUtils.join(flags.get(flag), ", "); prefix = "\n"; } MainUtil.sendMessage(player, message); return true; } } MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>"); return false; }
From source file:com.flipkart.foxtrot.core.querystore.impl.ElasticsearchQueryStoreTest.java
@Test public void testGetBulk() throws Exception { Map<String, Document> idValues = new HashMap<String, Document>(); List<String> ids = new Vector<String>(); for (int i = 0; i < 10; i++) { String id = UUID.randomUUID().toString(); ids.add(id);/*from w ww . j ava2s .c o m*/ idValues.put(id, new Document(id, System.currentTimeMillis(), mapper.valueToTree(Collections.singletonMap("TEST_NAME", "SINGLE_SAVE_TEST")))); idValues.get(id).setTimestamp(System.currentTimeMillis()); } queryStore.save(TestUtils.TEST_TABLE_NAME, ImmutableList.copyOf(idValues.values())); elasticsearchServer.refresh(ElasticsearchUtils.getIndices(TestUtils.TEST_TABLE_NAME)); List<Document> responseDocuments = queryStore.getAll(TestUtils.TEST_TABLE_NAME, ids); HashMap<String, Document> responseIdValues = new HashMap<String, Document>(); for (Document doc : responseDocuments) { responseIdValues.put(doc.getId(), doc); } assertNotNull("List of returned Documents should not be null", responseDocuments); for (String id : ids) { assertTrue("Requested Id should be present in response", responseIdValues.containsKey(id)); assertNotNull(responseIdValues.get(id)); assertEquals(id, responseIdValues.get(id).getId()); assertEquals("Timestamp should match request timestamp", idValues.get(id).getTimestamp(), responseIdValues.get(id).getTimestamp()); System.out.println("OK: " + id); } }
From source file:info.plugmania.mazemania.Util.java
/** * Takes two compressed inventories and returns a string representation of the difference * @param before HashMap<String,Integer> of inventory before changes * @param after HashMap<String,Integer> of inventory after changes * @return String in the form item:data,amount&item:data,amount@item:data,amount&item:data,amount where the first part is additions and second is subtractions *///from w ww .ja va2 s . c o m public String createDifferenceString(HashMap<String, Integer> before, HashMap<String, Integer> after) { List<String> add = new ArrayList<String>(); List<String> sub = new ArrayList<String>(); if ((before == null) || (after == null)) return ""; for (Entry<String, Integer> item : before.entrySet()) { //If the item does not appear after changes if (!after.containsKey(item.getKey())) { String loot = item.getKey().replace("_", " "); sub.add(ChatColor.GREEN + "1 " + loot + " " + ChatColor.BLUE); } //If the item is smaller after changes //else if (item.getValue() > after.get(item.getKey())) sub.add(item.getKey() + "," + (item.getValue() - after.get(item.getKey()))); //If the item is larger after changes //else if (item.getValue() < after.get(item.getKey())) add.add(item.getKey() + "," + (after.get(item.getKey()) - item.getValue())); } //for (Entry<String, Integer> item : after.entrySet()) { //If the item does not appear before changes //if (!before.containsKey(item.getKey())) add.add(item.getKey() + "," + item.getValue()); //} //return join(add.toArray(), "&",0) + "" + join(sub.toArray(), "&",0); return join(sub.toArray(), " & ", 0); }
From source file:in.flipbrain.controllers.Trail.java
private List<CommentDto> arrangeCommentsAsTree(List<CommentDto> nodes) { HashMap<Long, ArrayList<CommentDto>> tree = new HashMap<Long, ArrayList<CommentDto>>(); ArrayList<CommentDto> roots = new ArrayList<CommentDto>(); for (CommentDto n : nodes) { if (n.inReplyTo == null) { roots.add(n);//from w w w. j a v a 2s.c om } else { if (!tree.containsKey(n.inReplyTo)) { tree.put(n.inReplyTo, new ArrayList<CommentDto>()); } tree.get(n.inReplyTo).add(n); } } nodes.clear(); for (CommentDto n : roots) { nodes.add(n); nodes.addAll(getChildren(n.commentId, tree)); } return nodes; }
From source file:emlab.role.market.SubmitBidsToCommodityMarketRole.java
@Transactional public void act(EnergyProducer producer) { logger.info("Purchasing commodities"); HashMap<Substance, Double> fuelAmounts = new HashMap<Substance, Double>(); for (PowerPlant plant : reps.powerPlantRepository.findOperationalPowerPlantsByOwner(producer, getCurrentTick())) {//from w w w. j a va 2 s . co m double totalSupply = plant.calculateElectricityOutputAtTime(getCurrentTick()); for (SubstanceShareInFuelMix share : plant.getFuelMix()) { double amount = share.getShare() * totalSupply; Substance substance = share.getSubstance(); // already in? Than add to total if (fuelAmounts.containsKey(substance)) { amount += fuelAmounts.get(substance); } fuelAmounts.put(substance, amount); } } for (Substance substance : fuelAmounts.keySet()) { // find the totals and the right market. Place one bid for each // substance (fuel) if (!fuelAmounts.get(substance).isNaN() && fuelAmounts.get(substance) > 0) { Bid bid = reps.nonTransactionalCreateRepository.submitBidToMarket( reps.marketRepository.findFirstMarketBySubstance(substance), producer, getCurrentTick(), false, Double.MAX_VALUE, fuelAmounts.get(substance)); logger.info("Submited bid " + bid); } } }