List of usage examples for java.text Collator setStrength
public synchronized void setStrength(int newStrength)
From source file:Main.java
public static void main(String[] args) { Collator collator = Collator.getInstance(Locale.FRENCH); collator.setStrength(Collator.PRIMARY); if (collator.compare("d?b?rqu?r", "debarquer") == 0) { System.out.println("Both Strings are equal"); } else {/*from w w w . j av a2 s.com*/ System.out.println("Both Strings are not equal"); } }
From source file:Main.java
public static void main(String args[]) { String s1 = ""; String s2 = "f"; Collator frCollator = Collator.getInstance(Locale.FRANCE); frCollator.setStrength(Collator.CANONICAL_DECOMPOSITION); if (frCollator.compare(s1, s2) < 0) { System.out.println("s1 < s2"); }/*from ww w .j a va2s . c o m*/ }
From source file:org.fao.geonet.component.csw.GetDomain.java
public static List<Element> handlePropertyName(CatalogConfiguration catalogConfig, String[] propertyNames, ServiceContext context, boolean freq, int maxRecords, String cswServiceSpecificConstraint, LuceneConfig luceneConfig) throws Exception { List<Element> domainValuesList = new ArrayList<Element>(); if (Log.isDebugEnabled(Geonet.CSW)) Log.debug(Geonet.CSW, "Handling property names '" + Arrays.toString(propertyNames) + "' with max records of " + maxRecords); for (int i = 0; i < propertyNames.length; i++) { // Initialize list of values element. Element listOfValues = null; // Generate DomainValues element Element domainValues = new Element("DomainValues", Csw.NAMESPACE_CSW); // FIXME what should be the type ??? domainValues.setAttribute("type", "csw:Record"); String property = propertyNames[i].trim(); // Set propertyName in any case. Element pn = new Element("PropertyName", Csw.NAMESPACE_CSW); domainValues.addContent(pn.setText(property)); GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); SearchManager sm = gc.getBean(SearchManager.class); IndexAndTaxonomy indexAndTaxonomy = sm.getNewIndexReader(null); try {//from w w w . j ava2s .c o m GeonetworkMultiReader reader = indexAndTaxonomy.indexReader; BooleanQuery groupsQuery = (BooleanQuery) CatalogSearcher.getGroupsQuery(context); BooleanQuery query = null; // Apply CSW service specific constraint if (StringUtils.isNotEmpty(cswServiceSpecificConstraint)) { Query constraintQuery = CatalogSearcher .getCswServiceSpecificConstraintQuery(cswServiceSpecificConstraint, luceneConfig); query = new BooleanQuery(); BooleanClause.Occur occur = LuceneUtils.convertRequiredAndProhibitedToOccur(true, false); query.add(groupsQuery, occur); query.add(constraintQuery, occur); } else { query = groupsQuery; } List<Pair<String, Boolean>> sortFields = Collections .singletonList(Pair.read(Geonet.SearchResult.SortBy.RELEVANCE, true)); Sort sort = LuceneSearcher.makeSort(sortFields, context.getLanguage(), false); CachingWrapperFilter filter = null; Pair<TopDocs, Element> searchResults = LuceneSearcher.doSearchAndMakeSummary(maxRecords, 0, maxRecords, context.getLanguage(), null, luceneConfig, reader, query, filter, sort, null, false); TopDocs hits = searchResults.one(); try { // Get mapped lucene field in CSW configuration String indexField = catalogConfig.getFieldMapping().get(property.toLowerCase()); if (indexField != null) property = indexField; // check if params asked is in the index using getFieldNames ? @SuppressWarnings("resource") FieldInfos fi = SlowCompositeReaderWrapper.wrap(reader).getFieldInfos(); if (fi.fieldInfo(property) == null) continue; boolean isRange = false; if (catalogConfig.getGetRecordsRangeFields().contains(property)) isRange = true; if (isRange) listOfValues = new Element("RangeOfValues", Csw.NAMESPACE_CSW); else listOfValues = new Element("ListOfValues", Csw.NAMESPACE_CSW); Set<String> fields = new HashSet<String>(); fields.add(property); fields.add("_isTemplate"); // parse each document in the index String[] fieldValues; Collator stringCollator = Collator.getInstance(); stringCollator.setStrength(Collator.PRIMARY); SortedSet<String> sortedValues = new TreeSet<String>(stringCollator); ObjectKeyIntOpenHashMap duplicateValues = new ObjectKeyIntOpenHashMap(); for (int j = 0; j < hits.scoreDocs.length; j++) { DocumentStoredFieldVisitor selector = new DocumentStoredFieldVisitor(fields); reader.document(hits.scoreDocs[j].doc, selector); Document doc = selector.getDocument(); // Skip templates and subTemplates String[] isTemplate = doc.getValues("_isTemplate"); if (isTemplate[0] != null && !isTemplate[0].equals("n")) continue; // Get doc values for specified property fieldValues = doc.getValues(property); if (fieldValues == null) continue; addtoSortedSet(sortedValues, fieldValues, duplicateValues); } SummaryComparator valuesComparator = new SummaryComparator(SortOption.FREQUENCY, Type.STRING, context.getLanguage(), null); TreeSet<SummaryComparator.SummaryElement> sortedValuesFrequency = new TreeSet<SummaryComparator.SummaryElement>( valuesComparator); ObjectKeyIntMapIterator entries = duplicateValues.entries(); while (entries.hasNext()) { entries.next(); sortedValuesFrequency.add(new SummaryComparator.SummaryElement(entries)); } if (freq) return createValuesByFrequency(sortedValuesFrequency); else listOfValues.addContent(createValuesElement(sortedValues, isRange)); } finally { // any children means that the catalog was unable to determine // anything about the specified parameter if (listOfValues != null && listOfValues.getChildren().size() != 0) domainValues.addContent(listOfValues); // Add current DomainValues to the list domainValuesList.add(domainValues); } } finally { sm.releaseIndexReader(indexAndTaxonomy); } } return domainValuesList; }
From source file:Decomposition.java
public Decomposition() { String pairs[][] = new String[3][3]; pairs[0][0] = "Half-Width and full-width A"; pairs[0][1] = "A"; pairs[0][2] = "\uFF21"; // full-width A pairs[1][0] = "A with Ring and Angstrom Sign"; pairs[1][1] = "\u00c5"; // A with ring pairs[1][2] = "\u212b"; // Angstrom pairs[2][0] = "a + umlaut and precomposed a-umlaut"; pairs[2][1] = "a\u0308"; pairs[2][2] = "\u00e4"; for (int i = 0; i < 3; i++) { Collator collate = Collator.getInstance(Locale.US); collate.setStrength(Collator.IDENTICAL); System.out.println("Comparing " + pairs[i][0]); collate.setDecomposition(Collator.NO_DECOMPOSITION); compare(collate, pairs[i][1], pairs[i][2]); collate.setDecomposition(Collator.CANONICAL_DECOMPOSITION); compare(collate, pairs[i][1], pairs[i][2]); collate.setDecomposition(Collator.FULL_DECOMPOSITION); compare(collate, pairs[i][1], pairs[i][2]); System.out.println(""); }//from w ww. ja v a 2s. 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 . j a v a2s .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.trnltk.apps.experiments.TurkishCollatorPerformanceTest.java
@Test @Ignore// ww w.j av a2s.c om public void testCollatorPerformance() { final Collator collator = Collator.getInstance(Constants.TURKISH_LOCALE); collator.setStrength(Collator.PRIMARY); List<String> biggerList = getList(); System.out.println("Entry count : " + biggerList.size()); final StopWatch stopWatch = new StopWatch(); stopWatch.start(); Collections.sort(biggerList); stopWatch.stop(); System.out.println("w/o collator, it took " + stopWatch.toString()); biggerList = getList(); stopWatch.reset(); stopWatch.start(); Collections.sort(biggerList, collator); stopWatch.stop(); System.out.println("w/ collator, it took " + stopWatch.toString()); }
From source file:net.pms.dlna.RootFolder.java
private static boolean areNamesEqual(String aThis, String aThat) { Collator collator = Collator.getInstance(Locale.getDefault()); collator.setStrength(Collator.PRIMARY); int comparison = collator.compare(aThis, aThat); return (comparison == 0); }
From source file:net.felsing.client_cert.GetCountries.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final Locale defaultLanguage = Locale.ENGLISH; String bestLanguage = null;/* w ww .j a va2 s. com*/ resp.setContentType("application/json; charset=UTF-8"); resp.setCharacterEncoding("UTF-8"); final String acceptLanguage = StringEscapeUtils.escapeJava(req.getHeader("Accept-Language")); List<Locale.LanguageRange> languageRanges = Locale.LanguageRange.parse(acceptLanguage); for (Locale.LanguageRange l : languageRanges) { try { if (bestLanguage == null) { Locale locale = new Locale(l.getRange().split("-")[0]); bestLanguage = locale.getISO3Language(); logger.debug("bestLanguage: " + bestLanguage); usedLocale = locale; } } catch (Exception e) { // do nothing } } if (bestLanguage == null) { logger.debug("No sufficient language found for " + acceptLanguage); bestLanguage = defaultLanguage.getISO3Language(); usedLocale = Locale.ENGLISH; } logger.debug("usedLocale: " + usedLocale.getISO3Language()); PrintWriter pw = resp.getWriter(); loadFromJson(context); List<Country> countriesList = new ArrayList<>(); for (JsonElement jsonElement : countries) { String cca2 = jsonElement.getAsJsonObject().get("cca2").toString().replaceAll("\\\"", ""); cca2 = cca2.replaceAll("\\\\", ""); Country countryItem = new Country(); try { countryItem.name = jsonElement.getAsJsonObject().get("name").getAsJsonObject().get(bestLanguage) .getAsJsonObject().get("common").getAsString(); } catch (NullPointerException e) { countryItem.name = jsonElement.getAsJsonObject().get("name_").getAsString(); } countryItem.cca2 = cca2; countriesList.add(countryItem); } Collator coll = Collator.getInstance(usedLocale); coll.setStrength(Collator.PRIMARY); Collections.sort(countriesList); pw.print(new Gson().toJson(countriesList)); pw.flush(); }
From source file:org.eclipse.smarthome.io.rest.core.extensions.ExtensionResource.java
private Set<ExtensionType> getAllExtensionTypes(Locale locale) { final Collator coll = Collator.getInstance(locale); coll.setStrength(Collator.PRIMARY); Set<ExtensionType> ret = new TreeSet<>(new Comparator<ExtensionType>() { @Override// w w w . j ava2 s. co m public int compare(ExtensionType o1, ExtensionType o2) { return coll.compare(o1.getLabel(), o2.getLabel()); } }); for (ExtensionService extensionService : extensionServices) { ret.addAll(extensionService.getTypes(locale)); } return ret; }
From source file:io.gravitee.gateway.services.sync.SyncManager.java
private boolean hasMatchingTags(Api api) { final Optional<List<String>> optTagList = gatewayConfiguration.shardingTags(); if (optTagList.isPresent()) { List<String> tagList = optTagList.get(); if (api.getTags() != null) { final List<String> inclusionTags = tagList.stream().map(String::trim) .filter(tag -> !tag.startsWith("!")).collect(Collectors.toList()); final List<String> exclusionTags = tagList.stream().map(String::trim) .filter(tag -> tag.startsWith("!")).map(tag -> tag.substring(1)) .collect(Collectors.toList()); if (inclusionTags.stream().filter(exclusionTags::contains).count() > 0) { throw new IllegalArgumentException("You must not configure a tag to be included and excluded"); }/*w w w .ja va2s .co m*/ final boolean hasMatchingTags = inclusionTags.stream() .anyMatch(tag -> api.getTags().stream().anyMatch(apiTag -> { final Collator collator = Collator.getInstance(); collator.setStrength(Collator.NO_DECOMPOSITION); return collator.compare(tag, apiTag) == 0; })) || (!exclusionTags.isEmpty() && exclusionTags.stream() .noneMatch(tag -> api.getTags().stream().anyMatch(apiTag -> { final Collator collator = Collator.getInstance(); collator.setStrength(Collator.NO_DECOMPOSITION); return collator.compare(tag, apiTag) == 0; }))); if (!hasMatchingTags) { logger.info("The API {} has been ignored because not in configured tags {}", api.getName(), tagList); } return hasMatchingTags; } logger.info("Tags {} are configured on gateway instance but not found on the API {}", tagList, api.getName()); return false; } // no tags configured on this gateway instance return true; }