List of usage examples for java.util SortedMap containsKey
boolean containsKey(Object key);
From source file:lisong_mechlab.view.graphs.DpsGraph.java
private TableXYDataset getSeries() { final Collection<Modifier> modifiers = loadout.getModifiers(); SortedMap<Weapon, Integer> multiplicity = new TreeMap<Weapon, Integer>(new Comparator<Weapon>() { @Override//from w w w .j a v a2 s . c o m public int compare(Weapon aO1, Weapon aO2) { int comp = Double.compare(aO2.getRangeMax(modifiers), aO1.getRangeMax(modifiers)); if (comp == 0) return aO1.compareTo(aO2); return comp; } }); for (Weapon weapon : loadout.items(Weapon.class)) { if (!weapon.isOffensive()) continue; if (!multiplicity.containsKey(weapon)) { multiplicity.put(weapon, 0); } int v = multiplicity.get(weapon); multiplicity.put(weapon, v + 1); } List<Weapon> orderedWeapons = new ArrayList<>(); Double[] ranges = WeaponRanges.getRanges(multiplicity.keySet(), modifiers); DefaultTableXYDataset dataset = new DefaultTableXYDataset(); for (Map.Entry<Weapon, Integer> e : multiplicity.entrySet()) { Weapon weapon = e.getKey(); int mult = e.getValue(); XYSeries series = new XYSeries(weapon.getName(), true, false); for (double range : ranges) { final double dps = weapon.getStat("d/s", modifiers); final double rangeEff = weapon.getRangeEffectivity(range, modifiers); series.add(range, dps * rangeEff * mult); } dataset.addSeries(series); orderedWeapons.add(e.getKey()); } Collections.reverse(orderedWeapons); colours.updateColoursToMatch(orderedWeapons); return dataset; }
From source file:tajo.master.GlobalPlanner.java
@VisibleForTesting public static Map<String, List<URI>> hashFetches(SubQueryId sid, List<URI> uriList) { SortedMap<String, List<URI>> hashed = new TreeMap<String, List<URI>>(); String uriPath, key;/*from w w w . ja v a 2 s.co m*/ for (URI uri : uriList) { // TODO uriPath = uri.toString(); key = uriPath.substring(uriPath.lastIndexOf("=") + 1); if (hashed.containsKey(key)) { hashed.get(key).add(uri); } else { List<URI> list = new ArrayList<URI>(); list.add(uri); hashed.put(key, list); } } return combineURIByHost(hashed); }
From source file:testful.coverage.behavior.AbstractorNumber.java
@Override public Abstraction get(Map<String, Object> ctx) { // evaluate the expression and retrieve the result (obj) Object obj = evaluateExpression(ctx); if (obj == null) return new AbstractionObjectReference(expression, true); if (!(obj instanceof Number)) { logger.warning("Expected a number in AbstractorNumber!"); return new Abstraction.AbstractionError(expression); }/*ww w . j a v a2 s . co m*/ // if there are no intervals, then use the "default" abstraction if (intervalsString == null) return get(expression, obj); double elem = ((Number) obj).doubleValue(); // ensure that this.intervals contains parsed expressions getIntervals(); // retrieve the value of intervals. it may contain null values Double[] values = evaluateIntervals(ctx); // if the value is NaN, calculate the return value if (Double.isNaN(elem)) { String label = null; for (int i = 0; i < values.length; i++) if (values[i] != null && Double.isNaN(values[i])) { if (label == null) label = intervalsString[i]; else label += "," + intervalsString[i]; } if (label == null) return new AbstractionNumber(expression, expression + " is " + AbstractionNumber.NaN); return new AbstractionNumber(expression, expression + " = " + label); } // build the sortedValues Map SortedMap<Double, String> sortedValues = new TreeMap<Double, String>(); for (int i = 0; i < values.length; i++) if (values[i] != null && !Double.isNaN(values[i])) { String label = sortedValues.get(values[i]); if (label == null) label = intervalsString[i]; else label += "," + intervalsString[i]; sortedValues.put(values[i], label); } if (!sortedValues.containsKey(Double.POSITIVE_INFINITY)) sortedValues.put(Double.POSITIVE_INFINITY, AbstractionNumber.P_INF); if (!sortedValues.containsKey(Double.NEGATIVE_INFINITY)) sortedValues.put(Double.NEGATIVE_INFINITY, AbstractionNumber.N_INF); // calculate the interval String prev = null; for (Entry<Double, String> entry : sortedValues.entrySet()) { if (prev != null && elem < entry.getKey()) return new AbstractionNumber(expression, prev + " < " + expression + " < " + entry.getValue()); if (elem == entry.getKey()) return new AbstractionNumber(expression, expression + " = " + entry.getValue()); prev = entry.getValue(); } if (TestFul.DEBUG) TestFul.debug("This point was not supposed to be reachable."); return new AbstractionNumber(expression, expression + " = " + AbstractionNumber.P_INF); }
From source file:org.eclipse.skalli.core.persistence.XStreamPersistenceTest.java
@Test public void testGetExtensionsByClassName() throws Exception { XStreamPersistence xp = new TestXStreamPersistence(); Document doc = XMLUtils.documentFromString(XML_WITH_EXTENSIONS); Map<String, Class<?>> aliases = getAliases(); SortedMap<String, Element> extensions = xp.getExtensionsByClassName(doc, aliases); assertEquals(2, extensions.size());//w ww . j a v a 2s .com for (String alias : aliases.keySet()) { String className = aliases.get(alias).getName(); assertTrue(extensions.containsKey(className)); assertEquals(alias, extensions.get(className).getNodeName()); } }
From source file:org.opencms.workplace.CmsWidgetDialogParameter.java
/** * "Commits" (writes) the value of this widget back to the underlying base object.<p> * /* ww w . j ava 2 s. c o m*/ * @param dialog the widget dialog where the parameter is used on * * @throws CmsException in case the String value of the widget is invalid for the base Object */ @SuppressWarnings("unchecked") public void commitValue(CmsWidgetDialog dialog) throws CmsException { if (m_baseCollection == null) { PropertyUtilsBean bean = new PropertyUtilsBean(); ConvertUtilsBean converter = new ConvertUtilsBean(); Object value = null; try { Class<?> type = bean.getPropertyType(m_baseObject, m_baseObjectProperty); value = converter.convert(m_value, type); bean.setNestedProperty(m_baseObject, m_baseObjectProperty, value); setError(null); } catch (InvocationTargetException e) { setError(e.getTargetException()); throw new CmsWidgetException(Messages.get().container(Messages.ERR_PROPERTY_WRITE_3, value, dialog.keyDefault(A_CmsWidget.getLabelKey(this), getKey()), m_baseObject.getClass().getName()), e.getTargetException(), this); } catch (Exception e) { setError(e); throw new CmsWidgetException(Messages.get().container(Messages.ERR_PROPERTY_WRITE_3, value, dialog.keyDefault(A_CmsWidget.getLabelKey(this), getKey()), m_baseObject.getClass().getName()), e, this); } } else if (m_baseCollection instanceof SortedMap) { if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_value)) { int pos = m_value.indexOf('='); if ((pos > 0) && (pos < (m_value.length() - 1))) { String key = m_value.substring(0, pos); String value = m_value.substring(pos + 1); @SuppressWarnings("rawtypes") SortedMap map = (SortedMap) m_baseCollection; if (map.containsKey(key)) { Object val = map.get(key); CmsWidgetException error = new CmsWidgetException( Messages.get().container(Messages.ERR_MAP_DUPLICATE_KEY_3, dialog.keyDefault(A_CmsWidget.getLabelKey(this), getKey()), key, val), this); setError(error); throw error; } map.put(key, value); } else { CmsWidgetException error = new CmsWidgetException( Messages.get().container(Messages.ERR_MAP_PARAMETER_FORM_1, dialog.keyDefault(A_CmsWidget.getLabelKey(this), getKey())), this); setError(error); throw error; } } } else if (m_baseCollection instanceof List) { if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_value)) { @SuppressWarnings("rawtypes") List list = (List) m_baseCollection; list.add(m_value); } } }
From source file:org.eclipse.jubula.client.ui.rcp.handlers.project.OpenProjectHandler.java
/** * Checks all available projects/*from w ww.j a v a 2 s . c o m*/ * * @return list of all projects */ private List<IProjectPO> checkAllAvailableProjects() { List<IProjectPO> projList = null; try { projList = ProjectPM.findAllProjects(); if (projList.isEmpty()) { Display.getDefault().asyncExec(new Runnable() { public void run() { ErrorHandlingUtil.createMessageDialog(MessageIDs.I_NO_PROJECT_IN_DB); } }); Plugin.stopLongRunning(); } else { SortedMap<String, List<String>> projNameToVersionMap = new TreeMap<String, List<String>>(); for (IProjectPO proj : projList) { String projName = proj.getName(); String projVersion = proj.getVersionString(); if (!StringUtils.isBlank(projName) && !projNameToVersionMap.containsKey(projName)) { projNameToVersionMap.put(projName, new ArrayList<String>()); } projNameToVersionMap.get(projName).add(projVersion); } } } catch (final JBException e) { Display.getDefault().asyncExec(new Runnable() { public void run() { ErrorHandlingUtil.createMessageDialog(e, null, null); } }); } return projList; }
From source file:com.facebook.buck.util.unarchive.Unzip.java
private void extractDirectory(ExistingFileMode existingFileMode, SortedMap<Path, ZipArchiveEntry> pathMap, DirectoryCreator creator, Path target) throws IOException { ProjectFilesystem filesystem = creator.getFilesystem(); if (filesystem.isDirectory(target, LinkOption.NOFOLLOW_LINKS)) { // We have a pre-existing directory: delete its contents if they aren't in the zip. if (existingFileMode == ExistingFileMode.OVERWRITE_AND_CLEAN_DIRECTORIES) { for (Path path : filesystem.getDirectoryContents(target)) { if (!pathMap.containsKey(path)) { filesystem.deleteRecursivelyIfExists(path); }//from w ww. ja va 2 s . c om } } } else if (filesystem.exists(target, LinkOption.NOFOLLOW_LINKS)) { filesystem.deleteFileAtPath(target); creator.mkdirs(target); } else { creator.forcefullyCreateDirs(target); } }
From source file:com.abuabdul.knodex.service.KxDocumentServiceImpl.java
public SortedMap<String, List<KnodexDoc>> listAllSentences() { log.debug("Entered KxDocumentServiceImpl.listAllSentences method"); String indexKey = ""; List<KnodexDoc> indexKnodexList = null; SortedMap<String, List<KnodexDoc>> fullListOfSentences = null; List<KnodexDoc> listAllKnodex = knodexDAO.findAll(); if (listAllKnodex != null && !listAllKnodex.isEmpty()) { log.debug("The size of the overall key with sentences " + listAllKnodex.size()); fullListOfSentences = new TreeMap<String, List<KnodexDoc>>(); for (KnodexDoc knodexDoc : listAllKnodex) { if (knodexDoc != null && !StringUtils.isEmpty(knodexDoc.getKey())) { indexKey = knodexDoc.getKey(); log.debug("Index key to get the list of sentences for each indexBy value " + indexKey); if (!fullListOfSentences.isEmpty() && fullListOfSentences.containsKey(indexKey)) { indexKnodexList = fullListOfSentences.get(indexKey); if (indexKnodexList == null) { // Ideally this code will not execute indexKnodexList = new ArrayList<KnodexDoc>(); }//from w ww . j a va2s.c o m indexKnodexList.add(knodexDoc); } else { indexKnodexList = new ArrayList<KnodexDoc>(); indexKnodexList.add(knodexDoc); fullListOfSentences.put(indexKey, indexKnodexList); } } } } return fullListOfSentences; }
From source file:fr.landel.utils.commons.MapUtils2Test.java
/** * Test method for/*w ww.j a v a 2s . c om*/ * {@link MapUtils2#newMap(java.util.function.Supplier, java.lang.Class, java.lang.Class, java.lang.Object[])}. */ @Test public void testNewMapSupplierClass() { SortedMap<String, Long> map = MapUtils2.newMap(TreeMap::new, String.class, Long.class, "key1", 1L, "key2", 2L); assertTrue(map instanceof TreeMap); assertEquals(2, map.size()); Map<String, Long> expectedMap = new HashMap<>(); expectedMap.put("key1", 1L); expectedMap.put("key2", 2L); for (Entry<String, Long> entry : expectedMap.entrySet()) { assertTrue(map.containsKey(entry.getKey())); assertEquals(entry.getValue(), map.get(entry.getKey())); } map = MapUtils2.newMap(TreeMap::new, String.class, Long.class); assertTrue(map instanceof TreeMap); assertTrue(map.isEmpty()); map = MapUtils2.newMap(() -> new TreeMap<>(Comparators.STRING.desc()), String.class, Long.class, "key1", 1L, "key2", 2L, null, 3L, "key4", null, 2d, 5L, "key6", true); assertTrue(map instanceof TreeMap); assertEquals(4, map.size()); "key2".equals(map.firstKey()); map = MapUtils2.newMap(TreeMap::new, String.class, Long.class, new Object[0]); assertTrue(map instanceof TreeMap); assertTrue(map.isEmpty()); assertException(() -> { MapUtils2.newMap(TreeMap::new, null, Long.class, "", ""); }, NullPointerException.class); assertException(() -> { MapUtils2.newMap(TreeMap::new, String.class, null, "", ""); }, NullPointerException.class); assertException(() -> { MapUtils2.newMap(null, String.class, Long.class, "", ""); }, NullPointerException.class); assertException(() -> { MapUtils2.newMap(TreeMap::new, String.class, Long.class, (Object[]) null); }, IllegalArgumentException.class, "objects cannot be null or empty and has to contain an odd number of elements"); assertException(() -> { MapUtils2.newMap(TreeMap::new, String.class, Long.class, "key"); }, IllegalArgumentException.class, "objects cannot be null or empty and has to contain an odd number of elements"); }
From source file:org.apache.maven.archetype.ui.generation.DefaultArchetypeSelectionQueryer.java
private Archetype selectVersion(Map<String, List<Archetype>> catalogs, String groupId, String artifactId) throws PrompterException { SortedMap<ArtifactVersion, Archetype> archetypeVersionsMap = new TreeMap<ArtifactVersion, Archetype>(); for (Map.Entry<String, List<Archetype>> entry : catalogs.entrySet()) { for (Archetype archetype : entry.getValue()) { if (!groupId.equals(archetype.getGroupId()) || !artifactId.equals(archetype.getArtifactId())) { continue; }//from w ww .ja va2 s.c om ArtifactVersion version = new DefaultArtifactVersion(archetype.getVersion()); // don't override the first catalog containing a defined version of the artifact if (!archetypeVersionsMap.containsKey(version)) { archetypeVersionsMap.put(version, archetype); } } } if (archetypeVersionsMap.size() == 1) { return archetypeVersionsMap.values().iterator().next(); } // let the user choose between available versions StringBuilder query = new StringBuilder("Choose " + groupId + ":" + artifactId + " version: \n"); List<String> answers = new ArrayList<String>(); Map<String, Archetype> answerMap = new HashMap<String, Archetype>(); int counter = 1; String mapKey = null; for (Map.Entry<ArtifactVersion, Archetype> entry : archetypeVersionsMap.entrySet()) { ArtifactVersion version = entry.getKey(); Archetype archetype = entry.getValue(); mapKey = String.valueOf(counter); query.append(mapKey + ": " + version + "\n"); answers.add(mapKey); answerMap.put(mapKey, archetype); counter++; } query.append("Choose a number: "); Archetype archetype = null; do { String answer = prompter.prompt(query.toString(), answers, mapKey); archetype = answerMap.get(answer); } while (archetype == null); return archetype; }