List of usage examples for java.util HashMap values
public Collection<V> values()
From source file:de.fhg.fokus.odp.middleware.ckan.CKANGatewayUtil.java
/** * Sort the passed Map by the values/* w w w. j a v a 2 s. c o m*/ * * @param passedMap * the HashMap to sort. * @return the sorted HashMap. */ @SuppressWarnings({ "rawtypes", "unchecked" }) private static LinkedHashMap sortHashMapByValues(HashMap<String, Long> passedMap) { List<String> mapKeys = new ArrayList<String>(passedMap.keySet()); List<Long> mapValues = new ArrayList<Long>(passedMap.values()); Comparator comparator = Collections.reverseOrder(); Collections.sort(mapValues, comparator); Collections.sort(mapKeys, comparator); LinkedHashMap<String, Long> sortedMap = new LinkedHashMap<String, Long>(); Iterator valueIt = mapValues.iterator(); while (valueIt.hasNext()) { Object val = valueIt.next(); Iterator keyIt = mapKeys.iterator(); while (keyIt.hasNext()) { Object key = keyIt.next(); String comp1 = passedMap.get(key).toString(); String comp2 = val.toString(); if (comp1.equals(comp2)) { passedMap.remove(key); mapKeys.remove(key); sortedMap.put((String) key, (Long) val); break; } } } return sortedMap; }
From source file:com.shishicai.app.utils.XmlToJson.java
private JSONObject convertTagToJson(Tag tag, boolean isListElement) { JSONObject json = new JSONObject(); // Content is injected as a key/value if (tag.getContent() != null) { String path = tag.getPath(); String name = getContentNameReplacement(path, DEFAULT_CONTENT_NAME); putContent(path, json, name, tag.getContent()); }/*from w w w . j a va2s .co m*/ try { HashMap<String, ArrayList<Tag>> groups = tag.getGroupedElements(); // groups by tag names so that we can detect lists or single elements for (ArrayList<Tag> group : groups.values()) { if (group.size() == 1) { // element, or list of 1 Tag child = group.get(0); if (isForcedList(child)) { // list of 1 JSONArray list = new JSONArray(); list.put(convertTagToJson(child, true)); String childrenNames = tag.getChild(0).getName(); json.put(childrenNames, list); } else { // stand alone element if (child.hasChildren()) { JSONObject jsonChild = convertTagToJson(child, false); json.put(child.getName(), jsonChild); } else { String path = child.getPath(); putContent(path, json, child.getName(), child.getContent()); } } } else { // list JSONArray list = new JSONArray(); for (Tag child : group) { list.put(convertTagToJson(child, true)); } String childrenNames = group.get(0).getName(); json.put(childrenNames, list); } } return json; // if (tag.isList() || isForcedList(tag)) { // JSONArray list = new JSONArray(); // ArrayList<Tag> children = tag.getChildren(); // for (Tag child : children) { // list.put(convertTagToJson(child, true)); // } // String childrenNames = tag.getChild(0).getName(); // json.put(childrenNames, list); // return json; // } else { // ArrayList<Tag> children = tag.getChildren(); // if (children.size() == 0) { // if (!isListElement) { // putContent(json, tag.getName(), tag.getContent()); // } // } else { // for (Tag child : children) { // if (child.hasChildren()) { // JSONObject jsonChild = convertTagToJson(child, false); // json.put(child.getName(), jsonChild); // } else { // putContent(json, child.getName(), child.getContent()); // } // } // } // return json; // } } catch (JSONException e) { e.printStackTrace(); } return null; }
From source file:de.tor.tribes.util.parser.SOSParser.java
@Override public List<SOSRequest> parse(String pData) { print("Start parsing SOS request"); List<SOSRequest> requests = new LinkedList<>(); try {/*ww w . j a va 2 s. com*/ HashMap<Tribe, SOSRequest> parsedData = parseRequests(pData); if (parsedData.isEmpty()) { print("Check short version"); parsedData = parseRequestsShort(pData); } else { print("Got results for long version"); } CollectionUtils.addAll(requests, parsedData.values()); } catch (Exception ignored) { } return requests; }
From source file:org.apache.axis2.transport.http.ListingAgent.java
public void processExplicitSchemaAndWSDL(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { HashMap services = configContext.getAxisConfiguration().getServices(); String filePart = req.getRequestURL().toString(); String schema = filePart.substring(filePart.lastIndexOf("/") + 1, filePart.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/" + schema); if (stream != null) { OutputStream out = res.getOutputStream(); res.setContentType("text/xml"); copy(stream, out);/*from www . j a v a2 s . c om*/ out.flush(); out.close(); return; } } } }
From source file:mml.handler.scratch.ScratchVersionSet.java
/** * Replace our versions with those in other * @param other the other ScratchVersionSet *//*w w w . ja va2 s . c om*/ public void upsert(ScratchVersionSet other) { HashMap<String, ScratchVersion> map = new HashMap<String, ScratchVersion>(); for (int i = 0; i < this.list.length; i++) { ScratchVersion sv = this.list[i]; map.put(sv.version, sv); } for (int i = 0; i < other.list.length; i++) { map.put(other.list[i].version, other.list[i]); } ScratchVersion[] newList = new ScratchVersion[map.size()]; Collection coll = map.values(); int i = 0; Iterator iter = coll.iterator(); while (iter.hasNext()) { ScratchVersion sv = (ScratchVersion) iter.next(); newList[i++] = sv; } this.list = newList; }
From source file:org.apache.axis2.description.AxisOperation.java
protected void onDisengage(AxisModule module) { AxisService service = getAxisService(); if (service == null) return;//from w w w. j a va 2s.c o m AxisConfiguration axisConfiguration = service.getAxisConfiguration(); PhaseResolver phaseResolver = new PhaseResolver(axisConfiguration); if (!service.isEngaged(module.getName()) && (axisConfiguration != null && !axisConfiguration.isEngaged(module.getName()))) { phaseResolver.disengageModuleFromGlobalChains(module); } phaseResolver.disengageModuleFromOperationChain(module, this); //removing operations added at the time of module engagemnt HashMap<QName, AxisOperation> moduleOperations = module.getOperations(); if (moduleOperations != null) { Iterator<AxisOperation> moduleOperations_itr = moduleOperations.values().iterator(); while (moduleOperations_itr.hasNext()) { AxisOperation operation = moduleOperations_itr.next(); service.removeOperation(operation.getName()); } } }
From source file:org.n52.geoar.newdata.PluginLoader.java
/** * Loads all plugins from SD card, compares version strings for plugins with * same names and loads the most recent plugin. * //w ww . ja va2 s . c o m * The plugin name is the filename without its ending and without optional * version string. A version string is introduced by a hyphen, following * dot-separated numbers, e.g. "-1.2.3" */ private static void loadPlugins() { String[] apksInDirectory = PLUGIN_DIRECTORY_PATH.list(PLUGIN_FILENAME_FILTER); if (apksInDirectory == null || apksInDirectory.length == 0) { IntroController.startIntro(!mInstalledPlugins.isEmpty()); return; } // Map to store all plugins with their versions for loading only the // newest ones HashMap<String, PluginInfo> pluginVersionMap = new HashMap<String, PluginInfo>(); for (String pluginFileName : apksInDirectory) { PluginInfo pluginInfo = readPluginInfoFromPlugin(new File(PLUGIN_DIRECTORY_PATH, pluginFileName)); if (pluginInfo == null) { LOG.info("Plugin " + pluginFileName + " has no plugin descriptor"); pluginInfo = readPluginInfoFromFilename(new File(PLUGIN_DIRECTORY_PATH, pluginFileName)); } if (pluginInfo.identifier == null) { LOG.error("Plugin " + pluginFileName + " has an invalid plugin descriptor and an invalid filename. Plugin excluded from loading."); continue; } if (pluginInfo.version == null) { pluginInfo.version = -1L; // Set unknown version to version -1 } PluginInfo pluginInfoMapping = pluginVersionMap.get(pluginInfo.identifier); if (pluginInfoMapping == null || pluginInfoMapping.version < pluginInfo.version) { // Plugin not yet known or newer pluginVersionMap.put(pluginInfo.identifier, pluginInfo); } } for (PluginInfo pluginInfo : pluginVersionMap.values()) { InstalledPluginHolder pluginHolder = new InstalledPluginHolder(pluginInfo); mInstalledPlugins.add(pluginHolder); } }
From source file:org.apache.stratos.adc.mgt.cli.CommandLineService.java
private void initializeApplicationManagementStub(String serverURL, String username, String password) throws AxisFault { HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator(); authenticator.setUsername(username); authenticator.setPassword(password); authenticator.setPreemptiveAuthentication(true); ApplicationManagementServiceStub stub; ConfigurationContext configurationContext = null; try {//from www . ja va 2 s. c o m configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext(); } catch (Exception e) { String msg = "Backend error occurred. Please contact the service admins!"; throw new AxisFault(msg, e); } HashMap<String, TransportOutDescription> transportsOut = configurationContext.getAxisConfiguration() .getTransportsOut(); for (TransportOutDescription transportOutDescription : transportsOut.values()) { transportOutDescription.getSender().init(configurationContext, transportOutDescription); } stub = new ApplicationManagementServiceStub(configurationContext, serverURL + "/services/ApplicationManagementService"); ServiceClient client = stub._getServiceClient(); Options option = client.getOptions(); option.setManageSession(true); option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, authenticator); option.setTimeOutInMilliSeconds(300000); this.stub = stub; }
From source file:gov.nih.nci.protexpress.util.ExperimentToXar23FormatConversionHelper.java
private ExperimentArchiveType.ExperimentRuns getExperimentRuns( HashMap<Long, ExperimentRunHolder> experimentRunHolders) { ExperimentArchiveType.ExperimentRuns xarExperimentRunsElement = getObjectFactory() .createExperimentArchiveTypeExperimentRuns(); for (ExperimentRunHolder expRunHolder : experimentRunHolders.values()) { xarExperimentRunsElement.getExperimentRun().add(getExperimentRunTypeElement(expRunHolder)); }//from ww w. ja v a2 s. c om return xarExperimentRunsElement; }
From source file:de.suse.swamp.core.workflow.WorkflowTemplate.java
/** * @return a list of templates that refer to this template as parentworkflow *///www. j av a 2 s. c o m public List getSubworkflowTemplates() { List templates = new ArrayList(); HashMap templateMap = WorkflowManager.getInstance().getWorkflowTemplates(); for (Iterator it = templateMap.values().iterator(); it.hasNext();) { TreeMap wfversions = (TreeMap) it.next(); for (Iterator tempIt = wfversions.values().iterator(); tempIt.hasNext();) { WorkflowTemplate temp = (WorkflowTemplate) tempIt.next(); if (temp.getParentWfName() != null && temp.getParentWfName().equals(this.name) && temp.getParentWfVersion().equals(this.version)) { templates.add(temp); } } } return templates; }