List of usage examples for java.util SortedSet size
int size();
From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImplTest.java
/** * @throws ParseException // w w w .j a v a2 s . c om * @throws InputFormatException * */ @Test public void testAvailable104() throws InputFormatException, ParseException { // get owner with meeting durations preference of 20 minutes IScheduleOwner owner = sampleOwners[3]; SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat(); SortedSet<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "11:40 AM", "MW", dateFormat.parse("20100830"), dateFormat.parse("20100903"), 1); availableScheduleDao.addToSchedule(owner, blocks); AvailableSchedule stored = availableScheduleDao.retrieve(owner); SortedSet<AvailableBlock> storedBlocks = stored.getAvailableBlocks(); Assert.assertEquals(2, storedBlocks.size()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-0900"), storedBlocks.first().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-1140"), storedBlocks.first().getEndTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100901-0900"), storedBlocks.last().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100901-1140"), storedBlocks.last().getEndTime()); SortedSet<AvailableBlock> expanded = AvailableBlockBuilder.expand(storedBlocks, 20); Assert.assertEquals(16, expanded.size()); Date originalStart = CommonDateOperations.getDateTimeFormat().parse("20100830-0900"); Date currentStart = originalStart; for (AvailableBlock e : expanded) { if (!DateUtils.isSameDay(e.getStartTime(), currentStart)) { currentStart = DateUtils.addDays(originalStart, 2); } Assert.assertEquals(currentStart, e.getStartTime()); currentStart = DateUtils.addMinutes(currentStart, 20); Assert.assertEquals(currentStart, e.getEndTime()); } }
From source file:au.edu.uq.cmm.paul.grabber.Analyser.java
public Analyser analyse(Date lwmTimestamp, Date hwmTimestamp, DateRange queueRange, boolean checkHashes) { this.lwm = lwmTimestamp; this.hwm = hwmTimestamp; if (queueRange == null) { this.qStart = null; this.qEnd = null; } else {//from w ww . j a va 2 s . c o m this.qStart = queueRange.getFromDate(); this.qEnd = queueRange.getToDate(); } this.checkHashes = checkHashes; LOG.info("Analysing queues and folders for " + getFacility().getFacilityName()); SortedSet<DatasetMetadata> inFolder = buildInFolderMetadata(); SortedSet<DatasetMetadata> inDatabase = buildInDatabaseMetadata(); LOG.debug("Got " + inFolder.size() + " in folders and " + inDatabase.size() + " in database"); LOG.info("Grouping datasets for " + getFacility().getFacilityName()); grouped = groupDatasets(inFolder, inDatabase); LOG.debug("Got " + grouped.size() + " groups"); LOG.info("Gathering statistics for " + getFacility().getFacilityName()); determineFolderRange(inFolder); all = gatherStats(grouped, PredicateUtils.truePredicate()); if (hwmTimestamp == null || lwmTimestamp == null) { beforeLWM = null; afterHWM = null; intertidal = null; } else { final long lwmTime = lwmTimestamp.getTime(); beforeLWM = gatherStats(grouped, new Predicate() { public boolean evaluate(Object metadata) { return ((DatasetMetadata) metadata).getLastFileTimestamp().getTime() < lwmTime; } }); final long hwmTime = hwmTimestamp.getTime(); afterHWM = gatherStats(grouped, new Predicate() { public boolean evaluate(Object metadata) { return ((DatasetMetadata) metadata).getLastFileTimestamp().getTime() > hwmTime; } }); intertidal = gatherStats(grouped, new Predicate() { public boolean evaluate(Object metadata) { long time = ((DatasetMetadata) metadata).getLastFileTimestamp().getTime(); return time >= lwmTime && time <= hwmTime; } }); } if (queueRange == null) { afterQEnd = null; beforeQStart = null; inQueue = null; } else { final long qStart = this.qStart.getTime(); beforeQStart = gatherStats(grouped, new Predicate() { public boolean evaluate(Object metadata) { return ((DatasetMetadata) metadata).getLastFileTimestamp().getTime() < qStart; } }); final long qEnd = this.qEnd.getTime(); afterQEnd = gatherStats(grouped, new Predicate() { public boolean evaluate(Object metadata) { return ((DatasetMetadata) metadata).getLastFileTimestamp().getTime() > qEnd; } }); inQueue = gatherStats(grouped, new Predicate() { public boolean evaluate(Object metadata) { long ts = ((DatasetMetadata) metadata).getLastFileTimestamp().getTime(); return ts >= qStart && ts <= qEnd; } }); } LOG.info("Performing queue entry integrity checks for " + getFacility().getFacilityName()); problems = integrityCheck(grouped); return this; }
From source file:org.eclipse.skalli.view.ext.impl.internal.infobox.ProjectIssuesBox.java
@Override @SuppressWarnings("nls") public Component getContent(Project project, ExtensionUtil util) { Layout layout = new CssLayout(); layout.addStyleName(STYLE_ISSUES_INFOBOX); layout.setSizeFull();//w ww . j a v a 2 s . c o m IssuesService issuesService = Services.getService(IssuesService.class); if (issuesService != null) { Issues issues = issuesService.loadEntity(Issues.class, project.getUuid()); StringBuilder sb = new StringBuilder(); if (issues != null) { if (issues.isStale()) { sb.append("<ul><li class=\"STALE\">No information about issues available.</li></ul>"); } else { SortedSet<Issue> issueSet = issues.getIssues(); if (!issueSet.isEmpty()) { sb.append(Issue.asHTMLList(null, issueSet)); if (util.isUserProjectAdmin(project)) { sb.append("<p>Click <a href=\"").append(Consts.URL_PROJECTS).append("/") .append(project.getProjectId()).append("?").append(Consts.PARAM_ACTION) .append("=").append(Consts.PARAM_VALUE_EDIT).append("\">here</a> to correct "); sb.append((issueSet.size() == 1) ? "this issue" : "these issues"); sb.append(".</p>"); } } } if (util.isUserProjectAdmin(project)) { sb.append("<p>Click <a href=\"").append(Consts.URL_PROJECTS).append("/"); sb.append(project.getProjectId()).append("?").append(Consts.PARAM_ACTION).append("="); sb.append(Consts.PARAM_VALUE_VALIDATE).append("\">here</a> to validate the project now.</p>"); } createLabel(layout, sb.toString(), STYLE_ISSUES); } } return layout; }
From source file:org.jasig.ssp.service.impl.PersonServiceBulkCoachLookupIntegrationTest.java
/** * Ignored b/c it doesn't assert anything, it just demonstrates the * performance (and behavioral) differences between * {@link PersonService#getAllCurrentCoaches(java.util.Comparator)} * and {@link PersonService#getAllCurrentCoachesLite(java.util.Comparator)}. * There are (at least) three problems with the former... * * <ol>//from w ww. ja v a2s .c o m * <li>It lazily creates person records it hasn't encountered before, * and</li> * <li>It looks up {@link Person}s one-by-one, and</li> * <li>Person lookups are just very expensive</li> * </ol> * * <p>So if the total number of coaches returned from * {@link org.jasig.ssp.service.PersonAttributesService#getCoaches()} is * large (anywhere into the 100s), * {@link PersonService#getAllCurrentCoaches(java.util.Comparator)} is * unsuitable for invocation in the request cycle, <em>even if all * the referenced coaches have already been created as {@link Person} * records</em>.</p> * * <p>{@link PersonService#getAllCurrentCoachesLite(java.util.Comparator)} * is faster, but partly b/c it doesn't make any attempt to lazily create * new {@link Person}s. So it doesn't run the risk of exceptionally long * runtimes when first invoked. But it does so at the cost of potentially * not returning a completely up-to-date view of all coaches. * <a href="https://issues.jasig.org/browse/SSP-470">SSP-470</a> combats * this by moving the {@link Person} creation into a background job.</p> * * <p>This test demonstrates the performance gradient by causing * {@link org.jasig.ssp.service.PersonAttributesService#getCoaches()} to * return 500 coach usernames the {@link PersonService} hasn't seen before, * then making a series of calls to the methods of interest. At this * writing (Nov 20, 2012), in an all-local development env, the numbers * looked like this (execution time in * {@link org.jasig.ssp.service.PersonAttributesService#getCoaches()} is * effecively negiligible b/c this test stubs that service):</p> * * <ol> * <li>{@link PersonService#getAllCurrentCoachesLite(java.util.Comparator)} (returns 1 record): 55ms</li> * <li>{@link PersonService#getAllCurrentCoaches(java.util.Comparator)} (returns 501 records): 29504ms</li> * <li>{@link PersonService#getAllCurrentCoaches(java.util.Comparator)} (returns 501 records): 15428ms</li> * <li>{@link PersonService#getAllCurrentCoachesLite(java.util.Comparator)} (returns 501 records): 59ms</li> * </ol> * * <p>Keep in mind again that * {@link PersonService#getAllCurrentCoachesLite(java.util.Comparator)} * doesn't make any of the lazy-creation promises of * {@link PersonService#getAllCurrentCoaches(java.util.Comparator)}, so * the comparison isn't completely fair. But the calls to the latter * are sufficiently slow that it would be nice to find a way to * drop them both down... maybe through a combination of bulk db reads * and writes and by simplifying the object graph returned with all * {@link Person} lookups.</p> * */ @Test @Ignore public void testLiteCoachLookupMuchFasterButPotentiallyIncomplete() { int externalCoachQuota = 500; Set<String> addedCoachUsernames = addCoachesToExternalDataAndAttributeService(externalCoachQuota); long started = new Date().getTime(); final PagingWrapper<CoachPersonLiteTO> allCoachesLite1 = personService.getAllCoachesLite(null); long ended = new Date().getTime(); System.out.println("Lite Person lookups, no external Persons created yet: " + (ended - started) + "ms (" + allCoachesLite1.getResults() + " total records returned)"); started = new Date().getTime(); final SortedSet<Person> lazyCreatedCoaches1 = personService.getAllCurrentCoaches(null); ended = new Date().getTime(); System.out.println("Full Person lookups, lazy Person record creation: " + (ended - started) + "ms (" + externalCoachQuota + " lazy records, " + lazyCreatedCoaches1.size() + " total records returned)"); started = new Date().getTime(); final SortedSet<Person> lazyCreatedCoaches2 = personService.getAllCurrentCoaches(null); ended = new Date().getTime(); System.out.println("Full Person lookups, all Persons already created: " + (ended - started) + "ms (" + lazyCreatedCoaches2.size() + " total records returned)"); started = new Date().getTime(); final PagingWrapper<CoachPersonLiteTO> allCoachesLite2 = personService.getAllCoachesLite(null); ended = new Date().getTime(); System.out.println("Lite Person lookups, all Persons already created: " + (ended - started) + "ms (" + allCoachesLite2.getResults() + " total records returned)"); }
From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImplTest.java
/** * /*from w w w.j a v a 2s . c om*/ * @throws Exception */ @Test public void testAddRemoveScheduleMultiples() throws Exception { Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "5:00 PM", "MWF", CommonDateOperations.parseDatePhrase("20091102"), CommonDateOperations.parseDatePhrase("20091127")); AvailableSchedule schedule = availableScheduleDao.addToSchedule(sampleOwners[0], blocks); SortedSet<AvailableBlock> stored = schedule.getAvailableBlocks(); Assert.assertEquals(12, stored.size()); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091102-0900", "20091102-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091104-0900", "20091104-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091106-0900", "20091106-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091109-0900", "20091109-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091111-0900", "20091111-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091113-0900", "20091113-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091116-0900", "20091116-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091118-0900", "20091118-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091120-0900", "20091120-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091123-0900", "20091123-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091125-0900", "20091125-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091127-0900", "20091127-1700"))); schedule = availableScheduleDao.retrieve(sampleOwners[0]); stored = schedule.getAvailableBlocks(); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091102-0900", "20091102-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091104-0900", "20091104-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091106-0900", "20091106-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091109-0900", "20091109-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091111-0900", "20091111-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091113-0900", "20091113-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091116-0900", "20091116-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091118-0900", "20091118-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091120-0900", "20091120-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091123-0900", "20091123-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091125-0900", "20091125-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091127-0900", "20091127-1700"))); // remove some blocks from the middle of a few days schedule = availableScheduleDao.removeFromSchedule(sampleOwners[0], AvailableBlockBuilder.createBlock("20091111-1200", "20091111-1300")); stored = schedule.getAvailableBlocks(); Assert.assertFalse(stored.contains(AvailableBlockBuilder.createBlock("20091111-0900", "20091111-1700"))); Assert.assertFalse(stored.contains(AvailableBlockBuilder.createBlock("20091111-1200", "20091111-1300"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091111-0900", "20091111-1200"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091111-1300", "20091111-1700"))); schedule = availableScheduleDao.removeFromSchedule(sampleOwners[0], AvailableBlockBuilder.createBlock("20091116-0900", "20091116-1200")); stored = schedule.getAvailableBlocks(); Assert.assertFalse(stored.contains(AvailableBlockBuilder.createBlock("20091116-0900", "20091116-1200"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091116-1200", "20091116-1700"))); schedule = availableScheduleDao.removeFromSchedule(sampleOwners[0], AvailableBlockBuilder.createBlock("20091127-1600", "20091127-1800")); stored = schedule.getAvailableBlocks(); Assert.assertFalse(stored.contains(AvailableBlockBuilder.createBlock("20091127-0900", "20091127-1700"))); Assert.assertTrue(stored.contains(AvailableBlockBuilder.createBlock("20091127-0900", "20091127-1600"))); }
From source file:org.eclipse.winery.repository.resources.artifacts.GenericArtifactsResource.java
/** * Required for artifacts.jsp//ww w. java2s .com * * @return list of known artifact types. */ public List<QName> getAllArtifactTypes() { SortedSet<ArtifactTypeId> allArtifactTypes = Repository.INSTANCE .getAllTOSCAComponentIds(ArtifactTypeId.class); List<QName> res = new ArrayList<QName>(allArtifactTypes.size()); for (ArtifactTypeId id : allArtifactTypes) { res.add(id.getQName()); } return res; }
From source file:org.apache.accumulo.examples.wikisearch.ingest.WikipediaPartitionedIngester.java
private int runPartitionerJob() throws Exception { Job partitionerJob = new Job(getConf(), "Partition Wikipedia"); Configuration partitionerConf = partitionerJob.getConfiguration(); partitionerConf.set("mapred.map.tasks.speculative.execution", "false"); configurePartitionerJob(partitionerJob); List<Path> inputPaths = new ArrayList<Path>(); SortedSet<String> languages = new TreeSet<String>(); FileSystem fs = FileSystem.get(partitionerConf); Path parent = new Path(partitionerConf.get("wikipedia.input")); listFiles(parent, fs, inputPaths, languages); System.out.println("Input files in " + parent + ":" + inputPaths.size()); Path[] inputPathsArray = new Path[inputPaths.size()]; inputPaths.toArray(inputPathsArray); System.out.println("Languages:" + languages.size()); // setup input format WikipediaInputFormat.setInputPaths(partitionerJob, inputPathsArray); partitionerJob.setMapperClass(WikipediaPartitioner.class); partitionerJob.setNumReduceTasks(0); // setup output format partitionerJob.setMapOutputKeyClass(Text.class); partitionerJob.setMapOutputValueClass(Article.class); partitionerJob.setOutputKeyClass(Text.class); partitionerJob.setOutputValueClass(Article.class); partitionerJob.setOutputFormatClass(SequenceFileOutputFormat.class); Path outputDir = WikipediaConfiguration.getPartitionedArticlesPath(partitionerConf); SequenceFileOutputFormat.setOutputPath(partitionerJob, outputDir); SequenceFileOutputFormat.setCompressOutput(partitionerJob, true); SequenceFileOutputFormat.setOutputCompressionType(partitionerJob, CompressionType.RECORD); return partitionerJob.waitForCompletion(true) ? 0 : 1; }
From source file:edu.harvard.med.screensaver.model.screenresults.ScreenResult.java
public AdministrativeActivity createScreenResultDataLoading(AdministratorUser performedBy, Map<Integer, Integer> plateNumbersLoadedWithMaxReplicates, String comments) { Set<AssayPlate> assayPlatesDataLoaded = findOrCreateAssayPlatesDataLoaded( plateNumbersLoadedWithMaxReplicates); SortedSet<Integer> plateNumbers = Sets .newTreeSet(Iterables.transform(assayPlatesDataLoaded, AssayPlate.ToPlateNumber)); String mandatoryComments = "Loaded data for " + plateNumbers.size() + " plates " + Joiner.on(",").join(Iterables.transform(CollectionUtils.splitIntoSequentialRanges(plateNumbers), formatPlateNumberRange)); if (StringUtils.isEmpty(comments)) { comments = ""; }/*from www . jav a 2 s.c o m*/ comments = Joiner.on(". ").join(mandatoryComments, comments); AdministrativeActivity screenResultDataLoading = getScreen() .createUpdateActivity(AdministrativeActivityType.SCREEN_RESULT_DATA_LOADING, performedBy, comments); for (AssayPlate assayPlate : assayPlatesDataLoaded) { assayPlate.setScreenResultDataLoading(screenResultDataLoading); } return screenResultDataLoading; }
From source file:gov.nih.nci.cabig.caaers.domain.ResearchStaff.java
/** * The earliest start date of this research staff. * * @return the active date/*from w ww .j a va 2 s . co m*/ */ @Transient public Date getActiveDate() { SortedSet<Date> dates = new TreeSet<Date>(); for (SiteResearchStaff srs : this.getSiteResearchStaffs()) { Date activeDate = srs.getActiveDate(); if (activeDate != null) dates.add(activeDate); } if (dates.size() > 0) return dates.first(); else return null; }
From source file:org.apache.blur.kvs.HdfsKeyValueStore.java
public void cleanupOldFiles() throws IOException { _writeLock.lock();// ww w . j a v a 2 s . co m try { if (!isOpenForWriting()) { return; } SortedSet<FileStatus> fileStatusSet = getSortedSet(_path); if (fileStatusSet == null || fileStatusSet.size() < 1) { return; } Path newestGen = fileStatusSet.last().getPath(); if (!newestGen.equals(_outputPath)) { throw new IOException("No longer the owner of [" + _path + "]"); } Set<Path> existingFiles = new HashSet<Path>(); for (FileStatus fileStatus : fileStatusSet) { existingFiles.add(fileStatus.getPath()); } Set<Entry<BytesRef, Value>> entrySet = _pointers.entrySet(); existingFiles.remove(_outputPath); for (Entry<BytesRef, Value> e : entrySet) { Path p = e.getValue()._path; existingFiles.remove(p); } for (Path p : existingFiles) { LOG.info("Removing file no longer referenced [{0}]", p); _fileSystem.delete(p, false); } } finally { _writeLock.unlock(); } }