List of usage examples for java.util SortedMap get
V get(Object key);
From source file:org.mule.devkit.doclet.Doclava.java
public static Data makePackageHDF() { Data data = makeHDF();//from w w w . j a v a2s . co m ClassInfo[] classes = Converter.rootClasses(); SortedMap<String, PackageInfo> sorted = new TreeMap<String, PackageInfo>(); for (ClassInfo cl : classes) { PackageInfo pkg = cl.containingPackage(); String name; if (pkg == null) { name = ""; } else { name = pkg.name(); } sorted.put(name, pkg); } int i = 0; for (String s : sorted.keySet()) { PackageInfo pkg = sorted.get(s); if (pkg.isHidden()) { continue; } Boolean allHidden = true; int pass = 0; ClassInfo[] classesToCheck = null; while (pass < 5) { switch (pass) { case 0: classesToCheck = pkg.ordinaryClasses(); break; case 1: classesToCheck = pkg.enums(); break; case 2: classesToCheck = pkg.errors(); break; case 3: classesToCheck = pkg.exceptions(); break; case 4: classesToCheck = pkg.getInterfaces(); break; default: System.err.println("Error reading package: " + pkg.name()); break; } for (ClassInfo cl : classesToCheck) { if (!cl.isHidden()) { allHidden = false; break; } } if (!allHidden) { break; } pass++; } if (allHidden) { continue; } data.setValue("reference", "1"); data.setValue("reference.apilevels", sinceTagger.hasVersions() ? "1" : "0"); data.setValue("docs.packages." + i + ".name", s); data.setValue("docs.packages." + i + ".link", pkg.htmlPage()); data.setValue("docs.packages." + i + ".since.key", SinceTagger.keyForName(pkg.getSince())); data.setValue("docs.packages." + i + ".since.name", pkg.getSince()); TagInfo.makeHDF(data, "docs.packages." + i + ".shortDescr", pkg.firstSentenceTags()); i++; } sinceTagger.writeVersionNames(data); return data; }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step6GraphTransitivityCleaner.java
/** * Find all elementary cycles in graph (with hard limit 10k cycles to prevent overflow) * * @param graph graph/*from w ww .j a v a2s . com*/ * @return list of paths (path = list of node ID) of null, if self-loop found */ private static List<List<Object>> findCyclesInGraph(Graph graph) { // convert into adjacency matrix representation SortedMap<String, Integer> nodeToIndexMap = new TreeMap<>(); ArrayList<Node> origNodes = new ArrayList<>(graph.getNodeSet()); for (int i = 0; i < origNodes.size(); i++) { nodeToIndexMap.put(origNodes.get(i).getId(), i); } // convert to different format for the algorithm String[] nodeIds = new String[origNodes.size()]; boolean adjMatrix[][] = new boolean[origNodes.size()][origNodes.size()]; // fill node IDs to array for (Map.Entry<String, Integer> entry : nodeToIndexMap.entrySet()) { nodeIds[entry.getValue()] = entry.getKey(); } // fill adjacency matrix for (Edge edge : graph.getEdgeSet()) { String sourceId = edge.getSourceNode().getId(); String targetId = edge.getTargetNode().getId(); int sourceIndex = nodeToIndexMap.get(sourceId); int targetIndex = nodeToIndexMap.get(targetId); adjMatrix[sourceIndex][targetIndex] = true; } // let's do the magic :) ElementaryCyclesSearch ecs = new ElementaryCyclesSearch(adjMatrix, nodeIds); List<List<Object>> cycles = ecs.getElementaryCycles(); // since the algorithm doesn't reveal self-loops, find them by ourselves for (Edge edge : graph.getEdgeSet()) { if (edge.getTargetNode().getId().equals(edge.getSourceNode().getId())) { // cycles.add(Arrays.asList((Object) edge.getSourceNode().getId(), // edge.getTargetNode().getId())); cycles.add(Collections.<Object>singletonList(edge.getSourceNode().getId())); } } // System.out.println(cycles); return cycles; }
From source file:viper.api.time.TimeEncodedList.java
/** * Removes all values at the given range. Note that, like * <code>SortedMap</code>, this means that value is set in the * range from start, inclusive, to stop, exclusive. * @param start the first index to remove * @param stop the first index that is not removed * @return <code>true</code> if any elements were removed *///from w w w.j a v a2 s . com public boolean remove(Comparable start, Comparable stop) { boolean someFound = false; SortedMap head = values.headMap(start); if (!head.isEmpty()) { LelNode n = (LelNode) head.get(head.lastKey()); if (n.getEnd().compareTo(start) > 0) { someFound = true; head.put(head.lastKey(), new LelNode((Instant) start, n.getValue())); if (n.getEnd().compareTo(stop) > 0) { // this object spans the whole removed range values.put(stop, new TimeEncodedList.LelNode(n.getEnd(), n.getValue())); return true; } } } // By now, will have removed anything coming in from the head // Just remove the stuff in the subMap, making sure to put back // the leftovers. SortedMap sub = values.subMap(start, stop); if (!sub.isEmpty()) { LelNode n = (LelNode) sub.get(sub.lastKey()); if (n.getEnd().compareTo(stop) > 0) { values.put(stop, new LelNode(n.getEnd(), n.getValue())); } values.subMap(start, stop).clear(); return true; } return someFound; }
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 .jav 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:viper.api.time.TimeEncodedList.java
/** * Get the value at the specified index in the list. * @param index the index into the list//from www . ja v a2s. c o m * @return the value at the specified index */ public Object get(Instant index) { assert index != null; SortedMap m = values.tailMap(index); if (!m.isEmpty() && m.firstKey().equals(index)) { return ((LelNode) m.get(index)).getValue(); } m = values.headMap(index); if (!m.isEmpty()) { LelNode v = (LelNode) m.get(m.lastKey()); if (v.getEnd().compareTo(index) > 0) { return v.getValue(); } } return null; }
From source file:be.shad.tsqb.test.SelectTests.java
private void selectMapsDtoTest(boolean aliases) { TestDataCreator creator = new TestDataCreator(getSessionFactory()); creator.createTestPerson(creator.createTestTown(), "Josh"); ((TypeSafeRootQueryInternal) query).getProjections().setIncludeAliases(aliases); Person person = query.from(Person.class); MapsDto dtoPx = query.select(MapsDto.class); Map<String, Object> genericMapPx = dtoPx.getNestedMaps().getGenericMap(); CustomMap<String, Object> customMapPx = dtoPx.getNestedMaps().getCustomMap(); SortedMap<String, Object> sortedMapPx = dtoPx.getSortedMap(); genericMapPx.put("person.value", person.getName()); customMapPx.put("person.object", person); sortedMapPx.put("person.transformed", query.select(String.class, person.getName(), new SelectionValueTransformer<String, String>() { @Override//from ww w . j a va 2 s . c o m public String convert(String name) throws SelectionValueTransformerException { return "###" + name + "###"; } })); // subselect map Map<String, Object> merge1 = query.selectMergeValues(dtoPx, new MapSelectionMerger<MapsDto, String, Object>() { @Override public void mergeMapIntoResult(MapsDto partialResult, Map<String, Object> map) { partialResult.getSortedMap().put("thepersonid", map.get("person.id")); } }); merge1.put("person.id", person.getId()); if (aliases) { validate("select hobj1.name as nestedMaps_genericMap_person_value, " + "hobj1 as nestedMaps_customMap_person_object, " + "hobj1.name as sortedMap_person_transformed, " + "hobj1.id as g1__person_id " + "from Person hobj1"); } else { validate("select hobj1.name, hobj1, hobj1.name, hobj1.id from Person hobj1"); } assertTrue(MapsDto.class.isAssignableFrom(doQueryResult.get(0).getClass())); MapsDto result = (MapsDto) doQueryResult.get(0); Map<String, Object> genericMap = result.getNestedMaps().getGenericMap(); CustomMap<String, Object> customMap = result.getNestedMaps().getCustomMap(); SortedMap<String, Object> sortedMap = result.getSortedMap(); assertEquals("Josh", genericMap.get("person.value")); assertEquals("###Josh###", sortedMap.get("person.transformed")); assertTrue(Person.class.isAssignableFrom(customMap.get("person.object").getClass())); assertNotNull(sortedMap.get("thepersonid")); }
From source file:viper.api.time.TimeEncodedList.java
/** * Sets the value at the given range. Note that, like * <code>SortedMap</code>, this means that value is set in the * range from start, inclusive, to stop, exclusive. * @param start the first index to set/* w w w . j a v a 2s .com*/ * @param stop the first index that is not set * @param value all elements in the list in the range [start, stop) * will take this value * @throws IllegalArgumentException if start is not less than stop */ public void set(Comparable start, Comparable stop, Object value) { if (start.compareTo(stop) >= 0) { throw new IllegalArgumentException("Start not strictly less than stop: " + start + " !< " + stop); } if (value == null) { remove(start, stop); return; } SortedMap head = values.headMap(start); if (!head.isEmpty()) { LelNode n = (LelNode) head.get(head.lastKey()); if (n.getValue().equals(value)) { if (n.getEnd().compareTo(start) >= 0) { start = (Instant) head.lastKey(); } } else if (n.getEnd().compareTo(start) > 0) { head.put(head.lastKey(), new LelNode((Instant) start, n.getValue())); if (n.getEnd().compareTo(stop) > 0) { values.put(start, new LelNode((Instant) stop, value)); values.put(stop, new LelNode(n.getEnd(), n.getValue())); return; } } } SortedMap sub = values.subMap(start, stop); if (!sub.isEmpty()) { LelNode n = (LelNode) sub.get(sub.lastKey()); if (n.getValue().equals(value)) { if (n.getEnd().compareTo(stop) > 0) { stop = n.getEnd(); } } else if (n.getEnd().compareTo(stop) > 0) { values.put(stop, new LelNode(n.getEnd(), n.getValue())); } } values.subMap(start, stop).clear(); values.put(start, new TimeEncodedList.LelNode((Instant) stop, value)); }
From source file:com.aurel.track.fieldType.bulkSetters.CompositeSelectBulkSetter.java
/** * Sets the workItemBean's attribute depending on the value and bulkRelation * @param workItemBean//w w w . ja v a2s . c o m * @param fieldID * @param parameterCode * @param bulkTranformContext * @param selectContext * @param value * @return ErrorData if an error is found */ @Override public ErrorData setWorkItemAttribute(TWorkItemBean workItemBean, Integer fieldID, Integer parameterCode, BulkTranformContext bulkTranformContext, SelectContext selectContext, Object value) { if (value == null) { return null; } Map<Integer, SortedMap<Integer, Integer[]>> valueMap = (Map<Integer, SortedMap<Integer, Integer[]>>) value; CustomCompositeBaseRT customCompositeBaseRT = null; try { customCompositeBaseRT = (CustomCompositeBaseRT) FieldTypeManager.getFieldTypeRT(fieldID); } catch (Exception e) { } if (customCompositeBaseRT != null) { int noOfParts = customCompositeBaseRT.getNumberOfParts(); if (getRelation() == BulkRelations.SET_NULL) { for (int i = 0; i < noOfParts; i++) { workItemBean.setAttribute(fieldID, Integer.valueOf(i + 1), null); } return null; } else { if (getRelation() == BulkRelations.SET_TO && value != null) { Map<Integer, Map<Integer, Map<Integer, Integer>>> fieldToProjectToIssueTypeToListMap = bulkTranformContext .getFieldToProjectToIssueTypeToListMap(); if (fieldToProjectToIssueTypeToListMap != null) { Map<Integer, Map<Integer, Integer>> projectToIssueTypeToListMap = fieldToProjectToIssueTypeToListMap .get(fieldID); if (projectToIssueTypeToListMap != null) { Integer projectID = workItemBean.getProjectID(); Map<Integer, Integer> issueTypeToListMap = projectToIssueTypeToListMap.get(projectID); if (issueTypeToListMap != null) { Integer issueTypeID = workItemBean.getListTypeID(); Integer listID = issueTypeToListMap.get(issueTypeID); if (listID != null) { SortedMap<Integer, Integer[]> compositeListMap = valueMap.get(listID); if (compositeListMap != null) { for (int i = 0; i < noOfParts; i++) { Integer localParameterCode = Integer.valueOf(i + 1); workItemBean.setAttribute(fieldID, localParameterCode, compositeListMap.get(localParameterCode)); } } } } } } } } } return null; }
From source file:com.citic.zxyjs.zwlscx.mapreduce.join.api.DataJoinReducerBase.java
/** * This is the function that re-groups values for a key into sub-groups * based on a secondary key (input tag). * //from w ww . j a v a2 s .co m * @param values * @return */ private SortedMap<Text, ResetableIterator<TaggedMapOutput>> regroup(Text key, Iterator<TaggedMapOutput> values, Context context) throws IOException { this.numOfValues = 0; SortedMap<Text, ResetableIterator<TaggedMapOutput>> retv = new TreeMap<Text, ResetableIterator<TaggedMapOutput>>(); TaggedMapOutput aRecord = null; while (values.hasNext()) { this.numOfValues += 1; if (this.numOfValues % 100 == 0) { reporter.setStatus("key: " + key.toString() + " numOfValues: " + this.numOfValues); } if (this.numOfValues > this.maxNumOfValuesPerGroup) { continue; } aRecord = values.next().clone(context.getConfiguration()); Text tag = aRecord.getTag(); ResetableIterator<TaggedMapOutput> data = retv.get(tag); if (data == null) { data = createResetableIterator(); retv.put(tag, data); } data.add(aRecord); } if (this.numOfValues > this.largestNumOfValues) { this.largestNumOfValues = numOfValues; LOG.info("key: " + key.toString() + " this.largestNumOfValues: " + this.largestNumOfValues); } return retv; }
From source file:org.kuali.kra.budget.external.budget.impl.BudgetAdjustmentServiceHelperImpl.java
/** * This method returns the personnel salary cost. * @return/*from w ww . j av a2 s .c o m*/ * @throws Exception */ public SortedMap<String, ScaleTwoDecimal> getPersonnelSalaryCost(Budget currentBudget, AwardBudgetExt previousBudget) throws Exception { SortedMap<String, List<ScaleTwoDecimal>> currentSalaryTotals = currentBudget .getObjectCodePersonnelSalaryTotals(); SortedMap<String, ScaleTwoDecimal> netSalary = new TreeMap<String, ScaleTwoDecimal>(); int period = currentBudget.getBudgetPeriods().size() - 1; for (String person : currentSalaryTotals.keySet()) { String key = person; if (person.contains(",")) { String[] objectCode = getElements(key); key = objectCode[0]; } ScaleTwoDecimal currentSalary = currentSalaryTotals.get(person).get(period); netSalary.put(key, currentSalary); } return netSalary; }