List of usage examples for java.text Collator setStrength
public synchronized void setStrength(int newStrength)
From source file:com.evolveum.midpoint.web.component.prism.ContainerValueWrapper.java
public void sort() { Locale locale = WebModelServiceUtils.getLocale(); if (locale == null) { locale = Locale.getDefault(); }//from ww w . ja v a 2 s. co m Collator collator = Collator.getInstance(locale); if (isSorted()) { collator.setStrength(Collator.SECONDARY); // e.g. "a" should be different from "" collator.setDecomposition(Collator.FULL_DECOMPOSITION); // slower but more precise Collections.sort(properties, new Comparator<ItemWrapper>() { @Override public int compare(ItemWrapper pw1, ItemWrapper pw2) { if (pw1 instanceof ContainerWrapper) { ((ContainerWrapper) pw1).sort(); } if (pw2 instanceof ContainerWrapper) { ((ContainerWrapper) pw2).sort(); } if (PropertyOrReferenceWrapper.class.isAssignableFrom(pw1.getClass()) && pw2 instanceof ContainerWrapper) { return -1; } if (PropertyOrReferenceWrapper.class.isAssignableFrom(pw2.getClass()) && pw1 instanceof ContainerWrapper) { return 1; } // return compareByDisplayNames(pw1, pw2, collator); } }); } else { Collections.sort(properties, new Comparator<ItemWrapper>() { @Override public int compare(ItemWrapper pw1, ItemWrapper pw2) { if (pw1 instanceof ContainerWrapper) { ((ContainerWrapper) pw1).sort(); } if (pw2 instanceof ContainerWrapper) { ((ContainerWrapper) pw2).sort(); } if (PropertyOrReferenceWrapper.class.isAssignableFrom(pw1.getClass()) && pw2 instanceof ContainerWrapper) { return -1; } if (PropertyOrReferenceWrapper.class.isAssignableFrom(pw2.getClass()) && pw1 instanceof ContainerWrapper) { return 1; } ItemDefinition id1 = pw1.getItemDefinition(); ItemDefinition id2 = pw2.getItemDefinition(); int displayOrder1 = (id1 == null || id1.getDisplayOrder() == null) ? Integer.MAX_VALUE : id1.getDisplayOrder(); int displayOrder2 = (id2 == null || id2.getDisplayOrder() == null) ? Integer.MAX_VALUE : id2.getDisplayOrder(); if (displayOrder1 == displayOrder2) { return compareByDisplayNames(pw1, pw2, collator); } else { return Integer.compare(displayOrder1, displayOrder2); } } }); } }
From source file:org.apache.solr.schema.CollationField.java
/** * Setup the field according to the provided parameters *///from www. ja va 2 s .c om private void setup(ResourceLoader loader, Map<String, String> args) { String custom = args.remove("custom"); String language = args.remove("language"); String country = args.remove("country"); String variant = args.remove("variant"); String strength = args.remove("strength"); String decomposition = args.remove("decomposition"); final Collator collator; if (custom == null && language == null) throw new SolrException(ErrorCode.SERVER_ERROR, "Either custom or language is required."); if (custom != null && (language != null || country != null || variant != null)) throw new SolrException(ErrorCode.SERVER_ERROR, "Cannot specify both language and custom. " + "To tailor rules for a built-in language, see the javadocs for RuleBasedCollator. " + "Then save the entire customized ruleset to a file, and use with the custom parameter"); if (language != null) { // create from a system collator, based on Locale. collator = createFromLocale(language, country, variant); } else { // create from a custom ruleset collator = createFromRules(custom, loader); } // set the strength flag, otherwise it will be the default. if (strength != null) { if (strength.equalsIgnoreCase("primary")) collator.setStrength(Collator.PRIMARY); else if (strength.equalsIgnoreCase("secondary")) collator.setStrength(Collator.SECONDARY); else if (strength.equalsIgnoreCase("tertiary")) collator.setStrength(Collator.TERTIARY); else if (strength.equalsIgnoreCase("identical")) collator.setStrength(Collator.IDENTICAL); else throw new SolrException(ErrorCode.SERVER_ERROR, "Invalid strength: " + strength); } // set the decomposition flag, otherwise it will be the default. if (decomposition != null) { if (decomposition.equalsIgnoreCase("no")) collator.setDecomposition(Collator.NO_DECOMPOSITION); else if (decomposition.equalsIgnoreCase("canonical")) collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION); else if (decomposition.equalsIgnoreCase("full")) collator.setDecomposition(Collator.FULL_DECOMPOSITION); else throw new SolrException(ErrorCode.SERVER_ERROR, "Invalid decomposition: " + decomposition); } analyzer = new CollationKeyAnalyzer(collator); }
From source file:fr.gouv.culture.thesaurus.service.impl.SesameThesaurus.java
/** {@inheritDoc} */ @Override/* w ww .j av a2s .co m*/ public Collection<String> listConceptSchemesProducers(Locale locale) throws BusinessException { List<String> producers = new ArrayList<String>(); RepositoryConnection cnx = null; try { cnx = this.repository.getConnection(); TupleQuery query = getSelectQuery(SparqlQueries.ListConceptSchemesProducers.QUERY, cnx); TupleQueryResult rs = query.evaluate(); BindingSet result; while (rs.hasNext()) { result = rs.next(); producers.add(this.getValue("organisationName", result)); } } catch (OpenRDFException e) { throw new BusinessException(ErrorMessage.SPARQL_CONSTRUCT_FAILED, new Object[] { e.getMessage() }, e); } finally { if (cnx != null) { try { cnx.close(); } catch (Exception e) { /* Ignore... */ } } } Collator collator = Collator.getInstance(locale); collator.setStrength(Collator.PRIMARY); Collections.sort(producers, collator); if (log.isDebugEnabled()) { log.debug("listConceptSchemesProducers: " + producers); } return producers; }
From source file:fr.gouv.culture.thesaurus.service.impl.SesameThesaurus.java
/** {@inheritDoc} */ @Override//from w w w . jav a 2 s .co m public Collection<String> listConceptSchemesSubjects(Locale locale) throws BusinessException { List<String> subjects = new ArrayList<String>(); RepositoryConnection cnx = null; try { cnx = this.repository.getConnection(); TupleQuery query = getSelectQuery(SparqlQueries.ListConceptSchemesSubjects.QUERY, cnx); TupleQueryResult rs = query.evaluate(); BindingSet result; while (rs.hasNext()) { result = rs.next(); String subject = this.getValue("subject", result); if (StringUtils.isNotBlank(subject)) { subjects.add(subject); } } } catch (OpenRDFException e) { throw new BusinessException(ErrorMessage.SPARQL_CONSTRUCT_FAILED, new Object[] { e.getMessage() }, e); } finally { if (cnx != null) { try { cnx.close(); } catch (Exception e) { /* Ignore... */ } } } Collator collator = Collator.getInstance(locale); collator.setStrength(Collator.PRIMARY); Collections.sort(subjects, collator); if (log.isDebugEnabled()) { log.debug("listConceptSchemesSubjects: " + subjects); } return subjects; }
From source file:org.jahia.services.search.facets.SimpleJahiaJcrFacets.java
private NamedList<Object> sortValuesAfterChoiceListRenderer(NamedList<Object> values, ChoiceListRenderer renderer, ExtendedPropertyDefinition fieldPropertyType, Locale locale) { try {// w w w . j a v a 2 s.com //use case-insensitive and locale aware collator Collator collator = Collator.getInstance(locale); collator.setStrength(Collator.TERTIARY); Map<String, Integer> sortedLabels = new TreeMap<>(collator); int i = 0; boolean resolveReference = renderer instanceof NodeReferenceChoiceListRenderer ? true : false; JCRSessionWrapper currentUserSession = resolveReference ? JCRSessionFactory.getInstance().getCurrentUserSession(session.getWorkspace().getName(), locale) : null; for (Map.Entry<String, Object> facetValueEntry : values) { String facetValueKey = facetValueEntry.getKey(); sortedLabels.put(renderer.getStringRendering(locale, fieldPropertyType, resolveReference ? currentUserSession .getNode(StringUtils.substring(facetValueKey, facetValueKey.indexOf('/'))) : facetValueKey), i++); } NamedList<Object> sortedValues = new NamedList<>(); for (Integer index : sortedLabels.values()) { sortedValues.add(values.getName(index), values.getVal(index)); } return sortedValues; } catch (RepositoryException | UnsupportedOperationException e) { logger.warn("Exception while sorting label rendered facet values, fallback to default sorting", e); return values; } }
From source file:nz.ac.otago.psyanlab.common.designer.ExperimentDesignerActivity.java
Collator getCollater() { Locale locale = Locale.getDefault(); Collator collator = Collator.getInstance(locale); collator.setStrength(Collator.SECONDARY); return collator; }