List of usage examples for java.util HashMap values
public Collection<V> values()
From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java
/** * Helper function.//from ww w . j a v a 2s . co m * @param word1 * @param maxSubstringLength * @param probMap * @param probs * @param memoizationTable * @param pruneToSize * @return */ public static HashMap<String, Double> Predict2(String word1, int maxSubstringLength, Map<String, HashSet<String>> probMap, HashMap<Production, Double> probs, HashMap<String, HashMap<String, Double>> memoizationTable, int pruneToSize) { HashMap<String, Double> result; if (word1.length() == 0) { result = new HashMap<>(1); result.put("", 1.0); return result; } if (memoizationTable.containsKey(word1)) { return memoizationTable.get(word1); } result = new HashMap<>(); int maxSubstringLength1 = Math.min(word1.length(), maxSubstringLength); for (int i = 1; i <= maxSubstringLength1; i++) { String substring1 = word1.substring(0, i); if (probMap.containsKey(substring1)) { // recursion right here. HashMap<String, Double> appends = Predict2(word1.substring(i), maxSubstringLength, probMap, probs, memoizationTable, pruneToSize); //int segmentations = Segmentations( word1.Length - i ); for (String tgt : probMap.get(substring1)) { Production alignment = new Production(substring1, tgt); double alignmentProb = probs.get(alignment); for (String key : appends.keySet()) { Double value = appends.get(key); String word = alignment.getSecond() + key; //double combinedProb = (pair.Value/segmentations) * alignmentProb; double combinedProb = (value) * alignmentProb; // I hope this is an accurate translation... Dictionaries.IncrementOrSet(result, word, combinedProb, combinedProb); } } } } if (result.size() > pruneToSize) { Double[] valuesArray = result.values().toArray(new Double[result.values().size()]); String[] data = result.keySet().toArray(new String[result.size()]); //Array.Sort<Double, String> (valuesArray, data); TreeMap<Double, String> sorted = new TreeMap<>(); for (int i = 0; i < valuesArray.length; i++) { sorted.put(valuesArray[i], data[i]); } // FIXME: is this sorted in the correct order??? //double sum = 0; //for (int i = data.Length - pruneToSize; i < data.Length; i++) // sum += valuesArray[i]; result = new HashMap<>(pruneToSize); // for (int i = data.length - pruneToSize; i < data.length; i++) // result.put(data[i], valuesArray[i]); int i = 0; for (Double d : sorted.descendingKeySet()) { result.put(sorted.get(d), d); if (i++ > pruneToSize) { break; } } } memoizationTable.put(word1, result); return result; }
From source file:eu.planets_project.tb.impl.services.mockups.workflow.MigrateWorkflow.java
/** * Creates a list of MeasurementImpl for the requested format and Characterise service. * Properties are requested from the service's .listProperties(puid) method. * @param format/*from w w w . ja v a 2s . co m*/ * @param dp * @return */ private List<MeasurementImpl> getMeasurementsForFormat(String format, Characterise dp) { List<MeasurementImpl> lm = new Vector<MeasurementImpl>(); HashMap<URI, MeasurementImpl> meas = new HashMap<URI, MeasurementImpl>(); URI formatURI; if (format == null) { log.error("Format was set to NULL."); return lm; } try { formatURI = new URI(format); } catch (URISyntaxException e) { e.printStackTrace(); return lm; } if (dp == null) { return lm; } // Find all the PRONOM IDs for this format URI: for (URI puid : this.getPronomURIAliases(formatURI)) { List<Property> measurableProperties = dp.listProperties(puid); if (measurableProperties != null) { for (Property p : measurableProperties) { MeasurementImpl m = this.createMeasurementFromProperty(p); if (!meas.containsKey(m.getIdentifier())) { meas.put(m.getIdentifierUri(), m); } } } } lm = new Vector<MeasurementImpl>(meas.values()); //Collections.sort( lm ); return lm; }
From source file:mobi.jenkinsci.ci.JenkinsCIPlugin.java
@Override public List<ItemNode> getReleaseNotes(final Account account, final PluginConfig pluginConf, final String version, final String url, final HttpServletRequest request) throws Exception { final ArrayList<ItemNode> changes = new ArrayList<ItemNode>(); final JenkinsClient client = JenkinsClient.getInstance(account, pluginConf); final String jenkinsUrl = pluginConf.getUrl(); final String jobPathPart = getJobPathPart(url, jenkinsUrl); final Job job = client.getJob(jobPathPart); final String jobBuildPart = getJobBuildPart(client, url, jenkinsUrl); final int jobBuildNumber = job.getBuild(jobBuildPart).number; final HashMap<URL, ItemNode> ticketsMap = new HashMap<URL, ItemNode>(); final List<ItemNode> changesList = new ArrayList<ItemNode>(); final ArtifactFingerprint remoteBuildFingerprint = client.getArtifactFromMD5(getApkMd5(request)); if (job.builds.size() <= 0 || remoteBuildFingerprint.original.number >= job.builds.get(0).number) { throw new Exception("Nothing to upgrade: you already have the latest build"); }// w w w .j ava 2 s . co m for (final Build build : job.builds) { if (build.number > remoteBuildFingerprint.original.number && build.number <= jobBuildNumber) { for (final ChangeSetItem jobChange : client.getJobChanges(jobPathPart, build.number).items) { if (jobChange.issue != null) { final URL ticketUrl = jobChange.issue.linkUrl; if (ticketsMap.get(ticketUrl) == null) { ticketsMap.put(ticketUrl, account.getPluginNodeForUrl(pluginConf, ticketUrl)); } } else { changesList.add(jobChange.toAbstractNode(jenkinsUrl)); } } } } if (!ticketsMap.isEmpty()) { changes.add(new HeaderNode("New features / Fixed bugs")); changes.addAll(ticketsMap.values()); } if (!changesList.isEmpty()) { changes.add(new HeaderNode("Code changes")); changes.addAll(changesList); } return changes; }
From source file:com.opengamma.analytics.math.rootfinding.YieldCurveFittingFromMarketDataTest.java
private YieldCurveFittingTestDataBundle getSingleCurveSetup() { final List<String> curveNames = new ArrayList<String>(); curveNames.add("single curve"); final String interpolator = Interpolator1DFactory.DOUBLE_QUADRATIC; final CombinedInterpolatorExtrapolator extrapolator = CombinedInterpolatorExtrapolatorFactory .getInterpolator(interpolator, LINEAR_EXTRAPOLATOR, FLAT_EXTRAPOLATOR); final InstrumentDerivativeVisitor<YieldCurveBundle, Double> calculator = ParRateCalculator.getInstance(); final InstrumentDerivativeVisitor<YieldCurveBundle, Map<String, List<DoublesPair>>> sensitivityCalculator = ParRateCurveSensitivityCalculator .getInstance();/* w w w. j av a 2 s.c om*/ // final InterestRateDerivativeVisitor<YieldCurveBundle, Double> calculator = PresentValueCalculator.getInstance(); // final InterestRateDerivativeVisitor<YieldCurveBundle, Map<String, List<DoublesPair>>> sensitivityCalculator = PresentValueSensitivityCalculator.getInstance(); final HashMap<String, double[]> maturities = new LinkedHashMap<String, double[]>(); maturities.put("libor", new double[] { 0.019164956, 0.038329911, 0.084873374, 0.169746749, 0.251882272, 0.336755647, 0.41889117, 0.503764545, 0.588637919, 0.665297741, 0.750171116, 0.832306639, 0.917180014, 0.999315537 }); // maturities.put("fra", new double[] { 1.437371663, 1.686516085, 1.938398357 }); maturities.put("swap", new double[] { /* 2.001368925, */3.000684463, 4, 4.999315537, 7.000684463, 10.00136893, 15.00068446, 20, 24.99931554, 30.00136893, 35.00068446, 50.00136893 }); maturities.put("swap", new double[] { 1, 2, 3, 4, 5, 6, 7, 10, 15, 20, 25, 30 }); final HashMap<String, double[]> marketRates = new LinkedHashMap<String, double[]>(); marketRates.put("libor", new double[] { 0.0506375, 0.05075, 0.0513, 0.0518625, 0.0523625, 0.0526125, 0.052925, 0.053175, 0.053375, 0.0535188, 0.0536375, 0.0537563, 0.0538438, 0.0539438 }); // marketRates.put("fra", new double[] { 0.0566, 0.05705, 0.0572 }); // marketRates.put("swap", new double[] {/* 0.05412, */0.054135, 0.054295, 0.05457, 0.055075, 0.055715, 0.05652, 0.056865, 0.05695, 0.056925, 0.056885, 0.056725}); marketRates.put("swap", new double[] { 0.04285, 0.03953, 0.03986, 0.040965, 0.042035, 0.04314, 0.044, 0.046045, 0.048085, 0.048925, 0.049155, 0.049195 }); int nNodes = 0; for (final double[] temp : maturities.values()) { nNodes += temp.length; } final double[] temp = new double[nNodes]; int index = 0; for (final double[] times : maturities.values()) { for (final double t : times) { temp[index++] = t; } } Arrays.sort(temp); final List<double[]> curveKnots = new ArrayList<double[]>(); curveKnots.add(temp); // now get market prices final double[] marketValues = new double[nNodes]; final List<InstrumentDerivative> instruments = new ArrayList<InstrumentDerivative>(); InstrumentDerivative ird; index = 0; for (final String name : maturities.keySet()) { final double[] times = maturities.get(name); final double[] rates = marketRates.get(name); Validate.isTrue(times.length == rates.length); for (int i = 0; i < times.length; i++) { ird = makeSingleCurrencyIRD(name, times[i], SimpleFrequency.QUARTERLY, curveNames.get(0), curveNames.get(0), rates[i], 1); instruments.add(ird); marketValues[index] = rates[i]; index++; } } final double[] rates = new double[nNodes]; for (int i = 0; i < nNodes; i++) { rates[i] = 0.05; } final DoubleMatrix1D startPosition = new DoubleMatrix1D(rates); final YieldCurveFittingTestDataBundle data = getYieldCurveFittingTestDataBundle(instruments, null, curveNames, curveKnots, extrapolator, calculator, sensitivityCalculator, marketValues, startPosition, null, false, FX_MATRIX); return data; }
From source file:edu.utexas.cs.tactex.PortfolioManagerService.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.getSubscribedPopulation()); }/*from w w w. j ava 2 s.co m*/ } return result; }
From source file:edu.utexas.cs.tactex.PortfolioManagerService.java
/** * Returns total usage for a given timeslot (represented as a simple index). *//*w w w.j ava2 s . c o m*/ @Override public synchronized double collectUsage(int index) { double result = 0.0; for (HashMap<CustomerInfo, CustomerRecord> customerMap : customerSubscriptions.values()) { for (CustomerRecord record : customerMap.values()) { result += record.getUsage(index, false); } } return -result; // convert to needed energy account balance }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
public void addIsotopeCurves(TreeMap<Peak, Collection<Annotation>> annotations) { if (theDocument.size() == 0) return;// w w w.java 2 s.c om // remove old curves removeIsotopeCurves(); // add curves if (annotations != null) { // set renderer if (show_all_isotopes) { thePlot.setRenderer(1, new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES)); thePlot.getRenderer(1).setShape(new Ellipse2D.Double(0, 0, 7, 7)); } else thePlot.setRenderer(1, new StandardXYItemRenderer(StandardXYItemRenderer.LINES)); MSUtils.IsotopeList isotope_list = new MSUtils.IsotopeList(show_all_isotopes); for (Map.Entry<Peak, Collection<Annotation>> pa : annotations.entrySet()) { Peak p = pa.getKey(); // get compositions HashSet<Molecule> compositions = new HashSet<Molecule>(); for (Annotation a : pa.getValue()) { try { compositions.add(a.getFragmentEntry().fragment.computeIon()); } catch (Exception e) { e.printStackTrace(); } } // collect curves for this peak HashMap<String, double[][]> all_curves = new HashMap<String, double[][]>(); for (Molecule m : compositions) { try { double[][] data = MSUtils.getIsotopesCurve(1, m, show_all_isotopes); // overlay the distribution with the existing list of isotopes isotope_list.adjust(data, p.getMZ(), p.getIntensity()); all_curves.put(m.toString(), data); } catch (Exception e) { LogUtils.report(e); } } // add average curve for this peak if (all_curves.size() > 1) { double[][] data = MSUtils.average(all_curves.values(), show_all_isotopes); // add the average to the chart String name = "average-" + p.getMZ(); theIsotopesDataset.addSeries(name, data); thePlot.getRenderer(1).setSeriesPaint(theIsotopesDataset.indexOf(name), Color.magenta); thePlot.getRenderer(1).setSeriesStroke(theIsotopesDataset.indexOf(name), new BasicStroke(2)); // add the average to the isotope list isotope_list.add(data, false); } else if (all_curves.size() == 1) { // add the only curve to the isotope list isotope_list.add(all_curves.values().iterator().next(), false); } // add the other curves for (Map.Entry<String, double[][]> e : all_curves.entrySet()) { String name = e.getKey() + "-" + p.getMZ(); theIsotopesDataset.addSeries(name, e.getValue()); thePlot.getRenderer(1).setSeriesPaint(theIsotopesDataset.indexOf(name), Color.blue); } } } updateIntensityAxis(); }
From source file:de.dfki.km.perspecting.obie.model.Document.java
public List<TokenSequence<SemanticEntity>> getRetrievedPropertyValues() { List<TokenSequence<SemanticEntity>> entities = new ArrayList<TokenSequence<SemanticEntity>>(); HashMap<String, TokenSequence<SemanticEntity>> map = new HashMap<String, TokenSequence<SemanticEntity>>(); for (int tokenIndex : this.data.getIntegerKeys(TokenSequence.PROPERTY)) { List<SemanticEntity> values = this.data.get(TokenSequence.PROPERTY, tokenIndex); if (values != null) { for (SemanticEntity value : values) { String key = Integer.toString(value.getPropertyIndex()) + Integer.toString(value.getLiteralValueIndex()); if (value.getPosition().equals("B")) { TokenSequence<SemanticEntity> entity = map.get(key); if (entity != null) { entities.add(map.remove(key)); }/*from w w w .j a v a2 s. c o m*/ entity = new TokenSequence<SemanticEntity>(value); entity.addToken(new Token(tokenIndex, this)); map.put(key, entity); } else { map.get(key).addToken(new Token(tokenIndex, this)); } } } else { entities.addAll(map.values()); map.clear(); } } entities.addAll(map.values()); return entities; }
From source file:com.sonicle.webtop.mail.MailAccount.java
private void _loadFoldersCache(FolderCache fc) throws MessagingException { Folder f = fc.getFolder();// w w w. j a va 2 s .co m Folder children[] = f.list(); for (Folder child : children) { String cname = child.getFullName(); if (ms.isFolderHidden(this, cname)) continue; if (hasDifferentDefaultFolder && cname.equals(fcRoot.getFolderName())) continue; FolderCache fcc = addFoldersCache(fc, child); } //If shared folders, check for same descriptions and in case add login if (isSharedFolder(f.getFullName()) && fc.hasChildren()) { HashMap<String, ArrayList<FolderCache>> hm = new HashMap<String, ArrayList<FolderCache>>(); //map descriptions to list of folders for (FolderCache child : fc.getChildren()) { String desc = child.getDescription(); ArrayList<FolderCache> al = hm.get(desc); if (al == null) { al = new ArrayList<FolderCache>(); al.add(child); hm.put(desc, al); } else { al.add(child); } } //for folders with list>1 change description to all elements for (ArrayList<FolderCache> al : hm.values()) { if (al.size() > 1) { for (FolderCache fcc : al) { SharedPrincipal sip = fcc.getSharedInboxPrincipal(); String user = sip.getUserId(); fcc.setWebTopUser(user); fcc.setDescription(fcc.getDescription() + " [" + user + "]"); } } } } }
From source file:com.sfs.whichdoctor.isb.publisher.PersonIsbXmlWriter.java
/** * Output the related objects of an ISB entity to ISB xml. * * @param existingObjects the existing objects * @param updatedObjects the updated objects * * @throws IOException Signals that an I/O exception has occurred. *//*from w w w .j a va 2s. c o m*/ private void processObjects(final ArrayList<Object> existingObjects, final ArrayList<Object> updatedObjects) throws IOException { boolean objectsProcessed = false; HashMap<Integer, Object> existingMap = new HashMap<Integer, Object>(); HashMap<Integer, Object> updatedMap = new HashMap<Integer, Object>(); for (Object object : existingObjects) { WhichDoctorBean wdObject = (WhichDoctorBean) object; existingMap.put(wdObject.getGUID(), object); } for (Object object : updatedObjects) { WhichDoctorBean wdObject = (WhichDoctorBean) object; updatedMap.put(wdObject.getGUID(), object); } if (StringUtils.equals(getAction(), "create")) { // Iterate through existing objects on assumption they are all new for (Object object : existingMap.values()) { writeObject(object, null, "new"); } objectsProcessed = true; } if (StringUtils.equals(getAction(), "modify")) { // Iterate through all objects and see if they are new, // modified or deleted for (Object object : existingMap.values()) { WhichDoctorBean wdObject = (WhichDoctorBean) object; if (updatedMap.containsKey(wdObject.getGUID())) { // Object has been modified Object updatedObject = updatedMap.get(wdObject.getGUID()); // This has been disabled in favor of a simplier // new/delete command set. Hopefully this changes in // the future. // writeObject(object, updatedObject, "updated"); if (compareObject(object, updatedObject)) { // Only send through modified entries writeObject(object, object, "deleted"); writeObject(updatedObject, null, "new"); } } else { // Object has been deleted writeObject(object, object, "deleted"); } } for (Object object : updatedMap.values()) { WhichDoctorBean wdObject = (WhichDoctorBean) object; if (!existingMap.containsKey(wdObject.getGUID())) { // Object has been created writeObject(object, null, "new"); } } objectsProcessed = true; } if (!objectsProcessed) { // No action taken - snapshot requested for (Object object : existingMap.values()) { writeObject(object, null, "existing"); } } }