List of usage examples for java.util HashMap entrySet
Set entrySet
To view the source code for java.util HashMap entrySet.
Click Source Link
From source file:edu.utexas.cs.tactex.shiftingpredictors.ServerBasedShiftingPredictor.java
private void fillRepoWithPredictedSubscriptions( HashMap<TariffSpecification, HashMap<CustomerInfo, Double>> predictedCustomerSubscriptions) { // clean//from w w w .java 2 s . c om factoredCustomerService.cleanSubscriptionRelatedData(); TariffSubscriptionRepo tariffSubscriptionRepo = factoredCustomerService.getTariffSubscriptionRepo(); // record all subscriptions for (Entry<TariffSpecification, HashMap<CustomerInfo, Double>> entry : predictedCustomerSubscriptions .entrySet()) { TariffSpecification spec = entry.getKey(); Tariff tariff = tariffRepoMgr.findTariffById(spec.getId()); HashMap<CustomerInfo, Double> cust2subs = entry.getValue(); for (Entry<CustomerInfo, Double> custSub : cust2subs.entrySet()) { int count = (int) Math.round((double) custSub.getValue()); CustomerInfo custInfo = bundleCustInfos.get(custSub.getKey().getName()); TariffSubscription subscription = tariffSubscriptionRepo.getSubscription(custInfo, tariff); subscription.subscribe(count); } } }
From source file:com.fujitsu.dc.test.jersey.DcRestAdapter.java
/** * ????GET.//from www . j a va 2 s. co m * @param url URL * @param headers ?? * @return DcResponse * @throws DcException DAO */ public final DcResponse getAcceptEncodingGzip(final String url, final HashMap<String, String> headers) throws DcException { HttpUriRequest req = new HttpGet(url); req.addHeader("Accept-Encoding", "gzip"); for (Map.Entry<String, String> entry : headers.entrySet()) { req.setHeader(entry.getKey(), entry.getValue()); } req.addHeader("X-Dc-Version", DcCoreTestConfig.getCoreVersion()); debugHttpRequest(req, ""); DcResponse res = this.request(req); return res; }
From source file:com.eternitywall.ots.OtsCli.java
private static void multistamp(List<String> argsFiles, List<String> calendarsUrl, Integer m, String signatureFile, String algorithm) { // Parse input privateUrls HashMap<String, String> privateUrls = new HashMap<>(); if (signatureFile != null && signatureFile != "") { try {// ww w . ja v a2 s . c o m privateUrls = readSignature(signatureFile); } catch (Exception e) { log.severe("No valid signature file"); return; } } // Make list of detached files HashMap<String, DetachedTimestampFile> mapFiles = new HashMap<>(); for (String argsFile : argsFiles) { try { File file = new File(argsFile); Hash hash = Hash.from(file, Hash.getOp(algorithm)._TAG()); mapFiles.put(argsFile, DetachedTimestampFile.from(hash)); } catch (IOException e) { e.printStackTrace(); log.severe("File read error"); return; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); log.severe("Crypto error"); return; } } // Stamping Timestamp stampResult; try { List<DetachedTimestampFile> detaches = new ArrayList(mapFiles.values()); stampResult = OpenTimestamps.stamp(detaches, calendarsUrl, m, privateUrls); if (stampResult == null) { throw new IOException(); } } catch (IOException e) { e.printStackTrace(); log.severe("Stamp error"); return; } // Generate ots output files for (Map.Entry<String, DetachedTimestampFile> entry : mapFiles.entrySet()) { String argsFile = entry.getKey(); DetachedTimestampFile detached = entry.getValue(); String argsOts = argsFile + ".ots"; try { Path path = Paths.get(argsOts); if (Files.exists(path)) { System.out.println("File '" + argsOts + "' already exist"); } else { Files.write(path, detached.serialize()); System.out.println("The timestamp proof '" + argsOts + "' has been created!"); } } catch (Exception e) { e.printStackTrace(); log.severe("File '" + argsOts + "' writing error"); } } }
From source file:io.personium.test.jersey.PersoniumRestAdapter.java
/** * ????GET./*w ww . j a va 2s . c o m*/ * @param url URL * @param headers ?? * @return DcResponse * @throws PersoniumException DAO */ public final PersoniumResponse getAcceptEncodingGzip(final String url, final HashMap<String, String> headers) throws PersoniumException { HttpUriRequest req = new HttpGet(url); req.addHeader("Accept-Encoding", "gzip"); for (Map.Entry<String, String> entry : headers.entrySet()) { req.setHeader(entry.getKey(), entry.getValue()); } req.addHeader("X-Personium-Version", PersoniumCoreTestConfig.getCoreVersion()); debugHttpRequest(req, ""); PersoniumResponse res = this.request(req); return res; }
From source file:com.nridge.core.base.io.xml.DocumentXML.java
/** * Saves the previous assigned document (e.g. via constructor or set method) * to the print writer stream wrapped in a tag name specified in the parameter. * * @param aPW PrintWriter stream instance. * @param aParentTag Parent tag name. * @param aDocument Document instance. * @param anIndentAmount Indentation count. * * @throws java.io.IOException I/O related exception. *//*from w ww . ja v a 2s . c o m*/ public void save(PrintWriter aPW, String aParentTag, Document aDocument, int anIndentAmount) throws IOException { RelationshipXML relationshipXML; String docType = StringUtils.remove(aDocument.getType(), StrUtl.CHAR_SPACE); String parentTag = StringUtils.remove(aParentTag, StrUtl.CHAR_SPACE); IOXML.indentLine(aPW, anIndentAmount); if (StringUtils.isNotEmpty(aParentTag)) aPW.printf("<%s-%s", parentTag, docType); else aPW.printf("<%s", docType); if (!mIsSimple) { IOXML.writeAttrNameValue(aPW, "type", aDocument.getType()); IOXML.writeAttrNameValue(aPW, "name", aDocument.getName()); IOXML.writeAttrNameValue(aPW, "title", aDocument.getTitle()); IOXML.writeAttrNameValue(aPW, "schemaVersion", aDocument.getSchemaVersion()); } for (Map.Entry<String, String> featureEntry : aDocument.getFeatures().entrySet()) IOXML.writeAttrNameValue(aPW, featureEntry.getKey(), featureEntry.getValue()); aPW.printf(">%n"); DataTableXML dataTableXML = new DataTableXML(aDocument.getTable()); dataTableXML.setSaveFieldsWithoutValues(mSaveFieldsWithoutValues); dataTableXML.save(aPW, IO.XML_TABLE_NODE_NAME, anIndentAmount + 1); if (aDocument.relationshipCount() > 0) { ArrayList<Relationship> docRelationships = aDocument.getRelationships(); IOXML.indentLine(aPW, anIndentAmount + 1); aPW.printf("<%s>%n", IO.XML_RELATED_NODE_NAME); for (Relationship relationship : docRelationships) { relationshipXML = new RelationshipXML(relationship); relationshipXML.setSaveFieldsWithoutValues(mSaveFieldsWithoutValues); relationshipXML.save(aPW, IO.XML_RELATIONSHIP_NODE_NAME, anIndentAmount + 2); } IOXML.indentLine(aPW, anIndentAmount + 1); aPW.printf("</%s>%n", IO.XML_RELATED_NODE_NAME); } HashMap<String, String> docACL = aDocument.getACL(); if (docACL.size() > 0) { IOXML.indentLine(aPW, anIndentAmount + 1); aPW.printf("<%s>%n", IO.XML_ACL_NODE_NAME); for (Map.Entry<String, String> aclEntry : docACL.entrySet()) { IOXML.indentLine(aPW, anIndentAmount + 2); aPW.printf("<%s", IO.XML_ACE_NODE_NAME); IOXML.writeAttrNameValue(aPW, "name", aclEntry.getKey()); aPW.printf(">%s</%s>%n", StringEscapeUtils.escapeXml10(aclEntry.getValue()), IO.XML_ACE_NODE_NAME); } IOXML.indentLine(aPW, anIndentAmount + 1); aPW.printf("</%s>%n", IO.XML_ACL_NODE_NAME); } IOXML.indentLine(aPW, anIndentAmount); if (StringUtils.isNotEmpty(aParentTag)) aPW.printf("</%s-%s>%n", parentTag, docType); else aPW.printf("</%s>%n", docType); }
From source file:com.jetyun.pgcd.rpc.reflect.ClassAnalyzer.java
/** * Analyze a class and create a ClassData object containing all of the * public methods (both static and non-static) in the class. * //from ww w. java 2 s . co m * @param clazz * class to be analyzed. * * @return a ClassData object containing all the public static and * non-static methods that can be invoked on the class. */ private static ClassData analyzeClass(Class clazz) { log.info("analyzing " + clazz.getName()); Method methods[] = clazz.getMethods(); ClassData cd = new ClassData(); cd.clazz = clazz; // Create temporary method map HashMap staticMethodMap = new HashMap(); HashMap methodMap = new HashMap(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (method.getDeclaringClass() == Object.class) { continue; } int mod = methods[i].getModifiers(); if (!Modifier.isPublic(mod)) { continue; } Class param[] = method.getParameterTypes(); // don't count locally resolved args int argCount = 0; for (int n = 0; n < param.length; n++) { if (LocalArgController.isLocalArg(param[n])) { continue; } argCount++; } MethodKey mk = new MethodKey(method.getName(), argCount); ArrayList marr = (ArrayList) methodMap.get(mk); if (marr == null) { marr = new ArrayList(); methodMap.put(mk, marr); } marr.add(method); if (Modifier.isStatic(mod)) { marr = (ArrayList) staticMethodMap.get(mk); if (marr == null) { marr = new ArrayList(); staticMethodMap.put(mk, marr); } marr.add(method); } } cd.methodMap = new HashMap(); cd.staticMethodMap = new HashMap(); // Convert ArrayLists to arrays Iterator i = methodMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); MethodKey mk = (MethodKey) entry.getKey(); ArrayList marr = (ArrayList) entry.getValue(); if (marr.size() == 1) { cd.methodMap.put(mk, marr.get(0)); } else { cd.methodMap.put(mk, marr.toArray(new Method[0])); } } i = staticMethodMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); MethodKey mk = (MethodKey) entry.getKey(); ArrayList marr = (ArrayList) entry.getValue(); if (marr.size() == 1) { cd.staticMethodMap.put(mk, marr.get(0)); } else { cd.staticMethodMap.put(mk, marr.toArray(new Method[0])); } } return cd; }
From source file:com.photon.phresco.impl.IPhonePhrescoApplicationProcessor.java
private void storeConfigObjAsPlist(List<Configuration> configuration, String destPlistFile) throws PhrescoException { //FIXME: this logic needs to be revisited and should be fixed with XMLPropertyListConfiguration classes. try {/*from w w w .j a va 2 s. c om*/ XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration(); for (Configuration config : configuration) { if (FEATURES.equalsIgnoreCase(config.getType())) { String rootNode = ""; HashMap<String, Object> valueMap = new HashMap(); Properties properties = config.getProperties(); Enumeration em = properties.keys(); while (em.hasMoreElements()) { HashMap<String, Object> tempMap = new HashMap(); String key = (String) em.nextElement(); String value = properties.getProperty(key); String[] keySplited = key.split("\\."); rootNode = keySplited[0]; int length = keySplited.length; if (value != null && value instanceof String && value.toString().startsWith("[") && value.toString().endsWith("]")) { String arrayListvalue = value.toString().replace("[", "").replace("]", ""); String[] split = arrayListvalue.toString().split(","); Map<String, Object> keyValuePair = new HashMap<String, Object>(); List<String> asList = new ArrayList<String>(); for (String string : split) { asList.add(string.trim()); } String rootKey = ""; String arrayListKey = ""; if (length == 3) { rootKey = keySplited[1]; arrayListKey = keySplited[2]; keyValuePair.put(arrayListKey, asList); if (!valueMap.isEmpty()) { if (valueMap.containsKey(keySplited[1])) { HashMap<String, Object> object = (HashMap) valueMap.get(keySplited[1]); tempMap.put(arrayListKey, asList); for (Map.Entry<String, Object> entry : object.entrySet()) { tempMap.put(entry.getKey(), entry.getValue()); } valueMap.put(rootKey, tempMap); } else { valueMap.put(rootKey, keyValuePair); } } else { valueMap.put(rootKey, keyValuePair); } } else if (length == 2) { valueMap.put(keySplited[1], asList); } } else { String arrayListKey = ""; if (length == 2) { arrayListKey = keySplited[1]; valueMap.put(arrayListKey, value); } else if (length == 3) { HashMap localMap = new HashMap(); localMap.put(keySplited[2], value); if (!valueMap.isEmpty()) { if (valueMap.containsKey(keySplited[1])) { HashMap<String, Object> object = (HashMap) valueMap.get(keySplited[1]); tempMap.put(keySplited[2], value); for (Map.Entry<String, Object> entry : object.entrySet()) { tempMap.put(entry.getKey(), entry.getValue()); } valueMap.put(keySplited[1], tempMap); } else { valueMap.put(keySplited[1], localMap); } } else { valueMap.put(keySplited[1], localMap); } } } } plist.addProperty(rootNode, valueMap); } } plist.save(destPlistFile); } catch (ConfigurationException e) { throw new PhrescoException(e); } }
From source file:com.cloudera.kitten.appmaster.params.lua.WorkflowParameters.java
public HashMap<String, ContainerTracker> createTrackers(WorkflowService workflowService) { HashMap<String, ContainerTracker> trackers = new HashMap<String, ContainerTracker>(); for (Entry<String, ContainerLaunchParameters> e : getContainerLaunchParameters().entrySet()) { ContainerTracker tracker = new ContainerTracker(workflowService, e.getValue()); trackers.put(e.getKey(), tracker); }//from w ww.j a v a 2 s.c o m LOG.info("Trackers: " + trackers); for (Entry<String, ContainerTracker> e : trackers.entrySet()) { for (String in : workflow.getOperator(e.getKey()).getInput()) { addTrackerDependencyRecursive(in, e.getKey(), trackers); } } return trackers; }
From source file:it.polito.tellmefirst.web.rest.interfaces.EpubChaptersInterface.java
private String produceXML(HashMap<String, List<String[]>> chapters) throws TMFOutputException { LOG.debug("[produceXML] - BEGIN"); String xml;//from w w w. ja v a2 s . c om try { ByteArrayOutputStream out = new ByteArrayOutputStream(); TransformerHandler hd = initXMLDoc(out); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "service", "", "ClassifyEpubChapters"); hd.startElement("", "", "Classification", atts); int i = 0; Set set = chapters.entrySet(); Iterator iterator = set.iterator(); while (iterator.hasNext()) { Map.Entry me = (Map.Entry) iterator.next(); atts.clear(); if (i == 0) { hd.startElement("", "", "Chapters", atts); } atts.addAttribute("", "", "toc", "", me.getKey().toString()); hd.startElement("", "", "Chapter", atts); atts.clear(); ArrayList<String[]> topics = (ArrayList<String[]>) me.getValue(); int j = 0; for (String[] topic : topics) { atts.clear(); if (j == 0) { hd.startElement("", "", "Resources", atts); } atts.addAttribute("", "", "uri", "", topic[0]); atts.addAttribute("", "", "label", "", topic[1]); atts.addAttribute("", "", "title", "", topic[2]); atts.addAttribute("", "", "score", "", topic[3]); atts.addAttribute("", "", "mergedTypes", "", topic[4]); atts.addAttribute("", "", "image", "", topic[5]); hd.startElement("", "", "Resource", atts); hd.endElement("", "", "Resource"); j++; } if (j > 0) hd.endElement("", "", "Resources"); hd.endElement("", "", "Chapter"); i++; } if (i > 0) hd.endElement("", "", "Chapters"); hd.endElement("", "", "Classification"); hd.endDocument(); xml = out.toString("utf-8"); System.out.println(xml); } catch (Exception e) { throw new TMFOutputException("Error creating XML output.", e); } LOG.debug("[produceXML] - END"); return xml; }
From source file:ReferenceValueMap.java
/** * Accessor for the entry set.//from w w w . j a va2 s . co m * @return The Set. **/ public Set entrySet() { reap(); Set s = map.entrySet(); Iterator i = s.iterator(); HashMap m = new HashMap(s.size()); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); Reference ref = (Reference) entry.getValue(); Object obj = ref.get(); if (obj != null) { m.put(entry.getKey(), obj); } } return Collections.unmodifiableSet(m.entrySet()); }