List of usage examples for java.util LinkedHashMap get
public V get(Object key)
From source file:jp.primecloud.auto.ui.mock.service.MockInstanceService.java
protected List<ImageDto> getImages(Platform platform, LinkedHashMap<Long, ComponentType> componentTypeMap) { // ?/*from w w w .j ava 2 s . com*/ List<ImageDto> imageDtos = new ArrayList<ImageDto>(); List<Image> images = XmlDataLoader.getData("image.xml", Image.class); LinkedHashMap<Long, ImageAws> imageAwsMap = getImageAwsMap(); LinkedHashMap<Long, ImageVmware> imageVmwareMap = getImageVmwareMap(); LinkedHashMap<Long, ImageNifty> imageNiftyMap = getImageNiftyMap(); LinkedHashMap<Long, ImageCloudstack> imageCloudstackMap = getImageCloudstackMap(); for (Image image : images) { // ???? if (platform.getPlatformNo().equals(image.getPlatformNo()) == false || image.getSelectable() == false) { continue; } // ?????? String[] componentTypeNos = StringUtils.split(image.getComponentTypeNos(), ","); List<ComponentType> componentTypes = new ArrayList<ComponentType>(); if (componentTypeNos != null) { for (String componentTypeNo : componentTypeNos) { long no = Long.valueOf(componentTypeNo.trim()); ComponentType componentType = componentTypeMap.get(no); componentTypes.add(componentType); } } ImageDto imageDto = new ImageDto(); imageDto.setImage(image); imageDto.setImageAws(imageAwsMap.get(image.getImageNo())); imageDto.setImageVmware(imageVmwareMap.get(image.getImageNo())); imageDto.setImageNifty(imageNiftyMap.get(image.getImageNo())); imageDto.setImageCloudstack(imageCloudstackMap.get(image.getImageNo())); imageDto.setComponentTypes(componentTypes); imageDtos.add(imageDto); } return imageDtos; }
From source file:com.impetus.ankush2.cassandra.monitor.CassandraClusterMonitor.java
private String getNodeOwnership(JmxUtil jmxUtil, ObjectName mObjNameStorageService, String hostName) throws AnkushException { // Getting ownership Object attrOwnership = jmxUtil.getAttribute(mObjNameStorageService, CassandraConstants.Cassandra_JMX_Attributes.CASSANDRA_JMX_ATTRIBUTE_OWNERSHIP); System.out.println("attrOwnership: " + attrOwnership); if (attrOwnership == null) { throw new AnkushException("Could not get node ownership."); }/*from w w w . ja v a2 s .c o m*/ LinkedHashMap ownership = (LinkedHashMap) attrOwnership; for (Object key : ownership.keySet()) { if (key.toString().contains(hostName + "/")) { DecimalFormat df = new DecimalFormat("###.##"); return String.valueOf(df.format(((Float) ownership.get(key)) * 100)) + " %"; } } throw new AnkushException("Could not get node ownership."); }
From source file:edu.harvard.i2b2.adminTool.dataModel.ConceptTableModel.java
public void fillDataFromTable(ArrayList<ArrayList<ConceptTableRow>> list) { list.clear();// w ww. ja v a 2 s. co m ConceptTableRow row = null; ArrayList<ConceptTableRow> group = null; Integer curRow = null; LinkedHashMap<Integer, ArrayList<ConceptTableRow>> rowMap = new LinkedHashMap<Integer, ArrayList<ConceptTableRow>>(); for (int i = 1; i < rowCount; i++) { row = new ConceptTableRow(); curRow = new Integer((String) content.get("0/" + i)); row.rowNumber = curRow.intValue(); if (!rowMap.containsKey(curRow)) { group = new ArrayList<ConceptTableRow>(); list.add(group); rowMap.put(curRow, group); } else { group = rowMap.get(curRow); } row.conceptName = (String) content.get("1/" + i); row.dateText = (String) content.get("2/" + i); row.valueText = (String) content.get("3/" + i); row.modifierText = (String) content.get("4/" + i); row.height = (String) content.get("5/" + i); row.color = (RGB) content.get("6/" + i); row.conceptXml = (String) content.get("7/" + i); row.data = (QueryModel) content.get("8/" + i); row.rowId = i; group.add(row); } }
From source file:com.android.mtkex.chips.BaseRecipientAdapter.java
private static void putOneEntry(TemporaryEntry entry, boolean isAggregatedEntry, LinkedHashMap<Long, List<RecipientEntry>> entryMap, List<RecipientEntry> nonAggregatedEntries, Set<String> existingDestinations) { /// M: Let all entries which have same destination can be shown. if (!mShowDuplicateResults) { if (existingDestinations.contains(entry.destination)) { return; }/*from w ww . j a v a2 s. c o m*/ } existingDestinations.add(entry.destination); if (!isAggregatedEntry) { nonAggregatedEntries.add(RecipientEntry.constructTopLevelEntry(entry.displayName, entry.displayNameSource, entry.destination, entry.destinationType, entry.destinationLabel, entry.contactId, entry.dataId, entry.thumbnailUriString, true, entry.isGalContact)); /// M: Set destination kind of the recipient entry if the contact entry is queried from email. @{ if (mQueryType == QUERY_TYPE_PHONE) { if (entry.getDestinationKind() == RecipientEntry.ENTRY_KIND_EMAIL) { nonAggregatedEntries.get(nonAggregatedEntries.size() - 1) .setDestinationKind(RecipientEntry.ENTRY_KIND_EMAIL); } else if (entry.getDestinationKind() == RecipientEntry.ENTRY_KIND_PHONE) { nonAggregatedEntries.get(nonAggregatedEntries.size() - 1) .setDestinationKind(RecipientEntry.ENTRY_KIND_PHONE); } } /// @} } else if (entryMap.containsKey(entry.contactId)) { // We already have a section for the person. final List<RecipientEntry> entryList = entryMap.get(entry.contactId); entryList.add(RecipientEntry.constructSecondLevelEntry(entry.displayName, entry.displayNameSource, entry.destination, entry.destinationType, entry.destinationLabel, entry.contactId, entry.dataId, entry.thumbnailUriString, true, entry.isGalContact)); /// M: Set destination kind of the recipient entry if the contact entry is queried from email. @{ if (mQueryType == QUERY_TYPE_PHONE) { if (entry.getDestinationKind() == RecipientEntry.ENTRY_KIND_EMAIL) { entryList.get(entryList.size() - 1).setDestinationKind(RecipientEntry.ENTRY_KIND_EMAIL); } else if (entry.getDestinationKind() == RecipientEntry.ENTRY_KIND_PHONE) { entryList.get(entryList.size() - 1).setDestinationKind(RecipientEntry.ENTRY_KIND_PHONE); } } /// @} } else { final List<RecipientEntry> entryList = new ArrayList<RecipientEntry>(); entryList.add(RecipientEntry.constructTopLevelEntry(entry.displayName, entry.displayNameSource, entry.destination, entry.destinationType, entry.destinationLabel, entry.contactId, entry.dataId, entry.thumbnailUriString, true, entry.isGalContact)); /// M: Set destination kind of the recipient entry if the contact entry is queried from email. @{ if (mQueryType == QUERY_TYPE_PHONE) { if (entry.getDestinationKind() == RecipientEntry.ENTRY_KIND_EMAIL) { entryList.get(entryList.size() - 1).setDestinationKind(RecipientEntry.ENTRY_KIND_EMAIL); } else if (entry.getDestinationKind() == RecipientEntry.ENTRY_KIND_PHONE) { entryList.get(entryList.size() - 1).setDestinationKind(RecipientEntry.ENTRY_KIND_PHONE); } } /// @} entryMap.put(entry.contactId, entryList); } }
From source file:gate.util.reporting.DocTimeReporter.java
/** * Sorts LinkedHashMap by its values(natural descending order). keeps the * duplicates as it is./*www . j a v a 2s . c om*/ * * @param passedMap * An Object of type LinkedHashMap to be sorted by its values. * @return An Object containing the sorted LinkedHashMap. */ private LinkedHashMap<?, ?> sortHashMapByValues(LinkedHashMap<String, String> passedMap) { List<String> mapKeys = new ArrayList<String>(passedMap.keySet()); List<String> mapValues = new ArrayList<String>(passedMap.values()); Collections.sort(mapValues, new ValueComparator()); Collections.sort(mapKeys); // Reversing the collection to sort the values in descending order Collections.reverse(mapValues); LinkedHashMap<String, String> sortedMap = new LinkedHashMap<String, String>(); Iterator<String> valueIt = mapValues.iterator(); while (valueIt.hasNext()) { String val = valueIt.next(); Iterator<String> keyIt = mapKeys.iterator(); while (keyIt.hasNext()) { String 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(key, val); break; } } } return sortedMap; }
From source file:citation_prediction.CitationCore.java
/** * This function implements the algorithm designed by Josiah Neuberger and William Etcho used to solve for a WSB solution. * The general math for the Newton-Raphson method was provided by Dr. Allen Parks and can be found in the function 'getPartialsData'. * <br><br>//ww w .j av a 2 s . c om * This algorithm was created under the direction of Supervising University of Mary Washington faculty, Dr. Melody Denhere along with * consultation from Dr. Jeff Solka and Computer Scientists Kristin Ash with the Dahlgren Naval Surface Warfare Center. * <br><br> * If your interested in more information about the research behind this algorithm please visit:<br> * http://josiahneuberger.github.io/citation_prediction/ * <br><br> * * @param data The citation data in days. * @param mu The initial mu guess to use in the Newton-Raphson method. * @param sigma The initial sigma guess to use in the Newton-Raphson method. * @param m The constant value, which is determined by the average number of references in each new paper for a journal. * @param t The last time value in the paper's citation history. * @param n The total number of citations for this paper. * @param l A list structure to store values for each iteration (should be null to start). * @param iteration The iteration (should be zero to start) * @param max_iteration The maximum number of iterations to try before stopping. * @param tolerance The tolerance level, which determines that a solution has been converged on. * @return A list containing the WSB solution of (lambda, mu, sigma, iterations). */ private LinkedHashMap<String, Double> newtonRaphson(double[][] data, double mu, double sigma, double m, double t, double n, LinkedHashMap<String, Double> l, int iteration, int max_iteration, double tolerance) { double lambda; LinkedHashMap<String, Double> r = new LinkedHashMap<String, Double>(); if (iteration > max_iteration) { System.out.println("Does not converge."); r.put("lambda", null); r.put("mu", null); r.put("sigma", null); r.put("iterations", null); return r; } else if (tolerance < 0.00000001) { System.out.println("Stopped due to tolerance."); r.put("lambda", getLambda(data, mu, sigma, m, t, n)); r.put("mu", mu); r.put("sigma", sigma); r.put("iterations", (double) iteration); return r; } else { l = getPartialsData(getIterationData(data, mu, sigma, m)); double[] array_xn = { mu, sigma }; double[] array_yn = { l.get("fn"), l.get("gn") }; RealMatrix xn = MatrixUtils.createColumnRealMatrix(array_xn); RealMatrix yn = MatrixUtils.createColumnRealMatrix(array_yn); //http://commons.apache.org/proper/commons-math/userguide/linear.html double[][] array_jacobian = { { l.get("df_dmu"), l.get("df_dsigma") }, { l.get("dg_dmu"), l.get("dg_dsigma") } }; RealMatrix jacobian = MatrixUtils.createRealMatrix(array_jacobian); LUDecomposition lud = new LUDecomposition(jacobian); DecompositionSolver decS = lud.getSolver(); l.put("iteration", (double) (iteration + 1)); //DEBUG: printList(l); if (!decS.isNonSingular()) { l.put("iteration", (double) (max_iteration + 1)); System.err.println("ERROR: Jacobian matrix was singular."); } else { RealMatrix solution = xn.subtract(decS.getInverse().multiply(yn)); RealMatrix xndiff = solution.subtract(xn); tolerance = Math.sqrt(Math.pow(xndiff.getEntry(0, 0), 2) + Math.pow(xndiff.getEntry(1, 0), 2)); //update values l.put("mu", solution.getEntry(0, 0)); l.put("sigma", solution.getEntry(1, 0)); //DEBUG: System.out.printf("\"%-20s=%25f\"\n", "NEW MU", l.get("mu")); //DEBUG: System.out.printf("\"%-20s=%25f\"\n", "NEW SIGMA", l.get("sigma")); } //DEBUG: System.out.println("****************************************"); return newtonRaphson(data, l.get("mu"), l.get("sigma"), m, l, (l.get("iteration").intValue()), tolerance); } }
From source file:com.datatorrent.stram.engine.StreamingContainer.java
private void setupNode(OperatorDeployInfo ndi) { failedNodes.remove(ndi.id);/*from w w w .j ava2 s . c o m*/ final Node<?> node = nodes.get(ndi.id); node.setup(node.context); /* setup context for all the input ports */ LinkedHashMap<String, PortContextPair<InputPort<?>>> inputPorts = node .getPortMappingDescriptor().inputPorts; LinkedHashMap<String, PortContextPair<InputPort<?>>> newInputPorts = new LinkedHashMap<String, PortContextPair<InputPort<?>>>( inputPorts.size()); for (OperatorDeployInfo.InputDeployInfo idi : ndi.inputs) { InputPort<?> port = inputPorts.get(idi.portName).component; PortContext context = new PortContext(idi.contextAttributes, node.context); newInputPorts.put(idi.portName, new PortContextPair<InputPort<?>>(port, context)); port.setup(context); } inputPorts.putAll(newInputPorts); /* setup context for all the output ports */ LinkedHashMap<String, PortContextPair<OutputPort<?>>> outputPorts = node .getPortMappingDescriptor().outputPorts; LinkedHashMap<String, PortContextPair<OutputPort<?>>> newOutputPorts = new LinkedHashMap<String, PortContextPair<OutputPort<?>>>( outputPorts.size()); for (OperatorDeployInfo.OutputDeployInfo odi : ndi.outputs) { OutputPort<?> port = outputPorts.get(odi.portName).component; PortContext context = new PortContext(odi.contextAttributes, node.context); newOutputPorts.put(odi.portName, new PortContextPair<OutputPort<?>>(port, context)); port.setup(context); } outputPorts.putAll(newOutputPorts); logger.debug("activating {} in container {}", node, containerId); /* This introduces need for synchronization on processNodeRequest which was solved by adding deleted field in StramToNodeRequest */ processNodeRequests(false); node.activate(); eventBus.publish(new NodeActivationEvent(node)); }
From source file:edu.jhuapl.openessence.datasource.jdbc.JdbcOeDataSource.java
protected void addGroupByClauses(final StringBuilder query, final LinkedHashMap<String, String> columns) throws OeDataSourceException { query.append(" GROUP BY "); final List<String> groupBySql = new ArrayList<String>(); for (final String column : columns.keySet()) { String sqlSnippet = ""; //added to check for an alias on sort DimensionBean bean = this.getBean(column); if (bean != null && bean.getSqlColAlias() != null && !"".equals(bean.getSqlColAlias())) { sqlSnippet = bean.getSqlColAlias(); } else {//from ww w .ja v a2 s. c o m sqlSnippet = columns.get(column); } if (sqlSnippet != null) { groupBySql.add(sqlSnippet); } else { throw new OeDataSourceException("You cannot use this dimension '" + column + "' in groupby until you properly configure its sql column name. Please adjust your groovy definition file."); } } //query.append(StringUtils.collectionToDelimitedString(columns.values(), ",")); query.append(StringUtils.collectionToDelimitedString(groupBySql, ", ")); }
From source file:amulet.resourceprofiler.ResourceProfiler.java
/** * Helper function for getting the AVG. EXECUTION TIME for a particular resource. * @param resource//w w w. j a v a 2s.c o m * @param qmapp * @param deviceInfo * @param steadyStateInfo * @param api_energy_lookup * @return */ private double getTimeHelper(Resource resource, QMApp qmapp, DeviceInfo deviceInfo, SteadyStateInfo steadyStateInfo, LinkedHashMap<String, EnergyParam> api_energy_lookup, double[][] fill_rect_lookup, double[][] clear_rect_lookup) { // Compute the avg. time to execute a line of code (LoC). double AVG_LOC_TIME = deviceInfo.avgNumInstructionsPerLoC * deviceInfo.avgBasicInstructionTime; // Define an arbitrary time to give to un-recognized function calls/operations. double UNKNOWN_TIME = UNKNOWN_QUANTITY_SCALAR * AVG_LOC_TIME; // A time variable for keeping track of the time value to be returned to the caller. double time = resource.time; switch (resource.type) { case AMULET_API_FUNCTION_CALL: if (api_energy_lookup.containsKey(resource.name)) { // If the Amulet API call is recognized, then we just assign the real measurement value. EnergyParam energyparam = api_energy_lookup.get(resource.name); time = energyparam.avgTime; if (resource.name.contains("ClearRect")) { // MAGIC NUMBERS!!! Gawd this whole thing is a bit hacky for the special lookup functions int w = Math.min(resource.getIntExtra("width"), 127); int h = Math.min(resource.getIntExtra("height"), 114); time = clear_rect_lookup[w][h]; } if (resource.name.contains("FillRect")) { int w = Math.min(resource.getIntExtra("width"), 127); int h = Math.min(resource.getIntExtra("height"), 114); time = fill_rect_lookup[w][h]; } } else { // If the Amulet API call is *not* recognized, then we just assign a fixed time. m_resourceProfilerWarnings.add(" + (!) LOOK-UP WARNING:: Time for Amulet API function '" + resource.name + "' not found in api_energy_lookup table; assigning UNKNOWN_TIME=" + UNKNOWN_TIME + "."); time = UNKNOWN_TIME; } // If this call is nested within a loop, the time of this function call (really, the // resource record) needs to be multiplied by the number of times this call is actually made. if (resource.isContainedInLoop()) { // System.out.println("**** RESOURCE " + resource.name + " time was = " + time); time *= resource.getNumLoopIterations(); // System.out.println("**** RESOURCE " + resource.name + " is now = " + time + " (orignal-time x " + resource.getNumLoopIterations() + ")"); } break; case NON_AMULET_API_FUNCTION_CALL: if (qmapp.operationTimeMap.containsKey(resource.name)) { // This is a function defined within the QM application (i.e., an "operation" by QM's definition). time = qmapp.operationTimeMap.get(resource.name); } else { // If the Non-Amulet API call is *not* recognized, then we just assign a fixed cost. m_resourceProfilerWarnings.add(" + (!) LOOK-UP WARNING:: Time for Non-Amulet API function '" + resource.name + "' not found; assigning UNKNOWN_TIME=" + UNKNOWN_TIME + "."); time = UNKNOWN_TIME; } // If this call is nested within a loop, the time of this function call (really, the // resource record) needs to be multiplied by the number of times this call is actually made. if (resource.isContainedInLoop()) { // System.out.println("**** RESOURCE " + resource.name + " time was = " + time); time *= resource.getNumLoopIterations(); // System.out.println("**** RESOURCE " + resource.name + " is now = " + time + " (orignal-time x " + resource.getNumLoopIterations() + ")"); } break; case COMPUTATION: if (resource.name.equals(ComputationType.BASIC_BLOCKS.text())) { // Get the number of lines of code. double nLinesOfCode = resource.getIntExtra(Resource.EXTRA_NUM_LINES_OF_CODE); time = nLinesOfCode * AVG_LOC_TIME; } else if (resource.name.equals(ComputationType.FOR_LOOP.text())) { try { // Get number of iterations in this loop. double nIterations = resource.getNumLoopIterations(); // Get the number of lines of code. double nLinesOfCode = resource.getIntExtra(Resource.EXTRA_LOOP_NUM_STATEMENTS); time = (nLinesOfCode * AVG_LOC_TIME) * nIterations; } catch (Exception e) { System.err.println("**FAILED RESOURCE PARSING: skipping this resource"); System.err.println(" RESOURCE: " + resource + ""); } } break; case SENSOR_SUBSCRIPTION: if (resource.name.equalsIgnoreCase("ACCELEROMETER")) { time = 0.0; // no time here exactly -- compute.js scales the subscription to be in terms of "per week" } else if (resource.name.equalsIgnoreCase("HEARTRATE")) { time = 0.0; // no time here exactly -- compute.js scales the subscription to be in terms of "per week" } break; case MEMORY: case GLOBAL_MEMORY: case UNKNOWN: default: } return time; }
From source file:edu.jhuapl.openessence.controller.ReportController.java
private Collection<Double> getCountsForChart(LinkedHashMap<String, ChartData> recordMap) { Collection<Double> counts = new ArrayList<Double>(); for (String id : recordMap.keySet()) { counts.add(recordMap.get(id).getCount()); }//ww w .j a v a 2 s .com return counts; }