List of usage examples for java.util SortedSet addAll
boolean addAll(Collection<? extends E> c);
From source file:io.wcm.wcm.parsys.componentinfo.impl.AllowedComponentsProviderImpl.java
/** * Get all allowed components for a template (not respecting any path constraints) * @param pageComponentPath Path of template's page component * @return Set of component paths (absolute resource types) *//*from www .j a va 2s .co m*/ @Override public Set<String> getAllowedComponentsForTemplate(String pageComponentPath, ResourceResolver resolver) { Resource pageComponentResource = resolver.getResource(pageComponentPath); if (pageComponentResource != null) { Iterable<ParsysConfig> parSysConfigs = parsysConfigManager .getParsysConfigs(pageComponentResource.getPath(), resolver); SortedSet<String> allowedChildren = new TreeSet<>(); for (ParsysConfig parSysConfig : parSysConfigs) { allowedChildren.addAll(makeAbsolute(parSysConfig.getAllowedChildren(), resolver)); } return allowedChildren; } // fallback return ImmutableSet.of(); }
From source file:net.sourceforge.subsonic.service.ITunesParser.java
private Map<String, File> parseTracks(List<ITunesPlaylist> playlists) throws Exception { Map<String, File> result = new HashMap<String, File>(); SortedSet<String> trackIds = new TreeSet<String>(); for (ITunesPlaylist playlist : playlists) { trackIds.addAll(playlist.trackIds); }/*from w w w. j av a2 s . c o m*/ InputStream in = new FileInputStream(iTunesXml); try { XMLStreamReader streamReader = inputFactory.createXMLStreamReader(in); String trackId = null; while (streamReader.hasNext()) { int code = streamReader.next(); if (code == XMLStreamReader.START_ELEMENT) { String key = readKey(streamReader); if ("Track ID".equals(key)) { trackId = readNextTag(streamReader); } else if (trackId != null && trackIds.contains(trackId) && "Location".equals(key)) { String location = readNextTag(streamReader); File file = new File(StringUtil.urlDecode(new URL(location).getFile())); result.put(trackId, file); } } } } finally { IOUtils.closeQuietly(in); } return result; }
From source file:net.joinedminds.tools.evet.TimeValueTable.java
private JSONObject getJsonObject() { FastDateFormat fdf = resolution == Db.CountResolution.Day ? DATE_FORMAT : DATETIME_FORMAT; JSONObject data = new JSONObject(); JSONArray categories = new JSONArray(); JSONArray values = new JSONArray(); SortedSet<Date> keys = new TreeSet<>(); keys.addAll(keySet()); for (Date key : keys) { categories.add(fdf.format(key)); values.add(get(key).get(0)); //TODO support multisets }/*from w ww.j a va2 s.co m*/ data.put("categories", categories); data.put("data", values); return data; }
From source file:net.joinedminds.tools.evet.TimeValueTable.java
protected void generateCsvResponse(StaplerResponse rsp) throws IOException { FastDateFormat fdf = resolution == Db.CountResolution.Day ? DATE_FORMAT : DATETIME_FORMAT; rsp.setContentType("text/csv"); PrintWriter out = rsp.getWriter(); SortedSet<Date> keys = new TreeSet<>(); keys.addAll(keySet()); for (Date key : keys) { out.print(fdf.format(key));/* w w w. j av a2s . c o m*/ for (Integer value : get(key)) { out.print(','); out.print(value); } out.println(); } out.flush(); }
From source file:org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSelectionStrategy.java
/** * Select the disposition schedule to use given there is more than one * * @param recordFolders//from w ww.j a va 2 s . co m * @return */ public NodeRef selectDispositionScheduleFrom(List<NodeRef> recordFolders) { if (recordFolders == null || recordFolders.isEmpty()) { return null; } else { // 46 CHAPTER 2 // Records assigned more than 1 disposition must be retained and linked to the record folder (category) with the longest // retention period. // Assumption: an event-based disposition action has a longer retention // period than a time-based one - as we cannot know when an event will occur // TODO Automatic events? NodeRef recordFolder = null; if (recordFolders.size() == 1) { recordFolder = recordFolders.get(0); } else { SortedSet<NodeRef> sortedFolders = new TreeSet<NodeRef>(new DispositionableNodeRefComparator()); sortedFolders.addAll(recordFolders); recordFolder = sortedFolders.first(); } DispositionSchedule dispSchedule = dispositionService.getDispositionSchedule(recordFolder); if (logger.isDebugEnabled()) { logger.debug("Selected disposition schedule: " + dispSchedule); } NodeRef result = null; if (dispSchedule != null) { result = dispSchedule.getNodeRef(); } return result; } }
From source file:net.sourceforge.fenixedu.domain.organizationalStructure.ResearchUnit.java
public Collection<Unit> getAllCurrentActiveSubUnitsOrdered() { SortedSet<Unit> subUnits = new TreeSet<Unit>(Unit.COMPARATOR_BY_NAME_AND_ID); subUnits.addAll(getAllCurrentActiveSubUnits()); return subUnits; }
From source file:net.sourceforge.fenixedu.presentationTier.renderers.PersonUnitFunctionsTreeRenderer.java
@Override protected Collection<PersonFunction> getChildrenCollectionFor(Function function) { Person person = getPerson();/*from w w w. j a v a 2 s . c o m*/ SortedSet<PersonFunction> result = new TreeSet<PersonFunction>( new ReverseComparator(PersonFunction.COMPARATOR_BY_BEGIN_DATE)); result.addAll(person.getPersonFunctions(function)); return result; }
From source file:de.tudarmstadt.ukp.dkpro.tc.fstore.simple.DenseFeatureStore.java
@Override public SortedSet<String> getUniqueOutcomes() { SortedSet<String> uniqueOutcomes = new TreeSet<String>(); for (List<String> outcomes : outcomeList) { uniqueOutcomes.addAll(outcomes); }/*from w w w. j a v a2 s. c o m*/ return uniqueOutcomes; }
From source file:org.sakuli.services.forwarder.AbstractOutputBuilderTest.java
@Test(dataProvider = "testGenerateTestCaseInformationDP") public void testGenerateTestCaseInformation(TestCase[] testCases, String expectedTestCaseInformation) throws Exception { SortedSet<TestCase> input = new TreeSet<>(); input.addAll(Arrays.asList(testCases)); assertEquals(AbstractOutputBuilder.generateCaseInformation(input), expectedTestCaseInformation); }
From source file:femr.business.services.system.ResearchService.java
public static ResearchGraphDataItem createResearchGraphItem(ResearchResult primaryResult, ResearchResult secondaryResult, ResearchFilterItem filters) { ResearchGraphDataItem graphModel = new ResearchGraphDataItem(); List<ResearchItem> graphData = new ArrayList<>(); Map<String, ResearchItem> groupedData = new HashMap<>(); String yAxisTitle = "Number of Patients"; String xAxisTitle = WordUtils.capitalize(StringUtils.splitCamelCase(primaryResult.getDataType())); String unitOfMeasurement = primaryResult.getUnitOfMeasurement(); List<Float> sortedPrimary = new ArrayList<>(); Map<Integer, Float> primaryDataset = primaryResult.getDataset(); Map<Integer, Float> secondaryDataset = secondaryResult.getDataset(); int sampleSize = primaryDataset.size(); float total = 0; float rangeHigh = 0; float rangeLow = 10000; float median = 0; // Medications will not group correctly, just bundle and return if (filters.getPrimaryDataset().equals("prescribedMeds") || filters.getPrimaryDataset().equals("dispensedMeds")) { for (Integer key : primaryDataset.keySet()) { // Make sure all secondary keys are set for all items Float value = primaryDataset.get(key); ResearchItem currItem = new ResearchItem(); currItem.setPrimaryName(Float.toString((float) key)); currItem.setPrimaryValue(value); graphData.add(currItem);/*from w w w . j av a2 s . c o m*/ } graphModel.setAverage(0.0f); graphModel.setMedian(median); graphModel.setRangeLow(rangeLow); graphModel.setRangeHigh(rangeHigh); graphModel.setGraphData(graphData); graphModel.setPrimaryValuemap(primaryResult.getValueMap()); graphModel.setSecondaryValuemap(secondaryResult.getValueMap()); graphModel.setyAxisTitle(yAxisTitle); graphModel.setxAxisTitle(xAxisTitle); graphModel.setUnitOfMeasurement(unitOfMeasurement); return graphModel; } // total the individual patients based on their value Map<Float, ResearchItem> primaryGraphTotals = new HashMap<>(); // used to ensure all secondary keys are present in all items, just in case they have no data Map<String, Integer> secondaryKeyset = new HashMap<>(); for (Integer key : primaryDataset.keySet()) { Float value = primaryDataset.get(key); sortedPrimary.add(value); // Find current primary Value and add to builder map ResearchItem currItem; if (primaryGraphTotals.containsKey(value)) { currItem = primaryGraphTotals.get(value); float currItemTotal = currItem.getPrimaryValue() + 1; currItem.setPrimaryValue(currItemTotal); } else { currItem = new ResearchItem(); currItem.setPrimaryValue(1); } currItem.setPrimaryName(value.toString()); // check for and add secondary item to total if (secondaryDataset.containsKey(key)) { // Get secondary item form current ResearchItem Map<String, Float> secondaryItems = currItem.getSecondaryData(); Float secondaryValue = secondaryDataset.get(key); Float secondaryTotal = 1.0f; String secondaryKey = secondaryValue.toString(); // Keep track of unique keys for secondary items // want to make sure all possible keys are present in graphData secondaryKeyset.put(secondaryKey, 0); if (secondaryItems.containsKey(secondaryKey)) { secondaryTotal = secondaryItems.get(secondaryKey); secondaryTotal++; secondaryItems.put(secondaryKey, secondaryTotal); } else { secondaryItems.put(secondaryKey, 1.0f); } // add secondary totals to currItem currItem.setSecondaryData(secondaryItems); } primaryGraphTotals.put(value, currItem); // Calculate Stats while building data // check range if (value > rangeHigh) { rangeHigh = value; } if (value < rangeLow) { rangeLow = value; } // sum total for average total += value; } // If no grouping and over 30 items, force groups of 10 if (primaryGraphTotals.keySet().size() > 30 && !filters.isGroupPrimary() && (filters.getGraphType().equals("pie") || filters.getGraphType().equals("stacked-bar") || filters.getGraphType().equals("grouped-bar"))) { filters.setGroupPrimary(true); filters.setGroupFactor(10); } // Build group key values -- don't bother if there will only be 1 group // make happen automatically too? -- primaryGraphTotals.keySet().size() > 20 if (filters.isGroupPrimary() && primaryGraphTotals.keySet().size() > filters.getGroupFactor()) { int groupFactor = filters.getGroupFactor(); int firstLowKey = (int) (rangeLow / groupFactor) * groupFactor; int lastLowKey = (int) (rangeHigh / groupFactor) * groupFactor; //int totalGroups = (int)((lastLowKey-firstLowKey) / groupFactor); List<String> groupIndexes = new ArrayList<String>(); for (int low = firstLowKey; low <= lastLowKey; low += groupFactor) { int lowTemp = low; if (low < filters.getRangeStart()) { lowTemp = filters.getRangeStart().intValue(); } int high = low + (groupFactor - 1); if (high > filters.getRangeEnd()) { high = filters.getRangeEnd().intValue(); } String groupIndex = String.format("%d - %d", lowTemp, high); groupIndexes.add(groupIndex); ResearchItem blankItem = new ResearchItem(groupIndex); groupedData.put(groupIndex, blankItem); } for (Float key : primaryGraphTotals.keySet()) { ResearchItem currItem = primaryGraphTotals.get(key); Float newVal = Float.parseFloat(currItem.getPrimaryName()); Float newCount = currItem.getPrimaryValue(); int targetGroup = (int) (newVal / groupFactor) - (firstLowKey / groupFactor); String groupIndex = groupIndexes.get(targetGroup); ResearchItem finalItem; if (groupedData.containsKey(groupIndex)) { // add current single item to existing group Item finalItem = groupedData.get(groupIndex); Float currCount = finalItem.getPrimaryValue(); currCount += newCount; finalItem.setPrimaryValue(currCount); Map<String, Float> currSecondaryData = currItem.getSecondaryData(); for (String sKey : currSecondaryData.keySet()) { Float sCount = currSecondaryData.get(sKey); Map<String, Float> finalSecondaryData = finalItem.getSecondaryData(); if (finalSecondaryData.containsKey(sKey)) { Float finalCount = finalSecondaryData.get(sKey); finalCount += sCount; finalSecondaryData.put(sKey, finalCount); } else { finalSecondaryData.put(sKey, sCount); } finalItem.setSecondaryData(finalSecondaryData); } } else { // haven't encountered item in range before, just set to current single item finalItem = new ResearchItem(); finalItem.setPrimaryName(groupIndex); finalItem.setPrimaryValue(newCount); finalItem.setSecondaryData(currItem.getSecondaryData()); } // add item to grouped data groupedData.put(groupIndex, finalItem); } SortedSet<String> keys = new TreeSet<>(new GroupedCompare()); keys.addAll(groupedData.keySet()); for (String key : keys) { // Make sure all secondary keys are set for all items ResearchItem currItem = groupedData.get(key); Map<String, Float> secondaryData = currItem.getSecondaryData(); for (String secondaryKey : secondaryKeyset.keySet()) { if (!secondaryData.containsKey(secondaryKey)) { secondaryData.put(secondaryKey, 0.0f); } } graphData.add(currItem); } } else { SortedSet<Float> keys = new TreeSet<>(primaryGraphTotals.keySet()); for (Float key : keys) { // Make sure all secondary keys are set for all items ResearchItem currItem = primaryGraphTotals.get(key); Map<String, Float> secondaryData = currItem.getSecondaryData(); for (String secondaryKey : secondaryKeyset.keySet()) { if (!secondaryData.containsKey(secondaryKey)) { secondaryData.put(secondaryKey, 0.0f); } } graphData.add(currItem); } } // Sort primary Data Collections.sort(sortedPrimary); // Get Median Value from sorted list float average = total / sampleSize; if (sampleSize > 1) { if (sampleSize % 2 == 0) { int i = (sampleSize / 2) - 1; int j = i + 1; // get vals i and j float val1 = sortedPrimary.get(i); float val2 = sortedPrimary.get(j); //Integer key1 = primaryKeyList.get(i); //Integer key2 = primaryKeyList.get(j); //float val1 = primaryDataset.get(key1); //float val2 = primaryDataset.get(key2); median = (val1 + val2) / 2; } else { int i = (int) Math.floor(sampleSize / 2); //Integer key = primaryKeyList.get(i); //median = primaryDataset.get(key); median = sortedPrimary.get(i); } } else { median = sortedPrimary.get(0); } // build graph model item graphModel.setAverage(average); graphModel.setMedian(median); graphModel.setRangeLow(rangeLow); graphModel.setRangeHigh(rangeHigh); graphModel.setGraphData(graphData); graphModel.setPrimaryValuemap(primaryResult.getValueMap()); graphModel.setSecondaryValuemap(secondaryResult.getValueMap()); graphModel.setyAxisTitle(yAxisTitle); graphModel.setxAxisTitle(xAxisTitle); graphModel.setUnitOfMeasurement(unitOfMeasurement); return graphModel; }