List of usage examples for java.util SortedSet size
int size();
From source file:org.orekit.frames.FramesFactoryTest.java
@Test public void testEOPConversionSymetry1980() throws OrekitException { Utils.setDataRoot("rapid-data-columns"); IERSConventions.NutationCorrectionConverter converter = IERSConventions.IERS_1996 .getNutationCorrectionConverter(); SortedSet<EOPEntry> rawEquinox = new TreeSet<EOPEntry>(new ChronologicalComparator()); new RapidDataAndPredictionColumnsLoader(false, "^finals\\.daily$").fillHistory(converter, rawEquinox); Assert.assertEquals(181, rawEquinox.size()); for (final EOPEntry entry : rawEquinox) { final double[] rebuiltEquinox = converter.toEquinox(entry.getDate(), entry.getDx(), entry.getDy()); Assert.assertEquals(entry.getDdPsi(), rebuiltEquinox[0], 2.0e-22); Assert.assertEquals(entry.getDdEps(), rebuiltEquinox[1], 2.0e-23); }/*from w w w . j a v a 2 s . c o m*/ }
From source file:nz.ac.otago.psyanlab.common.designer.util.LongSparseArrayAdapter.java
private Long[] sortKeys(Context context, LongSparseArray<T> items) { Locale locale = context.getResources().getConfiguration().locale; final Collator collator = Collator.getInstance(locale); collator.setStrength(Collator.SECONDARY); SortedSet<Long> sortedKeys = new TreeSet<Long>(new Comparator<Long>() { @Override//from w w w .ja v a 2 s . c o m public int compare(Long lhs, Long rhs) { return collator.compare(mItems.get(lhs).toString(), mItems.get(rhs).toString()); } }); for (int i = 0; i < items.size(); i++) { sortedKeys.add(items.keyAt(i)); } return sortedKeys.toArray(new Long[sortedKeys.size()]); }
From source file:org.orekit.frames.FramesFactoryTest.java
@Test public void testEOPConversionSymetry2003() throws OrekitException { Utils.setDataRoot("rapid-data-columns"); IERSConventions.NutationCorrectionConverter converter = IERSConventions.IERS_2003 .getNutationCorrectionConverter(); final SortedSet<EOPEntry> rawNRO = new TreeSet<EOPEntry>(new ChronologicalComparator()); new RapidDataAndPredictionColumnsLoader(true, "^finals2000A\\.daily$").fillHistory(converter, rawNRO); Assert.assertEquals(181, rawNRO.size()); for (final EOPEntry entry : rawNRO) { final double[] rebuiltNRO = converter.toNonRotating(entry.getDate(), entry.getDdPsi(), entry.getDdEps());/*from ww w . j av a 2s.c o m*/ Assert.assertEquals(entry.getDx(), rebuiltNRO[0], 6.0e-23); Assert.assertEquals(entry.getDy(), rebuiltNRO[1], 2.0e-23); } }
From source file:org.jasig.ssp.service.impl.PersonServiceBulkCoachLookupIntegrationTest.java
@Test public void testGetAllCurrentCoachesLiteFiltersDuplicates() throws ObjectNotFoundException { final Person jamesDoe = person(JAMES_DOE); final Person advisor0 = person(ADVISOR_0); jamesDoe.setCoach(advisor0);/*from w w w. j ava 2s.c o m*/ personService.save(jamesDoe); sessionFactory.getCurrentSession().flush(); final SortedSet<CoachPersonLiteTO> result = personService.getAllCurrentCoachesLite(null); assertEquals(2, result.size()); }
From source file:com.hmsinc.epicenter.integrator.service.PatientService.java
private PatientDetail parseDetails(final HL7Message message, final Patient patient) throws HL7Exception { final Terser t = message.getTerser(); // Create new set of Details PatientDetail patientDetail = new PatientDetail(); patientDetail.setPatient(patient);//w w w .ja va2 s . com // Zipcode String zipcode = t.get("/PID-11-5"); try { if (zipcode == null) { throw new InvalidZipcodeException("No patient zipcode provided."); } patientDetail.setZipcode(zipcode); } catch (InvalidZipcodeException ize) { logger.error(ize.getMessage()); statisticsService.updateProviderStats(message, StatisticsService.StatsType.INCOMPLETE, "missing: " + IncompleteDataException.IncompleteDataType.ZIPCODE); } // Date of Birth final String dob = StringUtils.trimToNull(t.get("/PID-7")); if (dob == null) { logger.warn("No date of birth set in message"); } else { patientDetail.setDateOfBirth(ER7Utils.fromER7Date(dob)); } // Gender String genderAbbr = StringUtils.trimToNull(t.get("/PID-8")); if (genderAbbr == null) { genderAbbr = "U"; logger.warn("No gender set in message"); statisticsService.updateProviderStats(message, StatisticsService.StatsType.INCOMPLETE, "missing: " + IncompleteDataException.IncompleteDataType.GENDER); } patientDetail.setGender(attributeRepository.getGenderByAbbreviation(genderAbbr)); final SortedSet<PatientDetail> sortedDetails = patient.getPatientDetails(); if (patient.getPatientId() == null) { // Just save it. logger.debug("Saving details without patientID"); sortedDetails.add(patientDetail); } else if (sortedDetails.size() == 0) { // Just save it. logger.debug("Creating initial detail record"); sortedDetails.add(patientDetail); } else { final PatientDetail latestDetail = sortedDetails.last(); if (patientDetail.equals(latestDetail)) { patientDetail = latestDetail; logger.debug("Using existing detail record: {}", latestDetail.getId()); } else { logger.debug("Creating updated detail record"); logger.debug("Old: {} New: {}", latestDetail, patientDetail); sortedDetails.add(patientDetail); } } return patientDetail; }
From source file:org.eclipse.winery.repository.resources.AbstractComponentsResource.java
/** * Returns resources for all known component instances * /*from w w w. j a v a 2 s. c o m*/ * Required by topologytemplateedit.jsp */ public Collection<AbstractComponentInstanceResource> getAll() { Class<? extends TOSCAComponentId> idClass = Utils.getComponentIdClassForComponentContainer(this.getClass()); SortedSet<? extends TOSCAComponentId> allTOSCAcomponentIds = Repository.INSTANCE .getAllTOSCAComponentIds(idClass); ArrayList<AbstractComponentInstanceResource> res = new ArrayList<AbstractComponentInstanceResource>( allTOSCAcomponentIds.size()); for (TOSCAComponentId id : allTOSCAcomponentIds) { AbstractComponentInstanceResource r = AbstractComponentsResource.getComponentInstaceResource(id); res.add(r); } return res; }
From source file:mondrian.olap.IdBatchResolver.java
/** * Loops through the SortedSet of Ids, attempting to load sets of * children of parent Ids.//from w w w . j a v a2 s . co m * The loop below assumes the the SortedSet is ordered by segment * size from smallest to largest, such that parent identifiers will * occur before their children. */ private Map<QueryPart, QueryPart> resolveInParentGroupings(SortedSet<Id> identifiers) { final Map<QueryPart, QueryPart> resolvedIdentifiers = new HashMap<QueryPart, QueryPart>(); while (identifiers.size() > 0) { Id parent = identifiers.first(); identifiers.remove(parent); if (!supportedIdentifier(parent)) { continue; } Exp exp = (Exp) resolvedIdentifiers.get(parent); if (exp == null) { exp = lookupExp(resolvedIdentifiers, parent); } Member parentMember = getMemberFromExp(exp); if (!supportedMember(parentMember)) { continue; } batchResolveChildren(parent, parentMember, identifiers, resolvedIdentifiers); } return resolvedIdentifiers; }
From source file:org.jasig.ssp.service.impl.PersonServiceBulkCoachLookupIntegrationTest.java
@Test public void testGetAllCurrentCoachesLiteFiltersDuplicatesByIdNotName() throws ObjectNotFoundException { final String duplicatePersonSchoolId = ADVISOR_0.schoolId() + "_foo"; this.createExternalPerson(duplicatePersonSchoolId, ADVISOR_0.username() + "_foo", ADVISOR_0.firstName(), // everything else the same ADVISOR_0.lastName(), ADVISOR_0.middleName(), ADVISOR_0.primaryEmailAddress()); // this should create the person record Person duplicatePerson = personService.getBySchoolId(duplicatePersonSchoolId, true); assertNotNull(duplicatePerson); // sanity check final Person jamesDoe = person(JAMES_DOE); jamesDoe.setCoach(duplicatePerson);//from w w w. j a v a 2 s. c o m personService.save(jamesDoe); sessionFactory.getCurrentSession().flush(); final SortedSet<CoachPersonLiteTO> result = personService.getAllCurrentCoachesLite(null); assertEquals(3, result.size()); }
From source file:act.installer.HMDBParser.java
/** * Extract all chemicals from HMDB XML files that live in the specified directory and save them in the DB. * Note that this search is not recursive: documents in sub-directories will be ignored. * @param inputDir The directory to scan for HMDB XML files. * @throws IOException//ww w .j a va 2 s. com * @throws IllegalArgumentException */ public void run(File inputDir) throws IOException, IllegalArgumentException { if (inputDir == null || !inputDir.isDirectory()) { String msg = String.format("Unable to read input directory at %s", inputDir == null ? "null" : inputDir.getAbsolutePath()); LOGGER.error(msg); throw new RuntimeException(msg); } SortedSet<File> files = findHMDBFilesInDirectory(inputDir); LOGGER.info("Found %d HMDB XML files in directory %s", files.size(), inputDir.getAbsolutePath()); for (File file : files) { LOGGER.debug("Processing HMDB XML file %s", file.getAbsolutePath()); /* Promote our XML-specific exceptions to generic IllegalArgumentExceptions to reduce error handling surface * area for the caller. */ Document d; try { d = documentBuilder.parse(file); } catch (SAXException e) { String msg = String.format("Unable to parse XML file at %s: %s", file.getAbsolutePath(), e.getMessage()); throw new IllegalArgumentException(msg, e); } /* Jaxen doesn't throw exceptions if it can't find a path, so a JaxenException here is completely unexpected. * It might mean corrupted XML or some unrecoverable XPath problem that we don't expect. In any case, promote * the exception to the caller as it's unclear how we could deal with such an error here. */ Chemical chem; try { chem = extractChemicalFromXMLDocument(d); } catch (JaxenException e) { String msg = String.format("Unable to extract features from XML file at %s: %s", file.getAbsolutePath(), e.getMessage()); throw new IllegalArgumentException(msg, e); } // Not all HMDB entries contain if (chem == null) { LOGGER.warn("Unable to create chemical from file %s", file.getAbsolutePath()); continue; } // submitToActChemicalDB creates or merges as necessary. Long id = db.getNextAvailableChemicalDBid(); db.submitToActChemicalDB(chem, id); LOGGER.debug("Submitted chemical %d to the DB", id); } LOGGER.info("Loaded %d HMDB chemicals into DB", files.size()); }
From source file:org.apache.hive.ptest.execution.PTest.java
public int run() { int result = 0; boolean error = false; List<String> messages = Lists.newArrayList(); Map<String, Long> elapsedTimes = Maps.newTreeMap(); try {/*w w w . j a v a 2 s . c o m*/ mLogger.info("Running tests with " + mConfiguration); mLogger.info("Running tests with configuration context=[{}]", mConfiguration.getContext()); for (Phase phase : mPhases) { String msg = "Executing " + phase.getClass().getName(); mLogger.info(msg); messages.add(msg); long start = System.currentTimeMillis(); try { phase.execute(); } finally { long elapsedTime = TimeUnit.MINUTES.convert((System.currentTimeMillis() - start), TimeUnit.MILLISECONDS); elapsedTimes.put(phase.getClass().getSimpleName(), elapsedTime); } } if (!mFailedTests.isEmpty()) { throw new TestsFailedException(mFailedTests.size() + " tests failed"); } } catch (Throwable throwable) { mLogger.error("Test run exited with an unexpected error", throwable); // NonZeroExitCodeExceptions can have long messages and should be // trimmable when published to the JIRA via the JiraService if (throwable instanceof NonZeroExitCodeException) { messages.add("Tests exited with: " + throwable.getClass().getSimpleName()); for (String line : Strings.nullToEmpty(throwable.getMessage()).split("\n")) { messages.add(line); } } else { messages.add("Tests exited with: " + throwable.getClass().getSimpleName() + ": " + throwable.getMessage()); } error = true; } finally { for (HostExecutor hostExecutor : mHostExecutors) { hostExecutor.shutdownNow(); if (hostExecutor.isBad()) { mExecutionContext.addBadHost(hostExecutor.getHost()); } } mSshCommandExecutor.shutdownNow(); mRsyncCommandExecutor.shutdownNow(); mExecutor.shutdownNow(); SortedSet<String> failedTests = new TreeSet<String>(mFailedTests); if (failedTests.isEmpty()) { mLogger.info(String.format("%d failed tests", failedTests.size())); } else { mLogger.warn(String.format("%d failed tests", failedTests.size())); } for (String failingTestName : failedTests) { mLogger.warn(failingTestName); } mLogger.info("Executed " + mExecutedTests.size() + " tests"); for (Map.Entry<String, Long> entry : elapsedTimes.entrySet()) { mLogger.info(String.format("PERF: Phase %s took %d minutes", entry.getKey(), entry.getValue())); } publishJiraComment(error, messages, failedTests, mAddedTests); if (error || !mFailedTests.isEmpty()) { result = 1; } } return result; }