List of usage examples for java.text Collator getInstance
public static synchronized Collator getInstance()
From source file:org.apache.marmotta.platform.core.services.logging.LoggingServiceImpl.java
/** * Return a list of all modules found on the classpath. This list is assembled via CDI injection. Since modules are * managed beans, calling setters on the LoggingModule implementations will directly change the configuration. * * @return//w w w . j a v a 2 s.c om */ @Override public List<LoggingModule> listModules() { List<LoggingModule> result = Lists.newArrayList(loggingModules); Collections.sort(result, new Comparator<LoggingModule>() { @Override public int compare(LoggingModule o1, LoggingModule o2) { return Collator.getInstance().compare(o1.getName(), o2.getName()); } }); return result; }
From source file:org.sakaiproject.component.app.roster.RosterManagerImpl.java
private Comparator<Group> sortGroups() { Comparator<Group> groupComparator = new Comparator<Group>() { public int compare(Group one, Group another) { try { RuleBasedCollator r_collator = new RuleBasedCollator( ((RuleBasedCollator) Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'")); return r_collator.compare(one.getTitle(), another.getTitle()); } catch (ParseException e) { return Collator.getInstance().compare(one.getTitle(), another.getTitle()); }/*from ww w. ja v a 2 s .c om*/ } }; return groupComparator; }
From source file:hudson.logging.LogRecorder.java
/** * Gets a view of log records per agent matching this recorder. * @return a map (sorted by display name) from computer to (nonempty) list of log records * @since 1.519/*w w w .j av a 2s.co m*/ */ public Map<Computer, List<LogRecord>> getSlaveLogRecords() { Map<Computer, List<LogRecord>> result = new TreeMap<Computer, List<LogRecord>>(new Comparator<Computer>() { final Collator COLL = Collator.getInstance(); public int compare(Computer c1, Computer c2) { return COLL.compare(c1.getDisplayName(), c2.getDisplayName()); } }); for (Computer c : Jenkins.getInstance().getComputers()) { if (c.getName().length() == 0) { continue; // master } List<LogRecord> recs = new ArrayList<LogRecord>(); try { for (LogRecord rec : c.getLogRecords()) { for (Target t : targets) { if (t.includes(rec)) { recs.add(rec); break; } } } } catch (IOException x) { continue; } catch (InterruptedException x) { continue; } if (!recs.isEmpty()) { result.put(c, recs); } } return result; }
From source file:com.android.music.PlaylistBrowserFragment.java
private Cursor getPlaylistCursor(AsyncQueryHandler async, String filterstring) { StringBuilder where = new StringBuilder(); where.append(MediaStore.Audio.Playlists.NAME + " != ''"); // Add in the filtering constraints String[] keywords = null;/*from ww w . ja v a 2s . com*/ if (filterstring != null) { String[] searchWords = filterstring.split(" "); keywords = new String[searchWords.length]; Collator col = Collator.getInstance(); col.setStrength(Collator.PRIMARY); for (int i = 0; i < searchWords.length; i++) { keywords[i] = '%' + searchWords[i] + '%'; } for (int i = 0; i < searchWords.length; i++) { where.append(" AND "); where.append(MediaStore.Audio.Playlists.NAME + " LIKE ?"); } } String whereclause = where.toString(); if (async != null) { async.startQuery(0, null, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, mCols, whereclause, keywords, MediaStore.Audio.Playlists.NAME); return null; } Cursor c = null; c = MusicUtils.query(getActivity(), MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, mCols, whereclause, keywords, MediaStore.Audio.Playlists.NAME); return mergedCursor(c); }
From source file:org.forgerock.openidm.audit.impl.CSVAuditLogger.java
private void createImpl(String type, Map<String, Object> obj) throws ResourceException { // Re-try once in case the writer stream became closed for some reason boolean retry = false; int retryCount = 0; do {//from www . j a v a 2 s . c o m retry = false; BufferedWriter fileWriter = null; try { // TODO: Optimize ordering etc. Collection<String> fieldOrder = new TreeSet<String>(Collator.getInstance()); fieldOrder.addAll(obj.keySet()); File auditFile = getAuditLogFile(type); // Create header if creating a new file if (!auditFile.exists()) { synchronized (fileWriters) { BufferedWriter existingFileWriter = getWriter(type, auditFile, false); File auditTmpFile = new File(auditLogDir, type + ".tmp"); // This is atomic, so only one caller will succeed with created boolean created = auditTmpFile.createNewFile(); if (created) { BufferedWriter tmpFileWriter = new BufferedWriter(new FileWriter(auditTmpFile, true), bufferSize); writeHeaders(fieldOrder, tmpFileWriter); tmpFileWriter.close(); auditTmpFile.renameTo(auditFile); resetWriter(type, existingFileWriter); } } } fileWriter = getWriter(type, auditFile, true); writeEntry(fileWriter, type, auditFile, obj, fieldOrder); if (maxFlushDelay > 0) { synchronized (flushTimerLock) { if (flushTimer != null && flushTimer.isAlive()) { flushTimer.interrupt(); } flushTimer = new WriteBufferFlushTimer(maxFlushDelay); } } else { fileWriter.flush(); } } catch (IOException ex) { if (retryCount == 0) { retry = true; logger.debug("IOException during entry write, reset writer and re-try {}", ex.getMessage()); resetWriter(type, fileWriter); } else { throw new BadRequestException(ex); } } ++retryCount; } while (retry); }
From source file:org.openflexo.localization.LocalizedDelegateImpl.java
public Vector<Entry> getEntries() { if (entries == null) { if (_localizedDictionaries == null) { loadLocalizedDictionaries(); }/*from ww w .j a v a 2 s . c om*/ entries = new Vector<Entry>(); if (_localizedDictionaries.size() > 0) { Enumeration en = _localizedDictionaries.values().iterator().next().propertyNames(); while (en.hasMoreElements()) { entries.add(new Entry((String) en.nextElement())); } } Collections.sort(entries, new Comparator<Entry>() { @Override public int compare(Entry o1, Entry o2) { return Collator.getInstance().compare(o1.key, o2.key); } }); computeIssuesEntries(); } return entries; }
From source file:org.uguess.android.sysinfo.NetStateManager.java
void refresh() { ArrayList<ConnectionItem> data = new ArrayList<ConnectionItem>(); data.add(dummyInfo);/*from w w w . j av a2s.com*/ ArrayList<ConnectionItem> items = readStatesRaw(); if (items != null) { final int type = Util.getIntOption(getActivity(), PSTORE_NETMANAGER, PREF_KEY_SORT_ORDER_TYPE, ORDER_TYPE_PROTO); final int direction = Util.getIntOption(getActivity(), PSTORE_NETMANAGER, PREF_KEY_SORT_DIRECTION, ORDER_ASC); final Collator clt = Collator.getInstance(); switch (type) { case ORDER_TYPE_PROTO: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.proto, obj2.proto) * direction; } }); break; case ORDER_TYPE_LOCAL: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.local, obj2.local) * direction; } }); break; case ORDER_TYPE_REMOTE: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.remoteName == null ? obj1.remote : obj1.remoteName, obj2.remoteName == null ? obj2.remote : obj2.remoteName) * direction; } }); break; case ORDER_TYPE_STATE: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.state == null ? "" //$NON-NLS-1$ : obj1.state, obj2.state == null ? "" //$NON-NLS-1$ : obj2.state) * direction; } }); break; } data.addAll(items); } ArrayAdapter<ConnectionItem> adapter = (ArrayAdapter<ConnectionItem>) getListView().getAdapter(); adapter.setNotifyOnChange(false); adapter.clear(); for (int i = 0, size = data.size(); i < size; i++) { adapter.add(data.get(i)); } adapter.notifyDataSetChanged(); if (adapter.getCount() == 1) { Log.d(NetStateManager.class.getName(), "No network traffic detected"); //$NON-NLS-1$ } }
From source file:com.facebook.widget.GraphObjectAdapter.java
private void rebuildSections() { sectionKeys = new ArrayList<String>(); graphObjectsBySection = new HashMap<String, ArrayList<T>>(); graphObjectsById = new HashMap<String, T>(); displaySections = false;/* w w w . j a va2 s .c om*/ if (cursor == null || cursor.getCount() == 0) { return; } int objectsAdded = 0; cursor.moveToFirst(); do { T graphObject = cursor.getGraphObject(); if (!filterIncludesItem(graphObject)) { continue; } objectsAdded++; String sectionKeyOfItem = getSectionKeyOfGraphObject(graphObject); if (!graphObjectsBySection.containsKey(sectionKeyOfItem)) { sectionKeys.add(sectionKeyOfItem); graphObjectsBySection.put(sectionKeyOfItem, new ArrayList<T>()); } List<T> section = graphObjectsBySection.get(sectionKeyOfItem); section.add(graphObject); graphObjectsById.put(getIdOfGraphObject(graphObject), graphObject); } while (cursor.moveToNext()); if (sortFields != null) { final Collator collator = Collator.getInstance(); for (List<T> section : graphObjectsBySection.values()) { Collections.sort(section, new Comparator<GraphObject>() { @Override public int compare(GraphObject a, GraphObject b) { return compareGraphObjects(a, b, sortFields, collator); } }); } } Collections.sort(sectionKeys, Collator.getInstance()); displaySections = sectionKeys.size() > 1 && objectsAdded > DISPLAY_SECTIONS_THRESHOLD; }
From source file:com.eutectoid.dosomething.picker.GraphObjectAdapter.java
private void rebuildSections() { sectionKeys = new ArrayList<String>(); graphObjectsBySection = new HashMap<String, ArrayList<JSONObject>>(); graphObjectsById = new HashMap<String, JSONObject>(); displaySections = false;/* w w w. j av a 2 s . c om*/ if (cursor == null || cursor.getCount() == 0) { return; } int objectsAdded = 0; cursor.moveToFirst(); do { JSONObject graphObject = cursor.getGraphObject(); if (!filterIncludesItem(graphObject)) { continue; } objectsAdded++; String sectionKeyOfItem = getSectionKeyOfGraphObject(graphObject); if (!graphObjectsBySection.containsKey(sectionKeyOfItem)) { sectionKeys.add(sectionKeyOfItem); graphObjectsBySection.put(sectionKeyOfItem, new ArrayList<JSONObject>()); } List<JSONObject> section = graphObjectsBySection.get(sectionKeyOfItem); section.add(graphObject); graphObjectsById.put(getIdOfGraphObject(graphObject), graphObject); } while (cursor.moveToNext()); if (sortFields != null) { final Collator collator = Collator.getInstance(); for (List<JSONObject> section : graphObjectsBySection.values()) { Collections.sort(section, new Comparator<JSONObject>() { @Override public int compare(JSONObject a, JSONObject b) { return compareGraphObjects(a, b, sortFields, collator); } }); } } Collections.sort(sectionKeys, Collator.getInstance()); displaySections = sectionKeys.size() > 1 && objectsAdded > DISPLAY_SECTIONS_THRESHOLD; }
From source file:ro.nextreports.designer.util.NextReportsUtil.java
/** * Get i18n keys for current loaded report * //from w w w . j a v a2 s. c om * @return a set of i18n keys */ public static List<String> getReportKeys() { Set<String> keys = new TreeSet<String>(); if (Globals.isReportLoaded()) { keys.addAll(ReportUtil.getKeys(LayoutHelper.getReportLayout())); } else if (Globals.isChartLoaded()) { String loadedFilePath = Globals.getCurrentChartAbsolutePath(); if (loadedFilePath != null) { Chart chartLoaded = ChartUtil.loadChart(loadedFilePath); keys.addAll(ChartUtil.getKeys(chartLoaded)); } } List<QueryParameter> params = ParameterManager.getInstance().getParameters(); for (QueryParameter p : params) { if (p.getRuntimeName().contains(I18nString.MARKUP)) { keys.add(StringUtil.getKey(p.getRuntimeName())); } } List<String> result = new ArrayList(keys); Collections.sort(result, new Comparator<String>() { @Override public int compare(String o1, String o2) { return Collator.getInstance().compare(o1, o2); } }); return result; }