List of usage examples for java.util HashMap values
public Collection<V> values()
From source file:org.apache.nutch.indexer.field.FieldFilters.java
/** * Configurable constructor./*from ww w . j a v a 2 s. c om*/ */ public FieldFilters(Configuration conf) { // get the field filter order, the cache, and all field filters String order = conf.get(FIELD_FILTER_ORDER); ObjectCache objectCache = ObjectCache.get(conf); this.fieldFilters = (FieldFilter[]) objectCache.getObject(FieldFilter.class.getName()); if (this.fieldFilters == null) { String[] orderedFilters = null; if (order != null && !order.trim().equals("")) { orderedFilters = order.split("\\s+"); } try { // get the field filter extension point ExtensionPoint point = PluginRepository.get(conf).getExtensionPoint(FieldFilter.X_POINT_ID); if (point == null) { throw new RuntimeException(FieldFilter.X_POINT_ID + " not found."); } // get all of the field filter plugins Extension[] extensions = point.getExtensions(); HashMap<String, FieldFilter> filterMap = new HashMap<String, FieldFilter>(); for (int i = 0; i < extensions.length; i++) { Extension extension = extensions[i]; FieldFilter filter = (FieldFilter) extension.getExtensionInstance(); LOG.info("Adding " + filter.getClass().getName()); if (!filterMap.containsKey(filter.getClass().getName())) { filterMap.put(filter.getClass().getName(), filter); } } // order the filters if necessary if (orderedFilters == null) { objectCache.setObject(FieldFilter.class.getName(), filterMap.values().toArray(new FieldFilter[0])); } else { ArrayList<FieldFilter> filters = new ArrayList<FieldFilter>(); for (int i = 0; i < orderedFilters.length; i++) { FieldFilter filter = filterMap.get(orderedFilters[i]); if (filter != null) { filters.add(filter); } } objectCache.setObject(FieldFilter.class.getName(), filters.toArray(new FieldFilter[filters.size()])); } } catch (PluginRuntimeException e) { throw new RuntimeException(e); } // set the filters in the cache this.fieldFilters = (FieldFilter[]) objectCache.getObject(FieldFilter.class.getName()); } }
From source file:org.powertac.du.DefaultBrokerService.java
HashMap<String, Integer> getCustomerCounts() { HashMap<String, Integer> result = new HashMap<String, Integer>(); for (TariffSpecification spec : customerSubscriptions.keySet()) { HashMap<CustomerInfo, CustomerRecord> customerMap = customerSubscriptions.get(spec); for (CustomerRecord record : customerMap.values()) { result.put(record.customer.getName() + spec.getPowerType(), record.subscribedPopulation); }/*from w w w .j a v a2 s . com*/ } return result; }
From source file:com.rest4j.generator.Generator.java
List<ModelNode> computeModelGraph(Document xml) throws Exception { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); xpath.setNamespaceContext(new APINamespaceContext()); XPathExpression refsExpr = xpath.compile(".//api:complex"); HashMap<String, ModelNode> graph = new HashMap<String, ModelNode>(); for (Node model : Util.it(xml.getDocumentElement().getElementsByTagName("model"))) { String name = ((Attr) model.getAttributes().getNamedItem("name")).getValue(); graph.put(name, new ModelNode(model)); }/* w w w . ja va 2 s. com*/ for (ModelNode node : graph.values()) { for (Node complex : Util.it((NodeList) refsExpr.evaluate(node.model, XPathConstants.NODESET))) { Ref ref = new Ref(); String type = complex.getAttributes().getNamedItem("type").getTextContent(); ModelNode referenced = graph.get(type); if (referenced == null) throw new IllegalArgumentException("Wrong reference from " + node.model.getAttributes().getNamedItem("name").getTextContent() + "." + complex.getAttributes().getNamedItem("name").getTextContent() + " to " + type); ref.referencedModel = referenced; if (complex.getAttributes().getNamedItem("collection").getTextContent().equals("array")) { ref.array = true; } node.references.add(ref); } } return new ArrayList<ModelNode>(graph.values()); }
From source file:org.powertac.du.DefaultBrokerService.java
double collectUsage(int index) { double result = 0.0; for (HashMap<CustomerInfo, CustomerRecord> customerMap : customerSubscriptions.values()) { for (CustomerRecord record : customerMap.values()) { result += record.getUsage(index); }// w ww. j av a 2 s.co m } log.debug("Usage(" + index + ")=" + result); return -result; // convert to needed energy account balance }
From source file:org.apache.axis2.transport.http.HTTPWorker.java
public void service(final AxisHttpRequest request, final AxisHttpResponse response, final MessageContext msgContext) throws HttpException, IOException { ConfigurationContext configurationContext = msgContext.getConfigurationContext(); final String servicePath = configurationContext.getServiceContextPath(); final String contextPath = (servicePath.startsWith("/") ? servicePath : "/" + servicePath) + "/"; String uri = request.getRequestURI(); String method = request.getMethod(); String soapAction = HttpUtils.getSoapAction(request); InvocationResponse pi;//from w ww . j av a 2 s . c o m if (method.equals(HTTPConstants.HEADER_GET)) { if (uri.equals("/favicon.ico")) { response.setStatus(HttpStatus.SC_MOVED_PERMANENTLY); response.addHeader(new BasicHeader("Location", "http://ws.apache.org/favicon.ico")); return; } if (!uri.startsWith(contextPath)) { response.setStatus(HttpStatus.SC_MOVED_PERMANENTLY); response.addHeader(new BasicHeader("Location", contextPath)); return; } if (uri.endsWith("axis2/services/")) { String s = HTTPTransportReceiver.getServicesHTML(configurationContext); response.setStatus(HttpStatus.SC_OK); response.setContentType("text/html"); OutputStream out = response.getOutputStream(); out.write(EncodingUtils.getBytes(s, HTTP.ISO_8859_1)); return; } if (uri.indexOf("?") < 0) { if (!uri.endsWith(contextPath)) { if (uri.endsWith(".xsd") || uri.endsWith(".wsdl")) { HashMap services = configurationContext.getAxisConfiguration().getServices(); String file = uri.substring(uri.lastIndexOf("/") + 1, uri.length()); if ((services != null) && !services.isEmpty()) { Iterator i = services.values().iterator(); while (i.hasNext()) { AxisService service = (AxisService) i.next(); InputStream stream = service.getClassLoader() .getResourceAsStream("META-INF/" + file); if (stream != null) { OutputStream out = response.getOutputStream(); response.setContentType("text/xml"); ListingAgent.copy(stream, out); out.flush(); out.close(); return; } } } } } } if (uri.endsWith("?wsdl2")) { String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 6); HashMap services = configurationContext.getAxisConfiguration().getServices(); AxisService service = (AxisService) services.get(serviceName); if (service != null) { boolean canExposeServiceMetadata = canExposeServiceMetadata(service); if (canExposeServiceMetadata) { response.setStatus(HttpStatus.SC_OK); response.setContentType("text/xml"); service.printWSDL2(response.getOutputStream(), getHost(request)); } else { response.setStatus(HttpStatus.SC_FORBIDDEN); } return; } } if (uri.endsWith("?wsdl")) { /** * service name can be hierarchical (axis2/services/foo/1.0.0/Version?wsdl) or * normal (axis2/services/Version?wsdl). */ String[] temp = uri.split(configurationContext.getServiceContextPath() + "/"); String serviceName = temp[1].substring(0, temp[1].length() - 5); HashMap services = configurationContext.getAxisConfiguration().getServices(); AxisService service = (AxisService) services.get(serviceName); if (service != null) { boolean canExposeServiceMetadata = canExposeServiceMetadata(service); if (canExposeServiceMetadata) { response.setStatus(HttpStatus.SC_OK); response.setContentType("text/xml"); service.printWSDL(response.getOutputStream(), getHost(request)); } else { response.setStatus(HttpStatus.SC_FORBIDDEN); } return; } } if (uri.endsWith("?xsd")) { String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 4); HashMap services = configurationContext.getAxisConfiguration().getServices(); AxisService service = (AxisService) services.get(serviceName); if (service != null) { boolean canExposeServiceMetadata = canExposeServiceMetadata(service); if (canExposeServiceMetadata) { response.setStatus(HttpStatus.SC_OK); response.setContentType("text/xml"); service.printSchema(response.getOutputStream()); } else { response.setStatus(HttpStatus.SC_FORBIDDEN); } return; } } //cater for named xsds - check for the xsd name if (uri.indexOf("?xsd=") > 0) { // fix for imported schemas String[] uriParts = uri.split("[?]xsd="); String serviceName = uri.substring(uriParts[0].lastIndexOf("/") + 1, uriParts[0].length()); String schemaName = uri.substring(uri.lastIndexOf("=") + 1); HashMap services = configurationContext.getAxisConfiguration().getServices(); AxisService service = (AxisService) services.get(serviceName); if (service != null) { boolean canExposeServiceMetadata = canExposeServiceMetadata(service); if (!canExposeServiceMetadata) { response.setStatus(HttpStatus.SC_FORBIDDEN); return; } //run the population logic just to be sure service.populateSchemaMappings(); //write out the correct schema Map schemaTable = service.getSchemaMappingTable(); XmlSchema schema = (XmlSchema) schemaTable.get(schemaName); if (schema == null) { int dotIndex = schemaName.indexOf('.'); if (dotIndex > 0) { String schemaKey = schemaName.substring(0, dotIndex); schema = (XmlSchema) schemaTable.get(schemaKey); } } //schema found - write it to the stream if (schema != null) { response.setStatus(HttpStatus.SC_OK); response.setContentType("text/xml"); schema.write(response.getOutputStream()); return; } else { InputStream instream = service.getClassLoader() .getResourceAsStream(DeploymentConstants.META_INF + "/" + schemaName); if (instream != null) { response.setStatus(HttpStatus.SC_OK); response.setContentType("text/xml"); OutputStream outstream = response.getOutputStream(); boolean checkLength = true; int length = Integer.MAX_VALUE; int nextValue = instream.read(); if (checkLength) length--; while (-1 != nextValue && length >= 0) { outstream.write(nextValue); nextValue = instream.read(); if (checkLength) length--; } outstream.flush(); return; } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int ret = service.printXSD(baos, schemaName); if (ret > 0) { baos.flush(); instream = new ByteArrayInputStream(baos.toByteArray()); response.setStatus(HttpStatus.SC_OK); response.setContentType("text/xml"); OutputStream outstream = response.getOutputStream(); boolean checkLength = true; int length = Integer.MAX_VALUE; int nextValue = instream.read(); if (checkLength) length--; while (-1 != nextValue && length >= 0) { outstream.write(nextValue); nextValue = instream.read(); if (checkLength) length--; } outstream.flush(); return; } // no schema available by that name - send 404 response.sendError(HttpStatus.SC_NOT_FOUND, "Schema Not Found!"); return; } } } } if (uri.indexOf("?wsdl2=") > 0) { String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.lastIndexOf("?wsdl2=")); if (processInternalWSDL(uri, configurationContext, serviceName, response, getHost(request))) return; } if (uri.indexOf("?wsdl=") > 0) { String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.lastIndexOf("?wsdl=")); if (processInternalWSDL(uri, configurationContext, serviceName, response, getHost(request))) return; } String contentType = null; Header[] headers = request.getHeaders(HTTPConstants.HEADER_CONTENT_TYPE); if (headers != null && headers.length > 0) { contentType = headers[0].getValue(); int index = contentType.indexOf(';'); if (index > 0) { contentType = contentType.substring(0, index); } } // deal with GET request pi = RESTUtil.processURLRequest(msgContext, response.getOutputStream(), contentType); } else if (method.equals(HTTPConstants.HEADER_POST)) { // deal with POST request String contentType = request.getContentType(); if (HTTPTransportUtils.isRESTRequest(contentType)) { pi = RESTUtil.processXMLRequest(msgContext, request.getInputStream(), response.getOutputStream(), contentType); } else { String ip = (String) msgContext.getProperty(MessageContext.TRANSPORT_ADDR); if (ip != null) { uri = ip + uri; } pi = HTTPTransportUtils.processHTTPPostRequest(msgContext, request.getInputStream(), response.getOutputStream(), contentType, soapAction, uri); } } else if (method.equals(HTTPConstants.HEADER_PUT)) { String contentType = request.getContentType(); msgContext.setProperty(Constants.Configuration.CONTENT_TYPE, contentType); pi = RESTUtil.processXMLRequest(msgContext, request.getInputStream(), response.getOutputStream(), contentType); } else if (method.equals(HTTPConstants.HEADER_DELETE)) { pi = RESTUtil.processURLRequest(msgContext, response.getOutputStream(), null); } else { throw new MethodNotSupportedException(method + " method not supported"); } Boolean holdResponse = (Boolean) msgContext.getProperty(RequestResponseTransport.HOLD_RESPONSE); if (pi.equals(InvocationResponse.SUSPEND) || (holdResponse != null && Boolean.TRUE.equals(holdResponse))) { try { ((RequestResponseTransport) msgContext.getProperty(RequestResponseTransport.TRANSPORT_CONTROL)) .awaitResponse(); } catch (InterruptedException e) { throw new IOException("We were interrupted, so this may not function correctly:" + e.getMessage()); } } // Finalize response RequestResponseTransport requestResponseTransportControl = (RequestResponseTransport) msgContext .getProperty(RequestResponseTransport.TRANSPORT_CONTROL); if (TransportUtils.isResponseWritten(msgContext) || ((requestResponseTransportControl != null) && requestResponseTransportControl.getStatus() .equals(RequestResponseTransport.RequestResponseTransportStatus.SIGNALLED))) { // The response is written or signalled. The current status is used (probably SC_OK). } else { // The response may be ack'd, mark the status as accepted. response.setStatus(HttpStatus.SC_ACCEPTED); } }
From source file:com.tamingtext.classifier.mlt.MoreLikeThisCategorizer.java
public CategoryHits[] categorize(Reader reader) throws IOException { Query query = moreLikeThis.like(reader); HashMap<String, CategoryHits> categoryHash = new HashMap<String, CategoryHits>(25); for (ScoreDoc sd : indexSearcher.search(query, maxResults).scoreDocs) { String cat = getDocClass(sd.doc); if (cat == null) continue; CategoryHits ch = categoryHash.get(cat); if (ch == null) { ch = new CategoryHits(); ch.setLabel(cat);//from w ww . j a v a2 s. c o m categoryHash.put(cat, ch); } ch.incrementScore(sd.score); } SortedSet<CategoryHits> sortedCats = new TreeSet<CategoryHits>(CategoryHits.byScoreComparator()); sortedCats.addAll(categoryHash.values()); return sortedCats.toArray(new CategoryHits[0]); }
From source file:com.redhat.jenkins.plugins.ci.CIBuildTrigger.java
private List<ParameterValue> getUpdatedParameters(Map<String, String> messageParams, List<ParameterValue> definedParams) { // Update any build parameters that may have values from the triggering message. HashMap<String, ParameterValue> newParams = new HashMap<String, ParameterValue>(); for (ParameterValue def : definedParams) { newParams.put(def.getName(), def); }//from w w w. j a va2s .com for (String key : messageParams.keySet()) { if (newParams.containsKey(key)) { StringParameterValue spv = new StringParameterValue(key, messageParams.get(key)); newParams.put(key, spv); } } return new ArrayList<ParameterValue>(newParams.values()); }
From source file:de.tor.tribes.ui.views.DSWorkbenchTroopsFrame.java
private void addTroopsManuallyEvent() { HashMap<Integer, Tribe> tribes = DataHolder.getSingleton().getTribes(); List<Tribe> tribesList = new LinkedList<>(); for (Tribe t : tribes.values()) { tribesList.add(t);/*from w w w.j a v a 2 s .c o m*/ } Collections.sort(tribesList, Tribe.CASE_INSENSITIVE_ORDER); DefaultComboBoxModel model = new DefaultComboBoxModel(tribesList.toArray(new Tribe[tribesList.size()])); jTroopAddTribe.setModel(model); model.setSelectedItem(GlobalOptions.getSelectedProfile().getTribe()); jTroopsAddDialog.setLocationRelativeTo(DSWorkbenchTroopsFrame.this); jTroopsAddDialog.setVisible(true); }
From source file:com.nononsenseapps.notepad.sync.googleapi.GoogleTaskSync.java
/** * Loads the remote lists from the database and merges the two lists. If the * remote list contains all lists, then this method only adds local db-ids * to the items. If it does not contain all of them, this loads whatever * extra items are known in the db to the list also. * //from w ww. j a v a2s . c o m * Since all lists are expected to be downloaded, any non-existing entries * are assumed to be deleted and marked as such. */ public static void mergeListsWithLocalDB(final Context context, final String account, final List<GoogleTaskList> remoteLists) { Log.d(TAG, "mergeList starting with: " + remoteLists.size()); final HashMap<String, GoogleTaskList> localVersions = new HashMap<String, GoogleTaskList>(); final Cursor c = context.getContentResolver().query(GoogleTaskList.URI, GoogleTaskList.Columns.FIELDS, GoogleTaskList.Columns.ACCOUNT + " IS ? AND " + GoogleTaskList.Columns.SERVICE + " IS ?", new String[] { account, GoogleTaskList.SERVICENAME }, null); try { while (c.moveToNext()) { GoogleTaskList list = new GoogleTaskList(c); localVersions.put(list.remoteId, list); } } finally { if (c != null) c.close(); } for (final GoogleTaskList remotelist : remoteLists) { // Merge with hashmap if (localVersions.containsKey(remotelist.remoteId)) { //Log.d(TAG, "Setting merge id"); remotelist.dbid = localVersions.get(remotelist.remoteId).dbid; //Log.d(TAG, "Setting merge delete status"); remotelist.setDeleted(localVersions.get(remotelist.remoteId).isDeleted()); localVersions.remove(remotelist.remoteId); } } // Remaining ones for (final GoogleTaskList list : localVersions.values()) { list.remotelyDeleted = true; remoteLists.add(list); } Log.d(TAG, "mergeList finishing with: " + remoteLists.size()); }
From source file:org.apache.axis2.deployment.DeploymentEngine.java
public static void addNewModule(AxisModule modulemetadata, AxisConfiguration axisConfiguration) throws AxisFault { Flow inflow = modulemetadata.getInFlow(); ClassLoader moduleClassLoader = modulemetadata.getModuleClassLoader(); if (inflow != null) { Utils.addFlowHandlers(inflow, moduleClassLoader); }/* ww w .j av a2 s.c o m*/ Flow outFlow = modulemetadata.getOutFlow(); if (outFlow != null) { Utils.addFlowHandlers(outFlow, moduleClassLoader); } Flow faultInFlow = modulemetadata.getFaultInFlow(); if (faultInFlow != null) { Utils.addFlowHandlers(faultInFlow, moduleClassLoader); } Flow faultOutFlow = modulemetadata.getFaultOutFlow(); if (faultOutFlow != null) { Utils.addFlowHandlers(faultOutFlow, moduleClassLoader); } axisConfiguration.addModule(modulemetadata); log.debug(Messages.getMessage(DeploymentErrorMsgs.ADDING_NEW_MODULE)); synchronized (axisConfiguration.getFaultyServicesDuetoModules()) { //Check whether there are faulty services due to this module HashMap<String, FaultyServiceData> faultyServices = (HashMap<String, FaultyServiceData>) axisConfiguration .getFaultyServicesDuetoModule(modulemetadata.getName()); faultyServices = (HashMap<String, FaultyServiceData>) faultyServices.clone(); // Here iterating a cloned hashmap and modifying the original hashmap. // To avoid the ConcurrentModificationException. for (FaultyServiceData faultyServiceData : faultyServices.values()) { axisConfiguration.removeFaultyServiceDuetoModule(modulemetadata.getName(), faultyServiceData.getServiceGroup().getServiceGroupName()); //Recover the faulty serviceGroup. addServiceGroup(faultyServiceData.getServiceGroup(), faultyServiceData.getServiceList(), faultyServiceData.getServiceLocation(), faultyServiceData.getCurrentDeploymentFile(), axisConfiguration); } } }