List of usage examples for java.util LinkedHashMap get
public V get(Object key)
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PortCounterPlotWorker.java
/** * Creates a sample dataset.//from w ww . ja va 2s.co m * * @param name the dataset name. * @param base the starting value. * @param start the starting period. * @param count the number of values to generate. * * @return The dataset. */ private XYDataset createDataset(OMS_Collection history) { TimeSeries TSeries = new TimeSeries("counts"); // iterate through the collection, and build up a time series for (int j = 0; j < history.getSize(); j++) { OpenSmMonitorService osm = history.getOMS(j); // find the desired port counter, in this instance LinkedHashMap<String, OSM_Port> pL = osm.getFabric().getOSM_Ports(); OSM_Port p = pL.get(OSM_Port.getOSM_PortKey(Port)); long lValue = p.pfmPort.getCounter(PortCounter); TimeStamp ts = p.pfmPort.getCounterTimeStamp(); RegularTimePeriod ms = new FixedMillisecond(ts.getTimeInMillis()); TSeries.add(ms, (double) lValue); } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(TSeries); return dataset; }
From source file:com.opengamma.analytics.financial.provider.sensitivity.multicurve.MultipleCurrencyParameterSensitivity.java
/** * Create a copy of the sensitivity and add a given named sensitivity to it. If the name / currency pair is in the map, the two sensitivity matrices are added. * Otherwise, a new entry is put into the map * @param nameCcy The name and the currency, not null * @param sensitivity The sensitivity to add, not null * @return The total sensitivity./* w w w . j av a 2 s. c om*/ */ public MultipleCurrencyParameterSensitivity plus(final Pair<String, Currency> nameCcy, final DoubleMatrix1D sensitivity) { ArgumentChecker.notNull(nameCcy, "Name/currency"); ArgumentChecker.notNull(sensitivity, "Matrix"); final MatrixAlgebra algebra = MatrixAlgebraFactory.COMMONS_ALGEBRA; final LinkedHashMap<Pair<String, Currency>, DoubleMatrix1D> result = new LinkedHashMap<>(); result.putAll(_sensitivity); if (result.containsKey(nameCcy)) { result.put(nameCcy, (DoubleMatrix1D) algebra.add(result.get(nameCcy), sensitivity)); } else { result.put(nameCcy, sensitivity); } return new MultipleCurrencyParameterSensitivity(result); }
From source file:net.big_oh.resourcestats.dao.RequestorDAOIntegrationTest.java
/** * Test method for/* w ww. j a v a 2 s.c o m*/ * {@link net.big_oh.resourcestats.dao.RequestorDAO#getMostFrequentRequestors(int, java.util.Date)} * . */ @Test public void testGetMostFrequentRequestorsIntDate() { try { sf.getCurrentSession().beginTransaction(); LinkedHashMap<Requestor, Number> requestors = dao.getMostFrequentRequestors(5, DateUtils.addDays(new Date(), -3)); assertNotNull(requestors); for (Object key : requestors.keySet()) { assertTrue(key instanceof Requestor); Object value = requestors.get(key); assertTrue(value instanceof Number); } // TODO DSW Provide improved assertions sf.getCurrentSession().getTransaction().commit(); } catch (Throwable t) { HibernateUtil.rollback(t, sf, log); throw new RuntimeException(t); } }
From source file:at.porscheinformatik.common.spring.web.extended.template.cache.AbstractTemplateCache.java
private Template getTemplateFromMap(List<String> localizedTemplates, LinkedHashMap<String, Template> templatesToUse) { for (String name : localizedTemplates) { Template template = templatesToUse.get(name); if (template != null) { return template; }//w ww. j a va2 s.c om } return null; }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PortCounterPlotWorker.java
private XYDataset createUtilizationDataset(OSM_FabricDeltaCollection deltaHistory, PortCounterName pcn, String seriesName) {/*from w w w. j a va 2 s. c om*/ TimeSeries series = new TimeSeries(seriesName); // iterate through the collection, and build up a time series for (int j = 0; j < deltaHistory.getSize(); j++) { OSM_FabricDelta delta = deltaHistory.getOSM_FabricDelta(j); // find the desired port counter, in this instance LinkedHashMap<String, PFM_PortChange> pcL = delta.getPortChanges(); PFM_PortChange pC = pcL.get(OSM_Port.getOSM_PortKey(Port)); PFM_PortRate pR = new PFM_PortRate(pC); TimeStamp ts = pC.getCounterTimeStamp(); // convert rate to utilization double lValue = SMT_AnalysisManager.getInstance().getDeltaAnalysis().getPortUtilization(pR, pcn); RegularTimePeriod ms = new FixedMillisecond(ts.getTimeInMillis()); series.add(ms, lValue); } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); return dataset; }
From source file:com.smartbear.collab.client.Client.java
public JsonrpcResponse sendRequest(List<JsonrpcCommand> methods) { JsonrpcResponse result = new JsonrpcResponse(); List<LinkedHashMap<String, LinkedHashMap<String, String>>> results = new ArrayList<LinkedHashMap<String, LinkedHashMap<String, String>>>(); ObjectMapper mapper = new ObjectMapper(); try {//from w ww . j a v a2s . co m logger.info(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(methods)); } catch (JsonProcessingException jpe) { } results = target.request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(methods, MediaType.APPLICATION_JSON_TYPE), List.class); try { logger.info(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(results)); } catch (JsonProcessingException jpe) { } List<JsonrpcCommandResponse> commandResponses = new ArrayList<JsonrpcCommandResponse>(); for (LinkedHashMap commandResultMap : results) { JsonrpcCommandResponse commandResponse = new JsonrpcCommandResponse(); if (commandResultMap.get("result") != null) { JsonrpcResult commandResult = new JsonrpcResult(); LinkedHashMap<String, String> commandResultValue = (LinkedHashMap<String, String>) commandResultMap .get("result"); if (commandResultValue.size() > 0) { commandResult.setCommand(commandResultValue.keySet().iterator().next()); commandResult.setValue(commandResultValue.get(commandResult.getCommand())); commandResponse.setResult(commandResult); } } if (commandResultMap.get("errors") != null) { List<LinkedHashMap<String, String>> errors = (List<LinkedHashMap<String, String>>) commandResultMap .get("errors"); List<JsonrpcError> jsonrpcErrors = new ArrayList<JsonrpcError>(); for (LinkedHashMap<String, String> error : errors) { JsonrpcError jsonrpcError = new JsonrpcError(); jsonrpcError.setCode(error.get("code")); jsonrpcError.setMessage(error.get("message")); jsonrpcErrors.add(jsonrpcError); } commandResponse.setErrors(jsonrpcErrors); } commandResponses.add(commandResponse); } result.setResults(commandResponses); return result; }
From source file:org.envirocar.wps.DataTransformProcess.java
public SimpleFeatureCollection createFeaturesFromJSON(URL url) throws IOException { InputStream in = url.openStream(); ObjectMapper objMapper = new ObjectMapper(); Map<?, ?> map = objMapper.readValue(in, Map.class); ArrayList<?> features = null; for (Object o : map.keySet()) { Object entry = map.get(o); if (o.equals("features")) { features = (ArrayList<?>) entry; }/* ww w . j ava2s . com*/ } GeometryFactory geomFactory = new GeometryFactory(); List<SimpleFeature> simpleFeatureList = new ArrayList<SimpleFeature>(); String uuid = UUID.randomUUID().toString().substring(0, 5); String namespace = "http://www.52north.org/" + uuid; SimpleFeatureType sft = null; SimpleFeatureBuilder sfb = null; typeBuilder = new SimpleFeatureTypeBuilder(); try { typeBuilder.setCRS(CRS.decode("EPSG:4326")); } catch (NoSuchAuthorityCodeException e) { LOGGER.error("Could not decode EPSG:4326", e); } catch (FactoryException e) { LOGGER.error("Could not decode EPSG:4326", e); } typeBuilder.setNamespaceURI(namespace); Name nameType = new NameImpl(namespace, "Feature-" + uuid); typeBuilder.setName(nameType); typeBuilder.add("geometry", Point.class); typeBuilder.add("id", String.class); typeBuilder.add("time", String.class); Set<String> distinctPhenomenonNames = gatherPropertiesForFeatureTypeBuilder(features); for (Object object : features) { if (object instanceof LinkedHashMap<?, ?>) { LinkedHashMap<?, ?> featureMap = (LinkedHashMap<?, ?>) object; Object geometryObject = featureMap.get("geometry"); Point point = null; if (geometryObject instanceof LinkedHashMap<?, ?>) { LinkedHashMap<?, ?> geometryMap = (LinkedHashMap<?, ?>) geometryObject; Object coordinatesObject = geometryMap.get("coordinates"); if (coordinatesObject instanceof ArrayList<?>) { ArrayList<?> coordinatesList = (ArrayList<?>) coordinatesObject; Object xObj = coordinatesList.get(0); Object yObj = coordinatesList.get(1); point = geomFactory.createPoint(new Coordinate(Double.parseDouble(xObj.toString()), Double.parseDouble(yObj.toString()))); } } Object propertiesObject = featureMap.get("properties"); if (propertiesObject instanceof LinkedHashMap<?, ?>) { LinkedHashMap<?, ?> propertiesMap = (LinkedHashMap<?, ?>) propertiesObject; /* * get id and time */ String id = propertiesMap.get("id").toString(); String time = propertiesMap.get("time").toString(); Object phenomenonsObject = propertiesMap.get("phenomenons"); if (phenomenonsObject instanceof LinkedHashMap<?, ?>) { LinkedHashMap<?, ?> phenomenonsMap = (LinkedHashMap<?, ?>) phenomenonsObject; /* * properties are id, time and phenomenons */ if (sft == null) { sft = buildFeatureType(distinctPhenomenonNames); sfb = new SimpleFeatureBuilder(sft); } sfb.set("id", id); sfb.set("time", time); sfb.set("geometry", point); for (Object phenomenonKey : phenomenonsMap.keySet()) { Object phenomenonValue = phenomenonsMap.get(phenomenonKey); if (phenomenonValue instanceof LinkedHashMap<?, ?>) { LinkedHashMap<?, ?> phenomenonValueMap = (LinkedHashMap<?, ?>) phenomenonValue; String value = phenomenonValueMap.get("value").toString(); String unit = phenomenonValueMap.get("unit").toString(); /* * create property name */ String propertyName = phenomenonKey.toString() + " (" + unit + ")"; if (sfb != null) { sfb.set(propertyName, value); } } } if (sfb != null) { simpleFeatureList.add(sfb.buildFeature(id)); } } } } } return new ListFeatureCollection(sft, simpleFeatureList); }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PortCounterPlotWorker.java
private XYDataset createDeltaDataset(OSM_FabricDeltaCollection deltaHistory, PortCounterName pcn, String seriesName) {/*from w ww . j a va2s. co m*/ TimeSeries series = new TimeSeries(seriesName); // iterate through the collection, and build up a time series for (int j = 0; j < deltaHistory.getSize(); j++) { OSM_FabricDelta delta = deltaHistory.getOSM_FabricDelta(j); // find the desired port counter, in this instance LinkedHashMap<String, PFM_PortChange> pcL = delta.getPortChanges(); PFM_PortChange pC = pcL.get(OSM_Port.getOSM_PortKey(Port)); long lValue = pC.getDelta_port_counter(pcn); // correct for missing time periods int deltaSeconds = delta.getDeltaSeconds(); long sweepPeriod = delta.getFabric2().getPerfMgrSweepSecs(); if (sweepPeriod < deltaSeconds) { // graph is reported as counts per period, so if the period is too long, interpolate lValue *= sweepPeriod; lValue /= deltaSeconds; } TimeStamp ts = pC.getCounterTimeStamp(); RegularTimePeriod ms = new FixedMillisecond(ts.getTimeInMillis()); series.add(ms, (double) lValue); } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); return dataset; }
From source file:com.amalto.workbench.actions.XSDSetAnnotationDescriptionsAction.java
public IStatus doAction() { try {//from www .jav a 2 s .c o m IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection(); XSDComponent xSDCom = null; if (selection.getFirstElement() instanceof Element) { TreePath tPath = ((TreeSelection) selection).getPaths()[0]; for (int i = 0; i < tPath.getSegmentCount(); i++) { if (tPath.getSegment(i) instanceof XSDAnnotation) xSDCom = (XSDAnnotation) (tPath.getSegment(i)); } } else xSDCom = (XSDComponent) selection.getFirstElement(); XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom); if (struc.getAnnotation() == null) { throw new RuntimeException( Messages.bind(Messages.XSDSetAnnotationXX_ExceptionInfo2, xSDCom.getClass().getName())); } AnnotationLanguageLabelsDialog dlg = new AnnotationLanguageLabelsDialog(struc.getDescriptions(), new AnnotationLabelDialogSelectionListener(page), page.getEditorSite().getShell(), Messages.XSDSetAnnotationXX_SetDescOfThisItem); dlg.setBlockOnOpen(true); dlg.open(); if (dlg.getReturnCode() == Window.OK) { // remove existing annotations with labels struc.removeAllDescriptions(); // add the new ones LinkedHashMap<String, String> descriptions = dlg.getDescriptionsMap(); Set<String> isoCodes = descriptions.keySet(); for (Iterator iter = isoCodes.iterator(); iter.hasNext();) { String isoCode = (String) iter.next(); struc.setDescription(isoCode, descriptions.get(isoCode)); } } else { return Status.CANCEL_STATUS; } if (struc.hasChanged()) { page.markDirty(); page.refresh(); page.getTreeViewer().expandToLevel(xSDCom, 2); } } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetAnnotationXX_ErrorMsg, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:com.miserablemind.api.consumer.tradeking.api.impl.response_entities.TKResponse.java
/** * For arrays of objects TK returns an array when multiple, but if only one object found, it is not wrapped in array. * This method deserializes and wraps that object to array * * @param className Class Name of the object to de-serialize to * @param response response from TK/* ww w . j av a2 s . co m*/ * @param nestedKey Nesting array key * @return Array of objects. The user of this class will cast this to accommodate specif needs * @throws Exception */ Object[] extractArray(Class<? extends Object[]> className, LinkedHashMap response, String nestedKey) throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new TradeKingModule()); mapper.registerModule(new JodaModule()); mapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true); mapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true); Object nestedEntry = response.get(nestedKey); if (nestedEntry.getClass() != ArrayList.class) { nestedEntry = new Object[] { nestedEntry }; } String jsonArray = mapper.writeValueAsString(nestedEntry); return mapper.readValue(jsonArray, className); }