List of usage examples for java.text Collator getInstance
public static Collator getInstance(Locale desiredLocale)
From source file:nl.inl.util.StringUtil.java
/** * Get a Dutch, case-insensitive collator. * * @return the Dutch, case-insensitive collator. *//* ww w . j av a 2s .co m*/ public static Collator getEnglishInsensitiveCollator() { if (englishInsensitiveCollator == null) { englishInsensitiveCollator = Collator.getInstance(englishLocale); englishInsensitiveCollator.setStrength(Collator.SECONDARY); } return englishInsensitiveCollator; }
From source file:de.acosix.alfresco.site.hierarchy.repo.service.SiteHierarchyServiceImpl.java
/** * * {@inheritDoc}//from w w w .j a v a 2 s . com */ @Override public List<SiteInfo> listTopLevelSites(final boolean respectShowInHierarchyMode) { LOGGER.debug("Listing top level sites"); final SearchParameters sp = new SearchParameters(); sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); sp.setQueryConsistency(QueryConsistency.TRANSACTIONAL_IF_POSSIBLE); sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); final MessageFormat queryFormat = new MessageFormat("TYPE:\"{0}\" AND ASPECT:\"{1}\"", Locale.ENGLISH); String query = queryFormat.format(new Object[] { SiteModel.TYPE_SITE.toPrefixString(this.namespaceService), SiteHierarchyModel.ASPECT_TOP_LEVEL_SITE.toPrefixString(this.namespaceService) }); if (respectShowInHierarchyMode) { // this will cause db-fts not to be used final MessageFormat queryFilterFormat = new MessageFormat("={0}:{1} OR (={0}:{2} AND ASPECT:\"{3}\")", Locale.ENGLISH); final String queryFilter = queryFilterFormat.format(new Object[] { SiteHierarchyModel.PROP_SHOW_IN_HIERARCHY_MODE.toPrefixString(this.namespaceService), SiteHierarchyModel.CONSTRAINT_SHOW_IN_HIERARCHY_MODES_ALWAYS, SiteHierarchyModel.CONSTRAINT_SHOW_IN_HIERARCHY_MODES_IF_PARENT_OR_CHILD, SiteHierarchyModel.ASPECT_PARENT_SITE.toPrefixString(this.namespaceService) }); // if we did not want to support 5.0.d we could use filter query support // TODO find a way to dynamically use filter query support WITHOUT reflection query = query + " AND (" + queryFilter + ")"; } sp.setQuery(query); LOGGER.debug("Using FTS query \"{}\" to list top level sites", query); // we use short name sort since that is properly handled in either db-fts or fts // and might be specific enough so that in-memory post sort does not have to do that much final String shortNameSort = "@" + ContentModel.PROP_NAME.toPrefixString(this.namespaceService); sp.addSort(shortNameSort, true); List<SiteInfo> sites; final ResultSet resultSet = this.searchService.query(sp); try { sites = new ArrayList<>(resultSet.length()); resultSet.forEach(resultRow -> { final NodeRef nodeRef = resultRow.getNodeRef(); final SiteInfo site = this.siteService.getSite(nodeRef); if (site != null) { sites.add(site); } }); } finally { resultSet.close(); } final Collator collator = Collator.getInstance(I18NUtil.getLocale()); Collections.sort(sites, (siteA, siteB) -> { final int titleCompareResult = collator.compare(siteA.getTitle(), siteB.getTitle()); return titleCompareResult; }); LOGGER.debug("Listed top level sites {}", sites); return sites; }
From source file:com.jeans.iservlet.action.asset.AssetAction.java
/** * ?//w w w .java2 s .c o m * * @return * @throws Exception */ @Action(value = "load-assets", results = { @Result(type = "json", params = { "root", "data" }) }) public String loadAssets() throws Exception { long[] total = new long[1]; List<Asset> assets = assetService.loadAssets(getCurrentCompany(), type, page, rows, total); List<AssetItem> assetItemsList = new ArrayList<AssetItem>(); for (Asset asset : assets) { if (asset instanceof Hardware) { assetItemsList.add(HardwareItem.createInstance((Hardware) asset)); } else if (asset instanceof Software) { assetItemsList.add(SoftwareItem.createInstance((Software) asset)); } } data = new DataGrid<AssetItem>(total[0], assetItemsList); if (null != sort && data.getRows().size() > 0) { Collections.sort(data.getRows(), new Comparator<AssetItem>() { @Override public int compare(AssetItem o1, AssetItem o2) { int ret = 0; boolean asc = "asc".equals(order); boolean isHardware = o1 instanceof HardwareItem; switch (sort) { case "code": ret = compString(((HardwareItem) o1).getCode(), ((HardwareItem) o2).getCode(), asc); break; case "financialCode": ret = compString(((HardwareItem) o1).getFinancialCode(), ((HardwareItem) o2).getFinancialCode(), asc); break; case "name": if (isHardware) { ret = compString(((HardwareItem) o1).getName(), ((HardwareItem) o2).getName(), asc); } else { ret = compString(((SoftwareItem) o1).getName(), ((SoftwareItem) o2).getName(), asc); } break; case "vendor": if (isHardware) { ret = compString(((HardwareItem) o1).getVendor(), ((HardwareItem) o2).getVendor(), asc); } else { ret = compString(((SoftwareItem) o1).getVendor(), ((SoftwareItem) o2).getVendor(), asc); } break; case "modelOrVersion": if (isHardware) { ret = compString(((HardwareItem) o1).getModelOrVersion(), ((HardwareItem) o2).getName(), asc); } else { ret = compString(((SoftwareItem) o1).getModelOrVersion(), ((SoftwareItem) o2).getModelOrVersion(), asc); } break; case "sn": ret = compString(((HardwareItem) o1).getSn(), ((HardwareItem) o2).getSn(), asc); break; case "purchaseTime": Date t1 = isHardware ? ((HardwareItem) o1).getPurchaseTime() : ((SoftwareItem) o1).getPurchaseTime(); Date t2 = isHardware ? ((HardwareItem) o2).getPurchaseTime() : ((SoftwareItem) o2).getPurchaseTime(); if (null == t1) { if (null == t2) { ret = 0; } else { ret = asc ? -1 : 1; } } else { if (null == t2) { ret = asc ? 1 : -1; } else { ret = asc ? t1.compareTo(t2) : t2.compareTo(t1); } } break; case "quantity": if (isHardware) { ret = asc ? Integer.compare(((HardwareItem) o1).getQuantity(), ((HardwareItem) o2).getQuantity()) : Integer.compare(((HardwareItem) o2).getQuantity(), ((HardwareItem) o1).getQuantity()); } else { ret = asc ? Integer.compare(((SoftwareItem) o1).getQuantity(), ((SoftwareItem) o2).getQuantity()) : Integer.compare(((SoftwareItem) o2).getQuantity(), ((SoftwareItem) o1).getQuantity()); } break; case "cost": BigDecimal d1 = isHardware ? ((HardwareItem) o1).getCost() : ((SoftwareItem) o1).getCost(); BigDecimal d2 = isHardware ? ((HardwareItem) o2).getCost() : ((SoftwareItem) o2).getCost(); if (null == d1) { d1 = new BigDecimal(0.0); } if (null == d2) { d2 = new BigDecimal(0.0); } ret = asc ? d1.compareTo(d2) : d2.compareTo(d1); break; case "state": if (isHardware) { ret = compString(((HardwareItem) o1).getState(), ((HardwareItem) o2).getState(), asc); } else { ret = compString(((SoftwareItem) o1).getState(), ((SoftwareItem) o2).getState(), asc); } break; case "warranty": ret = compString(((HardwareItem) o1).getWarranty(), ((HardwareItem) o2).getWarranty(), asc); break; case "location": ret = compString(((HardwareItem) o1).getLocation(), ((HardwareItem) o2).getLocation(), asc); break; case "ip": ret = compString(((HardwareItem) o1).getIp(), ((HardwareItem) o2).getIp(), asc); break; case "importance": ret = compString(((HardwareItem) o1).getImportance(), ((HardwareItem) o2).getImportance(), asc); break; case "owner": ret = compString(((HardwareItem) o1).getOwner(), ((HardwareItem) o2).getOwner(), asc); break; case "softwareType": ret = compString(((SoftwareItem) o1).getSoftwareType(), ((SoftwareItem) o2).getSoftwareType(), asc); break; case "license": ret = compString(((SoftwareItem) o1).getLicense(), ((SoftwareItem) o2).getLicense(), asc); break; case "expiredTime": Date e1 = ((SoftwareItem) o1).getPurchaseTime(); Date e2 = ((SoftwareItem) o2).getPurchaseTime(); if (null == e1) { if (null == e2) { ret = 0; } else { ret = asc ? -1 : 1; } } else { if (null == e2) { ret = asc ? 1 : -1; } else { ret = asc ? e1.compareTo(e2) : e2.compareTo(e1); } } } return ret; } private int compString(String s1, String s2, boolean asc) { if (null == s1) { if (null == s2) { return 0; } else { return asc ? -1 : 1; } } else { if (null == s2) { return asc ? 1 : -1; } else { return asc ? Collator.getInstance(java.util.Locale.CHINA).compare(s1, s2) : Collator.getInstance(java.util.Locale.CHINA).compare(s2, s1); } } } }); } return SUCCESS; }
From source file:de.acosix.alfresco.site.hierarchy.repo.service.SiteHierarchyServiceImpl.java
/** * * {@inheritDoc}// w w w . j av a 2s .co m */ @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; }
From source file:org.nuxeo.directory.connector.SuggestDirectoryEntries.java
/** * @since 5.9.3/*from w w w . j a v a 2s . com*/ */ protected Collator getCollator() { if (collator == null) { collator = Collator.getInstance(getLocale()); if (caseSensitive) { collator.setStrength(Collator.TERTIARY); } else { collator.setStrength(Collator.SECONDARY); } } return collator; }
From source file:org.apache.nifi.audit.ProcessorAuditor.java
/** * Extracts the values for the configured properties from the specified Processor. *///from www.j a v a 2s . c o m private Map<String, String> extractConfiguredPropertyValues(ProcessorNode processor, ProcessorDTO processorDTO) { Map<String, String> values = new HashMap<>(); if (processorDTO.getName() != null) { values.put(NAME, processor.getName()); } if (processorDTO.getConfig() != null) { ProcessorConfigDTO newConfig = processorDTO.getConfig(); if (newConfig.getConcurrentlySchedulableTaskCount() != null) { values.put(CONCURRENTLY_SCHEDULABLE_TASKS, String.valueOf(processor.getMaxConcurrentTasks())); } if (newConfig.getPenaltyDuration() != null) { values.put(PENALTY_DURATION, processor.getPenalizationPeriod()); } if (newConfig.getYieldDuration() != null) { values.put(YIELD_DURATION, processor.getYieldPeriod()); } if (newConfig.getBulletinLevel() != null) { values.put(BULLETIN_LEVEL, processor.getBulletinLevel().name()); } if (newConfig.getAnnotationData() != null) { values.put(ANNOTATION_DATA, processor.getAnnotationData()); } if (newConfig.getSchedulingPeriod() != null) { values.put(SCHEDULING_PERIOD, String.valueOf(processor.getSchedulingPeriod())); } if (newConfig.getAutoTerminatedRelationships() != null) { // get each of the auto terminated relationship names final Set<Relationship> autoTerminatedRelationships = processor.getAutoTerminatedRelationships(); final List<String> autoTerminatedRelationshipNames = new ArrayList<>( autoTerminatedRelationships.size()); for (final Relationship relationship : autoTerminatedRelationships) { autoTerminatedRelationshipNames.add(relationship.getName()); } // sort them and include in the configuration Collections.sort(autoTerminatedRelationshipNames, Collator.getInstance(Locale.US)); values.put(AUTO_TERMINATED_RELATIONSHIPS, StringUtils.join(autoTerminatedRelationshipNames, ", ")); } if (newConfig.getProperties() != null) { // for each property specified, extract its configured value Map<String, String> properties = newConfig.getProperties(); Map<PropertyDescriptor, String> configuredProperties = processor.getProperties(); for (String propertyName : properties.keySet()) { // build a descriptor for getting the configured value PropertyDescriptor propertyDescriptor = new PropertyDescriptor.Builder().name(propertyName) .build(); String configuredPropertyValue = configuredProperties.get(propertyDescriptor); // if the configured value couldn't be found, use the default value from the actual descriptor if (configuredPropertyValue == null) { propertyDescriptor = locatePropertyDescriptor(configuredProperties.keySet(), propertyDescriptor); configuredPropertyValue = propertyDescriptor.getDefaultValue(); } values.put(propertyName, configuredPropertyValue); } } if (newConfig.getComments() != null) { values.put(COMMENTS, processor.getComments()); } if (newConfig.getSchedulingStrategy() != null) { values.put(SCHEDULING_STRATEGY, processor.getSchedulingStrategy().name()); } if (newConfig.getExecutionNode() != null) { values.put(EXECUTION_NODE, processor.getExecutionNode().name()); } } return values; }
From source file:fr.gouv.culture.thesaurus.service.impl.SesameThesaurus.java
/** {@inheritDoc} */ @Override/*from w w w . j a va 2s. c o 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 ww w.j av 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.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);//ww w . ja va 2s. c o m } } } // 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.baumann.thema.RequestActivity.java
@SuppressWarnings("unchecked") private void prepareData() // Sort the apps { ArrayList<AppInfo> arrayList = new ArrayList(); PackageManager pm = getPackageManager(); Intent intent = new Intent("android.intent.action.MAIN", null); intent.addCategory("android.intent.category.LAUNCHER"); List list = pm.queryIntentActivities(intent, 0); Iterator localIterator = list.iterator(); if (DEBUG)/* w w w. jav a 2 s . c o m*/ Log.v(TAG, "list.size(): " + list.size()); for (int i = 0; i < list.size(); i++) { ResolveInfo resolveInfo = (ResolveInfo) localIterator.next(); // This is the main part where the already styled apps are sorted out. if ((list_activities .indexOf(resolveInfo.activityInfo.packageName + "/" + resolveInfo.activityInfo.name) == -1)) { AppInfo tempAppInfo = new AppInfo( resolveInfo.activityInfo.packageName + "/" + resolveInfo.activityInfo.name, //Get package/activity resolveInfo.loadLabel(pm).toString(), //Get the app name getHighResIcon(pm, resolveInfo) //Loads xxxhdpi icon, returns normal if it on fail //Unselect icon per default ); arrayList.add(tempAppInfo); // This is just for debugging if (DEBUG) Log.i(TAG, "Added app: " + resolveInfo.loadLabel(pm)); } else { // This is just for debugging if (DEBUG) Log.v(TAG, "Removed app: " + resolveInfo.loadLabel(pm)); } } Collections.sort(arrayList, new Comparator<AppInfo>() { //Custom comparator to ensure correct sorting for characters like and apps starting with a small letter like iNex @Override public int compare(AppInfo object1, AppInfo object2) { Locale locale = Locale.getDefault(); Collator collator = Collator.getInstance(locale); collator.setStrength(Collator.TERTIARY); if (DEBUG) Log.v(TAG, "Comparing \"" + object1.getName() + "\" to \"" + object2.getName() + "\""); return collator.compare(object1.getName(), object2.getName()); } }); list_activities_final = arrayList; }