List of usage examples for java.util SortedSet size
int size();
From source file:org.geotools.coverage.io.netcdf.NetCDFPolyphemusTest.java
@Test public void geoToolsReader() throws IllegalArgumentException, IOException, NoSuchAuthorityCodeException { boolean isInteractiveTest = TestData.isInteractiveTest(); // create a base driver final DefaultFileDriver driver = new NetCDFDriver(); final File[] files = TestData.file(this, ".").listFiles(new FileFilter() { @Override// ww w . j a v a 2 s. co m public boolean accept(File pathname) { return FilenameUtils.getName(pathname.getAbsolutePath()).equalsIgnoreCase("O3-NO2.nc"); } }); for (File f : files) { // move to test directory final File file = new File(testDirectory, "O3-NO2.nc"); FileUtils.copyFile(f, file); // get the file final URL source = file.toURI().toURL(); assertTrue(driver.canProcess(DriverCapabilities.CONNECT, source, null)); LOGGER.info("ACCEPTED: " + source.toString()); // getting access to the file CoverageAccess access = null; try { access = driver.process(DriverCapabilities.CONNECT, source, null, null, null); if (access == null) { throw new IOException("Unable to connect"); } // get the names final List<Name> names = access.getNames(null); for (Name name : names) { // get a source final CoverageSource gridSource = access.access(name, null, AccessType.READ_ONLY, null, null); if (gridSource == null) { throw new IOException("Unable to access"); } LOGGER.info("Connected to coverage: " + name.toString()); // TEMPORAL DOMAIN final TemporalDomain temporalDomain = gridSource.getTemporalDomain(); if (temporalDomain == null) { LOGGER.info("Temporal domain is null"); } else { // temporal crs LOGGER.info("TemporalCRS: " + temporalDomain.getCoordinateReferenceSystem()); // print the temporal domain elements for (DateRange tg : temporalDomain.getTemporalElements(true, null)) { LOGGER.info("Global Temporal Domain: " + tg.toString()); } // print the temporal domain elements with overall = true StringBuilder overallTemporal = new StringBuilder( "Temporal domain element (overall = true):\n"); for (DateRange tg : temporalDomain.getTemporalElements(false, null)) { overallTemporal.append(tg.toString()).append("\n"); } LOGGER.info(overallTemporal.toString()); } // VERTICAL DOMAIN final VerticalDomain verticalDomain = gridSource.getVerticalDomain(); if (verticalDomain == null) { LOGGER.info("Vertical domain is null"); } else { // vertical crs LOGGER.info("VerticalCRS: " + verticalDomain.getCoordinateReferenceSystem()); // print the Vertical domain elements for (NumberRange<Double> vg : verticalDomain.getVerticalElements(true, null)) { LOGGER.info("Vertical domain element: " + vg.toString()); } // print the Vertical domain elements with overall = true StringBuilder overallVertical = new StringBuilder( "Vertical domain element (overall = true):\n"); for (NumberRange<Double> vg : verticalDomain.getVerticalElements(false, null)) { overallVertical.append(vg.toString()).append("\n"); } LOGGER.info(overallVertical.toString()); } // HORIZONTAL DOMAIN final SpatialDomain spatialDomain = gridSource.getSpatialDomain(); if (spatialDomain == null) { LOGGER.info("Horizontal domain is null"); } else { // print the horizontal domain elements final CoordinateReferenceSystem crs2D = spatialDomain.getCoordinateReferenceSystem2D(); assert crs2D != null; final MathTransform2D g2w = spatialDomain.getGridToWorldTransform(null); assert g2w != null; final Set<? extends BoundingBox> spatialElements = spatialDomain.getSpatialElements(true, null); assert spatialElements != null && !spatialElements.isEmpty(); final StringBuilder buf = new StringBuilder(); buf.append("Horizontal domain is as follows:\n"); buf.append("G2W:").append("\t").append(g2w).append("\n"); buf.append("CRS2D:").append("\t").append(crs2D).append("\n"); for (BoundingBox bbox : spatialElements) { buf.append("BBOX:").append("\t").append(bbox).append("\n"); } LOGGER.info(buf.toString()); } CoverageReadRequest readRequest = new CoverageReadRequest(); // // // // Setting up a limited range for the request. // // // LinkedHashSet<NumberRange<Double>> requestedVerticalSubset = new LinkedHashSet<NumberRange<Double>>(); SortedSet<? extends NumberRange<Double>> verticalElements = verticalDomain .getVerticalElements(false, null); final int numLevels = verticalElements.size(); final Iterator<? extends NumberRange<Double>> iterator = verticalElements.iterator(); for (int i = 0; i < numLevels; i++) { NumberRange<Double> level = iterator.next(); if (i % (numLevels / 5) == 1) { requestedVerticalSubset.add(level); } } readRequest.setVerticalSubset(requestedVerticalSubset); SortedSet<DateRange> requestedTemporalSubset = new DateRangeTreeSet(); SortedSet<? extends DateRange> temporalElements = temporalDomain.getTemporalElements(false, null); final int numTimes = temporalElements.size(); Iterator<? extends DateRange> iteratorT = temporalElements.iterator(); for (int i = 0; i < numTimes; i++) { DateRange time = iteratorT.next(); if (i % (numTimes / 5) == 1) { requestedTemporalSubset.add(time); } } readRequest.setTemporalSubset(requestedTemporalSubset); CoverageResponse response = gridSource.read(readRequest, null); if (response == null || response.getStatus() != Status.SUCCESS || !response.getExceptions().isEmpty()) { throw new IOException("Unable to read"); } final Collection<? extends Coverage> results = response.getResults(null); int index = 0; for (Coverage c : results) { GridCoverageResponse resp = (GridCoverageResponse) c; GridCoverage2D coverage = resp.getGridCoverage2D(); String title = coverage.getSampleDimension(0).getDescription().toString(); // Crs and envelope if (isInteractiveTest) { // ImageIOUtilities.visualize(coverage.getRenderedImage(), "tt",true); coverage.show(title + " " + index++); } else { PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles(); } final StringBuilder buffer = new StringBuilder(); buffer.append("GridCoverage CRS: ") .append(coverage.getCoordinateReferenceSystem2D().toWKT()).append("\n"); buffer.append("GridCoverage GG: ").append(coverage.getGridGeometry().toString()) .append("\n"); LOGGER.info(buffer.toString()); } gridSource.dispose(); } } catch (Throwable t) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, t.getLocalizedMessage(), t); } } finally { if (access != null) { try { access.dispose(); } catch (Throwable t) { // Does nothing } } } } }
From source file:ca.travelagency.components.fields.TravelDocumentField.java
@Override protected Iterator<String> getChoices(String input) { if (StringUtils.isEmpty(input)) { return Collections.<String>emptyList().iterator(); }//w w w. j a v a2s. co m SortedSet<String> choices = new TreeSet<String>(); Locale[] locales = Locale.getAvailableLocales(); for (Locale locale : locales) { String country = locale.getDisplayCountry().toUpperCase(); if (country.startsWith(input.toUpperCase())) { String value = getLocalizer().getString(country, this, country); if (StringUtils.isBlank(value)) { value = country; } choices.add(WordUtils.capitalize(StringUtils.lowerCase(value + " " + suffix))); if (choices.size() == DISPLAY_MAX_SIZE) { break; } } } return choices.iterator(); }
From source file:org.kuali.kfs.coa.businessobject.OrganizationReversionGlobalDetail.java
/** * This returns a string of object code names associated with the object code in this org rev change detail. * //from w w w . ja va 2s .c o m * @return String of distinct object code names */ public String getObjectCodeNames() { String objectCodeNames = ""; if (!StringUtils.isBlank(this.getOrganizationReversionObjectCode())) { if (this.getParentGlobalOrganizationReversion().getUniversityFiscalYear() != null && this.getParentGlobalOrganizationReversion() .getOrganizationReversionGlobalOrganizations() != null && this.getParentGlobalOrganizationReversion().getOrganizationReversionGlobalOrganizations() .size() > 0) { // find distinct chart of account codes SortedSet<String> chartCodes = new TreeSet<String>(); for (OrganizationReversionGlobalOrganization org : this.getParentGlobalOrganizationReversion() .getOrganizationReversionGlobalOrganizations()) { chartCodes.add(org.getChartOfAccountsCode()); } String[] chartCodesArray = new String[chartCodes.size()]; int i = 0; for (String chartCode : chartCodes) { chartCodesArray[i] = chartCode; i++; } objectCodeNames = (String) SpringContext.getBean(ObjectCodeService.class) .getObjectCodeNamesByCharts( this.getParentGlobalOrganizationReversion().getUniversityFiscalYear(), chartCodesArray, this.getOrganizationReversionObjectCode()); } } return objectCodeNames; }
From source file:org.mitre.mpf.mst.TestSystemNightly.java
/** * For a given media item, compare the number of tracks from the default pipeline and the custom pipeline * * @param defaultMedia//from w ww . java2 s .c om * @param customMedia */ private void compareMedia(JsonMediaOutputObject defaultMedia, JsonMediaOutputObject customMedia) { Map<String, SortedSet<JsonTrackOutputObject>> defaultTracks = defaultMedia.getTracks(); Map<String, SortedSet<JsonTrackOutputObject>> customTracks = customMedia.getTracks(); Iterator<Map.Entry<String, SortedSet<JsonTrackOutputObject>>> defaultEntries = defaultTracks.entrySet() .iterator(); Iterator<Map.Entry<String, SortedSet<JsonTrackOutputObject>>> customEntries = customTracks.entrySet() .iterator(); Assert.assertEquals( String.format("Default track entries size=%d doesn't match custom track entries size=%d", defaultTracks.size(), customTracks.size()), defaultTracks.size(), customTracks.size()); while (customEntries.hasNext()) { SortedSet<JsonTrackOutputObject> cusTrackSet = customEntries.next().getValue(); SortedSet<JsonTrackOutputObject> defTrackSet = defaultEntries.next().getValue(); int cusTrackSetSize = cusTrackSet.size(); int defTrackSetSize = defTrackSet.size(); log.debug("custom number of tracks={}", cusTrackSetSize); log.debug("default number of tracks={}", defTrackSetSize); Assert.assertTrue( String.format("Custom number of tracks=%d is not less than default number of tracks=%d", cusTrackSetSize, defTrackSetSize), cusTrackSetSize < defTrackSetSize); } }
From source file:se.jguru.nazgul.tools.codestyle.enforcer.rules.CorrectPackagingRule.java
/** * Delegate method, implemented by concrete subclasses. * * @param project The active MavenProject. * @param helper The EnforcerRuleHelper instance, from which the MavenProject has been retrieved. * @throws RuleFailureException If the enforcer rule was not satisfied. *//*w w w .j a v a2 s . co m*/ @Override @SuppressWarnings("unchecked") protected void performValidation(final MavenProject project, final EnforcerRuleHelper helper) throws RuleFailureException { // Find all java source files, and map their packages to their names. final List<String> compileSourceRoots = (List<String>) project.getCompileSourceRoots(); if (compileSourceRoots.size() == 0) { return; } final SortedMap<String, SortedSet<String>> packageName2SourceFileNameMap = new TreeMap<String, SortedSet<String>>(); for (String current : compileSourceRoots) { addPackages(new File(current), packageName2SourceFileNameMap); } // Retrieve the groupId of this project final String groupId = project.getGroupId(); if (groupId == null || groupId.equals("")) { // Don't accept empty groupIds throw new RuleFailureException("Maven groupId cannot be null or empty.", project.getArtifact()); } else { // Correct packaging everywhere? final SortedSet<String> incorrectPackages = new TreeSet<String>(); for (Map.Entry<String, SortedSet<String>> currentPackage : packageName2SourceFileNameMap.entrySet()) { final String candidate = currentPackage.getKey(); if (!candidate.startsWith(groupId)) { incorrectPackages.add(candidate); } } if (incorrectPackages.size() > 0) { final SortedMap<String, SortedSet<String>> result = new TreeMap<String, SortedSet<String>>(); for (String current : incorrectPackages) { result.put(current, packageName2SourceFileNameMap.get(current)); } throw new RuleFailureException("Incorrect packaging detected; required [" + groupId + "] but found package to file names: " + result, project.getArtifact()); } } }
From source file:ubic.gemma.loader.expression.geo.GeoSampleCorrespondence.java
@Override public String toString() { StringBuffer buf = new StringBuffer(); StringBuffer singletons = new StringBuffer(); SortedSet<String> groupStrings = new TreeSet<String>(); for (Set<String> set : sets) { String group = ""; SortedSet<String> sortedSet = new TreeSet<String>(set); for (String accession : sortedSet) { group = group + accession + " ('" + (accToTitle != null && accToTitle.containsKey(accession) ? accToTitle.get(accession) : "[no title]") + "'" + (accToDataset != null ? (" in " + accToDataset.get(accession)) : "") + ")"; if (sortedSet.size() == 1) { singletons.append(group + "\n"); group = group + (" - singleton"); } else { group = group + ("\t<==>\t"); }/* w w w. ja va 2 s. c o m*/ } group = group + "\n"; groupStrings.add(group); } for (String string : groupStrings) { buf.append(string); } return buf.toString().replaceAll("\\t<==>\\t\\n", "\n") + (singletons.length() > 0 ? "\nSingletons:\n" + singletons.toString() : ""); }
From source file:uk.ac.ebi.atlas.search.baseline.BaselineExperimentAssayGroupSearchService.java
public SortedSet<BaselineExperimentAssayGroup> query(Set<String> geneIds, Optional<String> condition, Optional<String> species) { LOGGER.info(String.format("<query> geneIds=%s, condition=%s", Joiner.on(", ").join(geneIds), condition)); StopWatch stopWatch = new StopWatch(getClass().getSimpleName()); stopWatch.start();/*from www. j a v a 2 s . com*/ String conditionString = condition.isPresent() ? condition.get() : ""; String speciesString = species.isPresent() ? species.get() : ""; Optional<ImmutableSet<IndexedAssayGroup>> indexedAssayGroups = fetchAssayGroupsForCondition( conditionString); SetMultimap<String, String> assayGroupsWithExpressionByExperiment = baselineExperimentAssayGroupsDao .fetchExperimentAssayGroupsWithNonSpecificExpression(indexedAssayGroups, Optional.of(geneIds)); SortedSet<BaselineExperimentAssayGroup> baselineExperimentAssayGroups = searchedForConditionButGotNoResults( conditionString, indexedAssayGroups) ? emptySortedSet() : buildResults(assayGroupsWithExpressionByExperiment, !StringUtils.isBlank(conditionString), speciesString); stopWatch.stop(); LOGGER.info(String.format("<query> %s results, took %s seconds", baselineExperimentAssayGroups.size(), stopWatch.getTotalTimeSeconds())); return baselineExperimentAssayGroups; }
From source file:org.jclouds.rackspace.cloudfiles.CloudFilesClientLiveTest.java
@Test public void testPutContainers() throws Exception { String containerName = getContainerName(); try {/*from ww w . ja v a 2 s. c o m*/ String containerName1 = containerName + ".hello"; assertTrue(context.getApi().createContainer(containerName1)); // List only the container just created, using a marker with the container name less 1 char SortedSet<ContainerMetadata> response = context.getApi().listContainers(ListContainerOptions.Builder .afterMarker(containerName1.substring(0, containerName1.length() - 1)).maxResults(1)); assertNotNull(response); assertEquals(response.size(), 1); assertEquals(response.first().getName(), containerName + ".hello"); String containerName2 = containerName + "?should-be-illegal-question-char"; assert context.getApi().createContainer(containerName2); // TODO: Should throw a specific exception, not UndeclaredThrowableException try { context.getApi().createContainer(containerName + "/illegal-slash-char"); fail("Should not be able to create container with illegal '/' character"); } catch (Exception e) { } assertTrue(context.getApi().deleteContainerIfEmpty(containerName1)); assertTrue(context.getApi().deleteContainerIfEmpty(containerName2)); } finally { returnContainer(containerName); } }
From source file:org.openmrs.module.privilegehelper.web.controller.PrivilegeAssignerController.java
@RequestMapping(value = "/assignRoles", method = RequestMethod.GET) public void assignRoles(@ModelAttribute(PRIVILEGES) final SortedSet<PrivilegeLogEntry> privileges, @ModelAttribute(MISSING_PRIVILEGES) final SortedSet<PrivilegeLogEntry> missingPrivileges, final User user, final ModelMap model) { Map<PrivilegeLogEntry, Boolean[]> rolesByPrivileges = new TreeMap<PrivilegeLogEntry, Boolean[]>(); SortedSet<Role> userRoles = new TreeSet<Role>(new Comparator<Role>() { @Override//w w w . j a v a 2 s. c o m public int compare(Role o1, Role o2) { return o1.getName().compareTo(o2.getName()); } }); userRoles.addAll(user.getAllRoles()); for (PrivilegeLogEntry privilege : privileges) { Boolean[] roles = new Boolean[userRoles.size()]; int i = 0; for (Role role : userRoles) { roles[i++] = !role.hasPrivilege(privilege.getPrivilege()); } if (privilege.isRequired()) { //Remove not required privilege if there's a required one. rolesByPrivileges.remove(new PrivilegeLogEntry(user.getUserId(), privilege.getPrivilege(), false, !user.hasPrivilege(privilege.getPrivilege()))); rolesByPrivileges.put(new PrivilegeLogEntry(user.getUserId(), privilege.getPrivilege(), privilege.isRequired(), !user.hasPrivilege(privilege.getPrivilege())), roles); } else { //Add not required privilege only if there's no required one. if (!rolesByPrivileges.containsKey(new PrivilegeLogEntry(user.getUserId(), privilege.getPrivilege(), true, !user.hasPrivilege(privilege.getPrivilege())))) { rolesByPrivileges.put(new PrivilegeLogEntry(user.getUserId(), privilege.getPrivilege(), privilege.isRequired(), !user.hasPrivilege(privilege.getPrivilege())), roles); } } } SortedSet<String> roles = new TreeSet<String>(); for (Role role : userRoles) { roles.add(role.getName()); } model.addAttribute("roles", roles); model.addAttribute("rolesByPrivileges", rolesByPrivileges); model.addAttribute("user", user); }
From source file:uk.ac.ebi.atlas.search.baseline.BaselineExperimentAssayGroupSearchService.java
@Deprecated public SortedSet<BaselineExperimentAssayGroup> query(String geneQuery, String condition, String specie, boolean isExactMatch) { LOGGER.info(String.format("<query> geneQuery=%s, condition=%s", geneQuery, condition)); StopWatch stopWatch = new StopWatch(getClass().getSimpleName()); stopWatch.start();//from ww w . j ava 2 s. c o m Optional<ImmutableSet<IndexedAssayGroup>> indexedAssayGroups = fetchAssayGroupsForCondition(condition); String species = StringUtils.isNotBlank(specie) ? specie : ""; //TODO: move outside into caller, because this is called twice, here and in DiffAnalyticsSearchService Optional<Set<String>> geneIds = solrQueryService.expandGeneQueryIntoGeneIds(geneQuery, species, isExactMatch); SetMultimap<String, String> assayGroupsWithExpressionByExperiment = baselineExperimentAssayGroupsDao .fetchExperimentAssayGroupsWithNonSpecificExpression(indexedAssayGroups, geneIds); boolean conditionSearch = !isEmpty(indexedAssayGroups); SortedSet<BaselineExperimentAssayGroup> baselineExperimentAssayGroups = Sets.newTreeSet(); if (conditionSearch || StringUtils.isNotEmpty(geneQuery) && StringUtils.isEmpty(condition)) { baselineExperimentAssayGroups = buildResults(assayGroupsWithExpressionByExperiment, conditionSearch, species); } stopWatch.stop(); LOGGER.info(String.format("<query> %s results, took %s seconds", baselineExperimentAssayGroups.size(), stopWatch.getTotalTimeSeconds())); return baselineExperimentAssayGroups; }