List of usage examples for java.text Collator getInstance
public static synchronized Collator getInstance()
From source file:dk.netarkivet.harvester.datamodel.HarvestDefinitionDBDAO.java
/** * Get a sorted list of all seeds of a Domain in a HarvestDefinition. * * @param harvestName//from w w w . jav a 2s.co m * of HarvestDefinition * @param domainName * of Domain * @return List of all seeds of the Domain in the HarvestDefinition. */ @Override public List<String> getListOfSeedsOfDomainOfHarvestDefinition(String harvestName, String domainName) { ArgumentNotValid.checkNotNullOrEmpty(harvestName, "harvestName"); ArgumentNotValid.checkNotNullOrEmpty(domainName, "domainName"); Connection c = HarvestDBConnection.get(); PreparedStatement s = null; try { s = c.prepareStatement("SELECT seedlists.seeds" + " FROM configurations," + " harvest_configs," + " harvestdefinitions," + " seedlists," + " config_seedlists," + " domains" + " WHERE config_seedlists.seedlist_id " + "= seedlists.seedlist_id" + " AND configurations.config_id " + "= config_seedlists.config_id" + " AND configurations.config_id " + "= harvest_configs.config_id" + " AND harvest_configs.harvest_id " + "= harvestdefinitions.harvest_id" + " AND configurations.domain_id = domains.domain_id" + " AND domains.name = ?" + " AND harvestdefinitions.name = ?"); s.setString(1, domainName); s.setString(2, harvestName); ResultSet res = s.executeQuery(); List<String> seeds = new ArrayList<String>(); while (res.next()) { String seedsOfDomain = res.getString(1); StringTokenizer st = new StringTokenizer(seedsOfDomain, "\n"); while (st.hasMoreTokens()) { String seed = st.nextToken(); boolean isDuplicate = false; for (String entry : seeds) { if (entry.equals(seed)) { isDuplicate = true; break; } } if (!isDuplicate) { // duplicates will not be added seeds.add(seed); } } } Collections.sort(seeds, Collator.getInstance()); return seeds; } catch (SQLException e) { throw new IOFailure( "SQL error getting seeds of a domain" + "\n" + ExceptionUtils.getSQLExceptionCause(e), e); } finally { DBUtils.closeStatementIfOpen(s); HarvestDBConnection.release(c); } }
From source file:com.marand.thinkmed.medications.business.impl.DefaultMedicationsBo.java
private void sortTherapiesByAdmissionLink(final List<SourceMedicationDto> therapies) { final Collator collator = Collator.getInstance(); Collections.sort(therapies, (o1, o2) -> { if (o1.getTherapy().isLinkedToAdmission() && !o2.getTherapy().isLinkedToAdmission()) { return -1; }/*www . j av a 2 s . co m*/ if (!o1.getTherapy().isLinkedToAdmission() && o2.getTherapy().isLinkedToAdmission()) { return 1; } return compareTherapiesForSort(o1.getTherapy(), o2.getTherapy(), collator); }); }
From source file:com.android.leanlauncher.LauncherModel.java
public static Comparator<AppInfo> getAppNameComparator() { final Collator collator = Collator.getInstance(); return new Comparator<AppInfo>() { public final int compare(AppInfo a, AppInfo b) { if (a.user.equals(b.user)) { int result = a.componentName.compareTo(b.componentName); if (a.title == null || b.title == null) { return result; }//from w ww . j a v a 2 s. c o m int titleCompareResult = collator.compare(a.title.toString().trim(), b.title.toString().trim()); if (titleCompareResult != 0) { result = titleCompareResult; } return result; } else { // TODO Need to figure out rules for sorting // profiles, this puts work second. return a.user.toString().compareTo(b.user.toString()); } } }; }
From source file:com.microsoft.tfs.core.clients.versioncontrol.engines.internal.GetEngine.java
/** * Reads the .tpattributes file from the directory that contains the given * localItemPath and stores a mapping between lower-cased file names and * attributes in this class instance's localDirectoryToAttributesMapCache. * * @param localItem// ww w . ja va 2 s .c om * a local file path, whose parent directory contains the * .tpattributes file to load (must not be <code>null</code> or * empty). */ private synchronized void ensureAttributesReadIntoCache(final String localItem) { Check.notNullOrEmpty(localItem, "localItem"); //$NON-NLS-1$ List<FileAttributesEntry> entries = null; /* * Check the cache for an existing list of attributes so we can skip * loading them from disk to save time. If an entry exists in the map * with a null value, this means there is no file attributes file to * load at that directory. If no entry exists at all, we should try to * load the file and update the map. */ final String localDirectory = LocalPath.getDirectory(localItem); if (localDirectoryToEntryListMap.containsKey(localDirectory) == true) { final List<FileAttributesEntry> value = localDirectoryToEntryListMap.get(localDirectory); /* * Null value means we have tried and failed to load the attributes * file for this directory, so there are no attributes to apply. */ if (value == null) { return; } entries = value; } else { /* * Try to load and update the cache. */ entries = FileAttributesFile .loadAttributesFile(localDirectory + File.separator + FileAttributesFile.DEFAULT_FILENAME); if (entries == null) { /* * Do not put null into the cache if the file we're getting is * the actual attributes file, because the next time we go * through here the file can be loaded. */ if (Collator.getInstance().equals(LocalPath.getFileName(localItem), FileAttributesFile.DEFAULT_FILENAME) == false) { localDirectoryToEntryListMap.put(localDirectory, null); } return; } /* * Update the cache with the new entries. */ localDirectoryToEntryListMap.put(localDirectory, entries); } }