List of usage examples for java.text Collator compare
@Override public int compare(Object o1, Object o2)
From source file:org.sakaiproject.sitestats.tool.wicket.pages.ReportsEditPage.java
public static final Comparator<String> getStringComparator(final Collator collator) { return new Comparator<String>() { public int compare(String o1, String o2) { return collator.compare(o1, o2); }// w w w. j a v a 2 s . c o m }; }
From source file:org.sakaiproject.sitestats.tool.wicket.pages.ReportsEditPage.java
public static final Comparator<Object> getOptionRendererComparator(final Collator collator, final IOptionRenderer renderer) { return new Comparator<Object>() { public int compare(Object o1, Object o2) { return collator.compare(renderer.getDisplayValue(o1), renderer.getDisplayValue(o2)); }//from w ww .j a va2s. c o m }; }
From source file:org.sakaiproject.sitestats.tool.wicket.pages.ReportsEditPage.java
public static final Comparator<Object> getChoiceRendererComparator(final Collator collator, final IChoiceRenderer renderer) { return new Comparator<Object>() { public int compare(Object o1, Object o2) { return collator.compare(renderer.getDisplayValue(o1), renderer.getDisplayValue(o2)); }/*from w w w. ja va2 s.co m*/ }; }
From source file:com.couchbase.lite.CollationTest.java
public void testCollateJapaneseStrings() { int mode = kJsonCollator_Unicode; // en_US/*from w w w. j a v a 2 s .c om*/ Collator c = Collator.getInstance(new Locale("en_US")); Assert.assertEquals(-1, SQLiteJsonCollator.testCollate(mode, encode("?"), encode("?"))); Assert.assertEquals(1, SQLiteJsonCollator.testCollate(mode, encode("?"), encode("?"))); Assert.assertEquals(0, SQLiteJsonCollator.testCollate(mode, encode("?"), encode("?"))); Assert.assertEquals(c.compare("", ""), SQLiteJsonCollator.testCollate(mode, encode(""), encode(""))); Assert.assertEquals(c.compare("?", ""), SQLiteJsonCollator.testCollate(mode, encode("?"), encode(""))); Assert.assertEquals(c.compare("?", ""), SQLiteJsonCollator.testCollate(mode, encode("?"), encode(""))); Assert.assertEquals(c.compare("", ""), SQLiteJsonCollator.testCollate(mode, encode(""), encode(""))); Assert.assertEquals(c.compare("", "?"), SQLiteJsonCollator.testCollate(mode, encode(""), encode("?"))); Assert.assertEquals(c.compare("", "?"), SQLiteJsonCollator.testCollate(mode, encode(""), encode("?"))); Assert.assertEquals(c.compare("", ""), SQLiteJsonCollator.testCollate(mode, encode(""), encode(""))); // ja Locale locale = new Locale("ja"); String localeStr = locale.toString(); Collator c1 = Collator.getInstance(locale); Assert.assertEquals(-1, SQLiteJsonCollator.testCollate(mode, localeStr, encode("?"), encode("?"))); Assert.assertEquals(1, SQLiteJsonCollator.testCollate(mode, localeStr, encode("?"), encode("?"))); Assert.assertEquals(0, SQLiteJsonCollator.testCollate(mode, localeStr, encode("?"), encode("?"))); Assert.assertEquals(c1.compare("", ""), SQLiteJsonCollator.testCollate(mode, localeStr, encode(""), encode(""))); Assert.assertEquals(c1.compare("?", ""), SQLiteJsonCollator.testCollate(mode, localeStr, encode("?"), encode(""))); Assert.assertEquals(c1.compare("?", ""), SQLiteJsonCollator.testCollate(mode, localeStr, encode("?"), encode(""))); Assert.assertEquals(c1.compare("", ""), SQLiteJsonCollator.testCollate(mode, localeStr, encode(""), encode(""))); Assert.assertEquals(c1.compare("", "?"), SQLiteJsonCollator.testCollate(mode, localeStr, encode(""), encode("?"))); Assert.assertEquals(c1.compare("", "?"), SQLiteJsonCollator.testCollate(mode, localeStr, encode(""), encode("?"))); Assert.assertEquals(c1.compare("", ""), SQLiteJsonCollator.testCollate(mode, localeStr, encode(""), encode(""))); }
From source file:pcgen.gui2.facade.TempBonusFacadeImpl.java
@Override public int compareTo(TempBonusFacadeImpl o) { final Collator collator = Collator.getInstance(); // Check sort keys first String key1 = this.getOriginObj().get(StringKey.SORT_KEY); if (key1 == null) { key1 = this.getOriginObj().getDisplayName(); }/*from w w w . j a v a 2 s. co m*/ String key2 = o.getOriginObj().get(StringKey.SORT_KEY); if (key2 == null) { key2 = o.getOriginObj().getDisplayName(); } if (!key1.equals(key2)) { return collator.compare(key1, key2); } return collator.compare(this.getOriginObj().getDisplayName(), o.getOriginObj().getDisplayName()); }
From source file:edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty.java
/** * Sorts alphabetically by public name/*from ww w . j a va 2s. c o m*/ */ public int compareTo(ObjectProperty op) { Collator collator = Collator.getInstance(); return collator.compare(this.getDomainPublic(), (op).getDomainPublic()); }
From source file:org.kuali.kfs.sys.DynamicCollectionComparatorTest.java
private <T> boolean isSortedByDescendingOrder(List<T> objectList, String fieldName) throws Exception { Collator collator = Collator.getInstance(); Object tempValue = null;/* w w w . ja v a 2s.c om*/ int count = 0; for (T object : objectList) { Object fieldValue = PropertyUtils.getProperty(object, fieldName); if (count == 0) { tempValue = fieldValue; count++; } else if (tempValue == null && fieldValue == null) { tempValue = fieldValue; } else if (tempValue == null) { return false; } else if (fieldValue == null) { tempValue = fieldValue; } else if (collator.compare(tempValue, fieldValue) >= 0) { tempValue = fieldValue; } else { return false; } } return true; }
From source file:org.sakaiproject.sitestats.tool.wicket.pages.ReportsEditPage.java
public static final Comparator<ToolInfo> getToolInfoComparator(final Collator collator) { return new Comparator<ToolInfo>() { public int compare(ToolInfo o1, ToolInfo o2) { String toolName1 = Locator.getFacade().getEventRegistryService().getToolName(o1.getToolId()); String toolName2 = Locator.getFacade().getEventRegistryService().getToolName(o2.getToolId()); return collator.compare(toolName1, toolName2); }//from ww w . j a va2s. c om }; }
From source file:org.apache.nifi.update.attributes.api.RuleResource.java
@GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Path("/rules/search-results") public Response searchRules(@QueryParam("processorId") final String processorId, @QueryParam("q") final String term) { // get the web context final NiFiWebConfigurationContext configurationContext = (NiFiWebConfigurationContext) servletContext .getAttribute("nifi-web-configuration-context"); // build the web context config final NiFiWebRequestContext requestContext = getRequestContext(processorId); // load the criteria final Criteria criteria = getCriteria(configurationContext, requestContext); final List<Rule> rules = criteria.getRules(); // generate the rules List<RuleDTO> ruleDtos = null; if (rules != null) { ruleDtos = new ArrayList<>(rules.size()); for (final Rule rule : rules) { if (StringUtils.containsIgnoreCase(rule.getName(), term)) { final RuleDTO ruleDto = DtoFactory.createRuleDTO(rule); ruleDtos.add(ruleDto);// w ww .j ava 2s .c om } } } // sort the rules Collections.sort(ruleDtos, new Comparator<RuleDTO>() { @Override public int compare(RuleDTO r1, RuleDTO r2) { final Collator collator = Collator.getInstance(Locale.US); return collator.compare(r1.getName(), r2.getName()); } }); // create the response entity final RulesEntity responseEntity = new RulesEntity(); responseEntity.setProcessorId(processorId); responseEntity.setRules(ruleDtos); // generate the response final ResponseBuilder response = Response.ok(responseEntity); return noCache(response).build(); }
From source file:de.acosix.alfresco.site.hierarchy.repo.service.SiteHierarchyServiceImpl.java
/** * * {@inheritDoc}/*from w w w . j a va 2s . c om*/ */ @Override public List<SiteInfo> listChildSites(final String parentSite, final boolean respectShowInHierarchyMode) { ParameterCheck.mandatoryString("parentSite", parentSite); final SiteInfo parentSiteInfo = this.siteService.getSite(parentSite); if (parentSiteInfo == null) { throw new SiteDoesNotExistException(parentSite); } LOGGER.debug("Listing child sites for parent {}", parentSite); final List<ChildAssociationRef> childSiteAssocs = this.nodeService.getChildAssocs( parentSiteInfo.getNodeRef(), SiteHierarchyModel.ASSOC_CHILD_SITE, RegexQNamePattern.MATCH_ALL); if (respectShowInHierarchyMode) { final List<ChildAssociationRef> childSiteAssocsNeverToShow = this.nodeService .getChildAssocsByPropertyValue(parentSiteInfo.getNodeRef(), SiteHierarchyModel.PROP_SHOW_IN_HIERARCHY_MODE, SiteHierarchyModel.CONSTRAINT_SHOW_IN_HIERARCHY_MODES_NEVER); childSiteAssocs.removeAll(childSiteAssocsNeverToShow); } final List<SiteInfo> childSites = new ArrayList<>(childSiteAssocs.size()); childSiteAssocs.forEach(childSiteAssoc -> { final SiteInfo site = this.siteService.getSite(childSiteAssoc.getChildRef()); if (site != null) { childSites.add(site); } }); final Collator collator = Collator.getInstance(I18NUtil.getLocale()); Collections.sort(childSites, (siteA, siteB) -> { final int titleCompareResult = collator.compare(siteA.getTitle(), siteB.getTitle()); return titleCompareResult; }); LOGGER.debug("Listed child sites {} for parent {}", childSites, parentSite); return childSites; }