List of usage examples for java.util LinkedHashMap keySet
public Set<K> keySet()
From source file:msi.gama.outputs.layers.charts.ChartOutput.java
public void updateOutput(final IScope scope) { if (chartdataset.doResetAll(scope, lastUpdateCycle)) { clearDataSet(scope);/*ww w .j a va 2 s . com*/ for (final String serieid : chartdataset.getDataSeriesIds(scope)) { createNewSerie(scope, serieid); } preResetSeries(scope); for (final String serieid : chartdataset.getDataSeriesIds(scope)) { this.resetSerie(scope, serieid); } resetAxes(scope); } else { final LinkedHashMap<String, Integer> toremove = chartdataset.getSerieRemovalDate(); for (final String serieid : toremove.keySet()) { if (toremove.get(serieid) >= lastUpdateCycle) { removeSerie(scope, serieid); toremove.put(serieid, toremove.get(serieid) - 1); } } final LinkedHashMap<String, Integer> toadd = chartdataset.getSerieCreationDate(); for (final String serieid : toadd.keySet()) { if (toadd.get(serieid) >= lastUpdateCycle) { createNewSerie(scope, serieid); toadd.put(serieid, toadd.get(serieid) - 1); } } preResetSeries(scope); for (final String serieid : chartdataset.getDataSeriesIds(scope)) { this.resetSerie(scope, serieid); } resetAxes(scope); } updateImage(scope); lastUpdateCycle = scope.getClock().getCycle(); // DEBUG.LOG("output last update:" + lastUpdateCycle); }
From source file:fr.cirad.mgdb.exporting.markeroriented.HapMapExportHandler.java
@Override public void exportData(OutputStream outputStream, String sModule, List<SampleId> sampleIDs, ProgressIndicator progress, DBCursor markerCursor, Map<Comparable, Comparable> markerSynonyms, int nMinimumGenotypeQuality, int nMinimumReadDepth, Map<String, InputStream> readyToExportFiles) throws Exception { MongoTemplate mongoTemplate = MongoTemplateManager.get(sModule); File warningFile = File.createTempFile("export_warnings_", ""); FileWriter warningFileWriter = new FileWriter(warningFile); int markerCount = markerCursor.count(); ZipOutputStream zos = new ZipOutputStream(outputStream); if (readyToExportFiles != null) for (String readyToExportFile : readyToExportFiles.keySet()) { zos.putNextEntry(new ZipEntry(readyToExportFile)); InputStream inputStream = readyToExportFiles.get(readyToExportFile); byte[] dataBlock = new byte[1024]; int count = inputStream.read(dataBlock, 0, 1024); while (count != -1) { zos.write(dataBlock, 0, count); count = inputStream.read(dataBlock, 0, 1024); }/* w w w . j a v a 2 s . c o m*/ } List<Individual> individuals = getIndividualsFromSamples(sModule, sampleIDs); ArrayList<String> individualList = new ArrayList<String>(); for (int i = 0; i < sampleIDs.size(); i++) { Individual individual = individuals.get(i); if (!individualList.contains(individual.getId())) { individualList.add(individual.getId()); } } String exportName = sModule + "_" + markerCount + "variants_" + individualList.size() + "individuals"; zos.putNextEntry(new ZipEntry(exportName + ".hapmap")); String header = "rs#" + "\t" + "alleles" + "\t" + "chrom" + "\t" + "pos" + "\t" + "strand" + "\t" + "assembly#" + "\t" + "center" + "\t" + "protLSID" + "\t" + "assayLSID" + "\t" + "panelLSID" + "\t" + "QCcode"; zos.write(header.getBytes()); for (int i = 0; i < individualList.size(); i++) { zos.write(("\t" + individualList.get(i)).getBytes()); } zos.write((LINE_SEPARATOR).getBytes()); int avgObjSize = (Integer) mongoTemplate .getCollection(mongoTemplate.getCollectionName(VariantRunData.class)).getStats().get("avgObjSize"); int nChunkSize = nMaxChunkSizeInMb * 1024 * 1024 / avgObjSize; short nProgress = 0, nPreviousProgress = 0; long nLoadedMarkerCount = 0; while (markerCursor == null || markerCursor.hasNext()) { int nLoadedMarkerCountInLoop = 0; Map<Comparable, String> markerChromosomalPositions = new LinkedHashMap<Comparable, String>(); boolean fStartingNewChunk = true; markerCursor.batchSize(nChunkSize); while (markerCursor.hasNext() && (fStartingNewChunk || nLoadedMarkerCountInLoop % nChunkSize != 0)) { DBObject exportVariant = markerCursor.next(); DBObject refPos = (DBObject) exportVariant.get(VariantData.FIELDNAME_REFERENCE_POSITION); markerChromosomalPositions.put((Comparable) exportVariant.get("_id"), refPos.get(ReferencePosition.FIELDNAME_SEQUENCE) + ":" + refPos.get(ReferencePosition.FIELDNAME_START_SITE)); nLoadedMarkerCountInLoop++; fStartingNewChunk = false; } List<Comparable> currentMarkers = new ArrayList<Comparable>(markerChromosomalPositions.keySet()); LinkedHashMap<VariantData, Collection<VariantRunData>> variantsAndRuns = MgdbDao.getSampleGenotypes( mongoTemplate, sampleIDs, currentMarkers, true, null /*new Sort(VariantData.FIELDNAME_REFERENCE_POSITION + "." + ChromosomalPosition.FIELDNAME_SEQUENCE).and(new Sort(VariantData.FIELDNAME_REFERENCE_POSITION + "." + ChromosomalPosition.FIELDNAME_START_SITE))*/); // query mongo db for matching genotypes for (VariantData variant : variantsAndRuns.keySet()) // read data and write results into temporary files (one per sample) { Comparable variantId = variant.getId(); if (markerSynonyms != null) { Comparable syn = markerSynonyms.get(variantId); if (syn != null) variantId = syn; } boolean fIsSNP = variant.getType().equals(Type.SNP.toString()); byte[] missingGenotype = ("\t" + "NN").getBytes(); String[] chromAndPos = markerChromosomalPositions.get(variant.getId()).split(":"); zos.write(((variantId == null ? variant.getId() : variantId) + "\t" + StringUtils.join(variant.getKnownAlleleList(), "/") + "\t" + chromAndPos[0] + "\t" + Long.parseLong(chromAndPos[1]) + "\t" + "+").getBytes()); for (int j = 0; j < 6; j++) zos.write(("\t" + "NA").getBytes()); Map<String, Integer> gqValueForSampleId = new LinkedHashMap<String, Integer>(); Map<String, Integer> dpValueForSampleId = new LinkedHashMap<String, Integer>(); Map<String, List<String>> individualGenotypes = new LinkedHashMap<String, List<String>>(); Collection<VariantRunData> runs = variantsAndRuns.get(variant); if (runs != null) for (VariantRunData run : runs) for (Integer sampleIndex : run.getSampleGenotypes().keySet()) { SampleGenotype sampleGenotype = run.getSampleGenotypes().get(sampleIndex); String gtCode = run.getSampleGenotypes().get(sampleIndex).getCode(); String individualId = individuals .get(sampleIDs.indexOf(new SampleId(run.getId().getProjectId(), sampleIndex))) .getId(); List<String> storedIndividualGenotypes = individualGenotypes.get(individualId); if (storedIndividualGenotypes == null) { storedIndividualGenotypes = new ArrayList<String>(); individualGenotypes.put(individualId, storedIndividualGenotypes); } storedIndividualGenotypes.add(gtCode); gqValueForSampleId.put(individualId, (Integer) sampleGenotype.getAdditionalInfo().get(VariantData.GT_FIELD_GQ)); dpValueForSampleId.put(individualId, (Integer) sampleGenotype.getAdditionalInfo().get(VariantData.GT_FIELD_DP)); } int writtenGenotypeCount = 0; for (String individualId : individualList /* we use this list because it has the proper ordering */) { int individualIndex = individualList.indexOf(individualId); while (writtenGenotypeCount < individualIndex - 1) { zos.write(missingGenotype); writtenGenotypeCount++; } List<String> genotypes = individualGenotypes.get(individualId); HashMap<Object, Integer> genotypeCounts = new HashMap<Object, Integer>(); // will help us to keep track of missing genotypes int highestGenotypeCount = 0; String mostFrequentGenotype = null; if (genotypes != null) for (String genotype : genotypes) { if (genotype.length() == 0) continue; /* skip missing genotypes */ Integer gqValue = gqValueForSampleId.get(individualId); if (gqValue != null && gqValue < nMinimumGenotypeQuality) continue; /* skip this sample because its GQ is under the threshold */ Integer dpValue = dpValueForSampleId.get(individualId); if (dpValue != null && dpValue < nMinimumReadDepth) continue; /* skip this sample because its DP is under the threshold */ int gtCount = 1 + MgdbDao.getCountForKey(genotypeCounts, genotype); if (gtCount > highestGenotypeCount) { highestGenotypeCount = gtCount; mostFrequentGenotype = genotype; } genotypeCounts.put(genotype, gtCount); } byte[] exportedGT = mostFrequentGenotype == null ? missingGenotype : ("\t" + StringUtils.join(variant.getAllelesFromGenotypeCode(mostFrequentGenotype), fIsSNP ? "" : "/")).getBytes(); zos.write(exportedGT); writtenGenotypeCount++; if (genotypeCounts.size() > 1) warningFileWriter.write("- Dissimilar genotypes found for variant " + (variantId == null ? variant.getId() : variantId) + ", individual " + individualId + ". Exporting most frequent: " + new String(exportedGT) + "\n"); } while (writtenGenotypeCount < individualList.size()) { zos.write(missingGenotype); writtenGenotypeCount++; } zos.write((LINE_SEPARATOR).getBytes()); } if (progress.hasAborted()) return; nLoadedMarkerCount += nLoadedMarkerCountInLoop; nProgress = (short) (nLoadedMarkerCount * 100 / markerCount); if (nProgress > nPreviousProgress) { // if (nProgress%5 == 0) // LOG.info("========================= exportData: " + nProgress + "% =========================" + (System.currentTimeMillis() - before)/1000 + "s"); progress.setCurrentStepProgress(nProgress); nPreviousProgress = nProgress; } } warningFileWriter.close(); if (warningFile.length() > 0) { zos.putNextEntry(new ZipEntry(exportName + "-REMARKS.txt")); int nWarningCount = 0; BufferedReader in = new BufferedReader(new FileReader(warningFile)); String sLine; while ((sLine = in.readLine()) != null) { zos.write((sLine + "\n").getBytes()); in.readLine(); nWarningCount++; } LOG.info("Number of Warnings for export (" + exportName + "): " + nWarningCount); in.close(); } warningFile.delete(); zos.close(); progress.setCurrentStepProgress((short) 100); }
From source file:com.google.gwt.emultest.java.util.LinkedHashMapTest.java
@SuppressWarnings("unchecked") public void testClone() { LinkedHashMap<String, String> srcMap = new LinkedHashMap<String, String>(); checkEmptyLinkedHashMapAssumptions(srcMap); // Check empty clone behavior LinkedHashMap<String, String> dstMap = (LinkedHashMap<String, String>) srcMap.clone(); assertNotNull(dstMap);/*ww w . j a v a2s .com*/ assertEquals(dstMap.size(), srcMap.size()); assertEquals(dstMap.keySet().toArray(), srcMap.keySet().toArray()); assertEquals(dstMap.entrySet().toArray(), srcMap.entrySet().toArray()); // Check non-empty clone behavior srcMap.put(KEY_1, VALUE_1); srcMap.put(KEY_2, VALUE_2); srcMap.put(KEY_3, VALUE_3); srcMap.put(KEY_4, VALUE_4); dstMap = (LinkedHashMap<String, String>) srcMap.clone(); assertNotNull(dstMap); assertEquals(dstMap.size(), srcMap.size()); assertEquals(dstMap.keySet().toArray(), srcMap.keySet().toArray()); assertEquals(dstMap.entrySet().toArray(), srcMap.entrySet().toArray()); }
From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java
@Override public void mouseClicked(MouseEvent event, final StateRenderer2D source) { if (event.getButton() == MouseEvent.BUTTON3) { final LinkedHashMap<String, Vector<AssetPosition>> positions = positionsByType(); JPopupMenu popup = new JPopupMenu(); for (String type : positions.keySet()) { JMenu menu = new JMenu(type + "s"); for (final AssetPosition p : positions.get(type)) { if (p.getTimestamp() < oldestTimestampSelection || p.getTimestamp() > newestTimestampSelection) continue; Color c = cmap.getColor(1 - (p.getAge() / (7200000.0))); String htmlColor = String.format("#%02X%02X%02X", c.getRed(), c.getGreen(), c.getBlue()); menu.add("<html><b>" + p.getAssetName() + "</b> <font color=" + htmlColor + ">" + getAge(p) + "</font>").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { source.focusLocation(p.getLoc()); }/*from w ww . java 2s . c o m*/ }); } popup.add(menu); } popup.addSeparator(); popup.add("Settings").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PluginUtils.editPluginProperties(SituationAwareness.this, true); } }); popup.add("Fetch asset properties").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // for (AssetTrack track : assets.values()) { // track.setColor(new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255))); // } fetchAssetProperties(); } }); popup.add("Select location sources").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS)); for (ILocationProvider l : localizers) { JCheckBox check = new JCheckBox(l.getName()); check.setSelected(true); p.add(check); check.setSelected(updateMethodNames.contains(l.getName())); } int op = JOptionPane.showConfirmDialog(getConsole(), p, "Location update sources", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (op == JOptionPane.CANCEL_OPTION) return; Vector<String> methods = new Vector<String>(); for (int i = 0; i < p.getComponentCount(); i++) { if (p.getComponent(i) instanceof JCheckBox) { JCheckBox sel = (JCheckBox) p.getComponent(i); if (sel.isSelected()) methods.add(sel.getText()); } } updateMethods = StringUtils.join(methods, ", "); propertiesChanged(); } }); popup.add("Select hidden positions types").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS)); for (String type : positions.keySet()) { JCheckBox check = new JCheckBox(type); check.setSelected(true); p.add(check); check.setSelected(hiddenPosTypes.contains(type)); } int op = JOptionPane.showConfirmDialog(getConsole(), p, "Position types to be hidden", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (op == JOptionPane.CANCEL_OPTION) return; Vector<String> types = new Vector<String>(); for (int i = 0; i < p.getComponentCount(); i++) { if (p.getComponent(i) instanceof JCheckBox) { JCheckBox sel = (JCheckBox) p.getComponent(i); if (sel.isSelected()) types.add(sel.getText()); } } hiddenTypes = StringUtils.join(types, ", "); propertiesChanged(); } }); popup.addSeparator(); popup.add("Decision Support").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (dialogDecisionSupport == null) { dialogDecisionSupport = new JDialog(getConsole()); dialogDecisionSupport.setModal(false); dialogDecisionSupport.setAlwaysOnTop(true); dialogDecisionSupport.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); } ArrayList<AssetPosition> tags = new ArrayList<AssetPosition>(); LinkedHashMap<String, Vector<AssetPosition>> positions = positionsByType(); Vector<AssetPosition> spots = positions.get("SPOT Tag"); Vector<AssetPosition> argos = positions.get("Argos Tag"); if (spots != null) tags.addAll(spots); if (argos != null) tags.addAll(argos); if (!assets.containsKey(getConsole().getMainSystem())) { GuiUtils.errorMessage(getConsole(), "Decision Support", "UUV asset position is unknown"); return; } supportTable.setAssets(assets.get(getConsole().getMainSystem()).getLatest(), tags); JXTable table = new JXTable(supportTable); dialogDecisionSupport.setContentPane(new JScrollPane(table)); dialogDecisionSupport.invalidate(); dialogDecisionSupport.validate(); dialogDecisionSupport.setSize(600, 300); dialogDecisionSupport.setTitle("Decision Support Table"); dialogDecisionSupport.setVisible(true); dialogDecisionSupport.toFront(); GuiUtils.centerOnScreen(dialogDecisionSupport); } }); popup.show(source, event.getX(), event.getY()); } super.mouseClicked(event, source); }
From source file:ubic.gemma.core.visualization.ExperimentalDesignVisualizationServiceImpl.java
/** * Test method for now, shows how this can be used. * * @param e ee/* w w w . ja va2 s . co m*/ */ @SuppressWarnings("unused") // Test method for now, shows how this can be used. protected void plotExperimentalDesign(ExpressionExperiment e) { LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> layout = this .getExperimentalDesignLayout(e); List<String> efStrings = new ArrayList<>(); List<String> baStrings = new ArrayList<>(); List<double[]> rows = new ArrayList<>(); boolean first = true; int i = 0; for (BioAssayValueObject ba : layout.keySet()) { baStrings.add(ba.getName()); int j = 0; for (ExperimentalFactor ef : layout.get(ba).keySet()) { if (first) { double[] nextRow = new double[layout.size()]; rows.add(nextRow); efStrings.add(ef.getName() + " ( id=" + ef.getId() + ")"); // make sure they are unique. } double d = layout.get(ba).get(ef); rows.get(j)[i] = d; j++; } i++; first = false; } double[][] mat = rows.toArray(new double[][] {}); DoubleMatrix<String, String> data = DoubleMatrixFactory.dense(mat); data.setRowNames(efStrings); data.setColumnNames(baStrings); ColorMatrix<String, String> cm = new ColorMatrix<>(data, ColorMap.GREENRED_COLORMAP, Color.GRAY); try { this.writeImage(cm, File.createTempFile(e.getShortName() + "_", ".png")); } catch (IOException e1) { throw new RuntimeException(e1); } }
From source file:com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition.java
public Map<String, String> getChoicesByDropdownId() throws Exception { LinkedHashMap<String, LinkedHashSet<String>> choicesByDropdownId = calculateChoicesByDropdownId(); Map<String, String> collapsedMap = new LinkedHashMap<String, String>(); for (String dropdownId : choicesByDropdownId.keySet()) { String choices = new String(); for (String choice : choicesByDropdownId.get(dropdownId)) { if (choices.length() > 0) { choices += ","; }/*from w w w .j a v a 2s. c o m*/ choices += choice; } collapsedMap.put(dropdownId, choices); } /* collapsedMap is of a form like this: collapsedMap.put(name + " dropdown MultiLevelMultiSelect 0", "Select a genome...,HG18,ZZ23"); collapsedMap.put(name + " dropdown MultiLevelMultiSelect 0 HG18", "Select a source...,Diffuse large B-cell lymphoma,Multiple Myeloma"); collapsedMap.put(name + " dropdown MultiLevelMultiSelect 0 ZZ23", "Select a source...,Neuroblastoma"); collapsedMap.put(name + " dropdown MultiLevelMultiSelect 0 HG18 Diffuse large B-cell lymphoma","Select a cell type...,LY1"); collapsedMap.put(name + " dropdown MultiLevelMultiSelect 0 HG18 Multiple Myeloma","Select a cell type...,MM1S"); collapsedMap.put(name + " dropdown MultiLevelMultiSelect 0 ZZ23 Neuroblastoma","Select a cell type...,BE2C,SKNAS"); collapsedMap.put(name + " dropdown MultiLevelMultiSelect 0 HG18 Diffuse large B-cell lymphoma LY1","Select a name...,LY1_BCL6_DMSO,LY1_BCL6_JQ1"); collapsedMap.put(name + " dropdown MultiLevelMultiSelect 0 HG18 Multiple Myeloma MM1S", "Select a name...,MM1S_BRD4_150nM_JQ1,MM1S_BRD4_500nM_JQ1"); collapsedMap.put(name + " dropdown MultiLevelMultiSelect 0 ZZ23 Neuroblastoma BE2C", "Select a name...,BE2C_BRD4"); collapsedMap.put(name + " dropdown MultiLevelMultiSelect 0 ZZ23 Neuroblastoma SKNAS", "Select a name...,SKNAS_H3K4ME3"); */ return collapsedMap; }
From source file:fr.mby.utils.spring.beans.factory.BasicProxywiredManager.java
/** * Update the wiring configuration./* w w w.ja v a 2 s . c om*/ * * @param dependencies * @param dependencyToModify */ protected void updateWiringConfiguration(final LinkedHashMap<String, Object> dependencies, final IManageableProxywired dependencyToModify) { if (this.configuration != null) { final IProxywiredIdentifier identifier = dependencyToModify.getIdentifier(); // Internal method => Identifier cannot be null here ! Assert.notNull(identifier, "Cannot found valid identifier for this dependency !"); final String beanNames = StringUtils.collectionToDelimitedString(dependencies.keySet(), IProxywiredManager.WIRING_PREFS_SEPARATOR); final Configuration elementConfig = identifier.getConfigurationSubset(this.configuration); elementConfig.addProperty(IProxywiredManager.WIRED_BEANS_CONFIG_KEY, beanNames); } }
From source file:com.sapito.db.dao.AbstractDao.java
public List<T> findBySpecificField(String field, Object fieldContent, String predicates, LinkedHashMap<String, String> ordering, LinkedList<String> grouping) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(); Root<T> root = cq.from(entityClass); Predicate predicate = null;/*from w w w.ja v a 2 s . co m*/ if (predicates.equals("equal")) { predicate = cb.equal(root.get(field), fieldContent); } else if (predicates.equals("likelower")) { predicate = cb.like(cb.lower(root.<String>get(field)), fieldContent.toString()); } else if (predicates.equals("like")) { predicate = cb.like(root.<String>get(field), "%" + fieldContent.toString() + "%"); } cq.select(root); cq.where(predicate); if (ordering != null) { Set<String> set = ordering.keySet(); List<Order> orders = new ArrayList<>(); for (String orderingField : set) { Order order; if (ordering.get(orderingField).equals("ASC")) { order = cb.asc(root.get(orderingField)); } else { order = cb.desc(root.get(orderingField)); } orders.add(order); } cq.orderBy(orders); } if (grouping != null) { Iterator iterator = grouping.iterator(); List<Expression> groups = new LinkedList<>(); while (iterator.hasNext()) { groups.add(root.get(iterator.next().toString())); } cq.groupBy(groups); } Query query = entityManager.createQuery(cq); query.setMaxResults(MAX_RECORDS_RETURNED); return query.getResultList(); }
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; }//from w w w .ja v a 2s. c o m } 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:org.peerfact.impl.service.aggregation.skyeye.visualization.SkyNetVisualization.java
public void updateDisplayedMetrics(long time, LinkedHashMap<String, MetricsAggregate> simulatorMetrics, LinkedHashMap<String, MetricsAggregate> rootMetrics/* * , double * nodeCounter */) { if (activated && displayedMetrics.size() > 0) { Iterator<String> nameIter = simulatorMetrics.keySet().iterator(); String name = null;//from ww w .j a v a2 s. c om while (nameIter.hasNext()) { name = nameIter.next(); if (displayedMetrics.containsKey(name)) { DeviationSet[] values = null; if (rootMetrics.size() > 0) { DeviationSet[] temp = { new DeviationSet(simulatorMetrics.get(name).getAverage()), new DeviationSet(rootMetrics.get(name).getAverage(), rootMetrics.get(name).getStandardDeviation()), new DeviationSet(rootMetrics.get(name).getMinimum()), new DeviationSet(rootMetrics.get(name).getMaximum()) }; values = temp; } else { DeviationSet[] temp = { new DeviationSet(simulatorMetrics.get(name).getAverage()), new DeviationSet(0), new DeviationSet(0), new DeviationSet(0), }; values = temp; } String[] metricNames = { "Real " + name, "Measured " + name, "Min_Measured" + name, "Max_Measured" + name }; MetricsPlot temp = displayedMetrics.remove(name); temp.updatePlot(name, new DataSet(VisualizationType.Metric, time / 1000, values, metricNames)); displayedMetrics.put(name, temp); updatePlotInWindow(time, name); } } validate(); repaint(); } }