List of usage examples for java.text Collator setStrength
public synchronized void setStrength(int newStrength)
From source file:de.geeksfactory.opacclient.objects.Library.java
@Override public int compareTo(Library arg0) { Collator deCollator = Collator.getInstance(Locale.GERMAN); deCollator.setStrength(Collator.TERTIARY); int g = deCollator.compare(country, arg0.getCountry()); if (g == 0) { g = deCollator.compare(state, arg0.getState()); if (g == 0) { g = deCollator.compare(city, arg0.getCity()); if (g == 0) { g = deCollator.compare(title, arg0.getTitle()); }/*from ww w . ja va 2 s.co m*/ } } return g; }
From source file:org.nimbustools.messaging.query.security.QueryAuthenticationFilter.java
private String getStringToSign_v1(HttpServletRequest request) { // Request must mapped to into a canonical string format. See: // http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/using-query-api.html#query-authentication final StringBuilder buf = new StringBuilder(); Collator stringCollator = Collator.getInstance(); stringCollator.setStrength(Collator.PRIMARY); final Set<String> sortedKeys = new TreeSet<String>(stringCollator); final Enumeration paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { String param = (String) paramNames.nextElement(); // don't include signature in canonical query string if (!param.equals(this.signatureParameter)) { sortedKeys.add(param);/*ww w . j a v a 2 s .co m*/ } } for (String key : sortedKeys) { String[] values = request.getParameterValues(key); for (String val : values) { buf.append(key).append(val); } } return buf.toString(); }
From source file:com.andryr.musicplayer.activities.MusicPicker.java
private void getSongList() { ContentResolver resolver = getContentResolver(); Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; Cursor cursor = resolver.query(musicUri, sProjection, null, null, null); if (cursor != null && cursor.moveToFirst()) { int idCol = cursor.getColumnIndex(MediaStore.Audio.Playlists.Members.AUDIO_ID); if (idCol == -1) { idCol = cursor.getColumnIndex(MediaStore.Audio.Media._ID); }// w ww .ja v a 2 s .c o m int titleCol = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE); int artistCol = cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST); int albumCol = cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM); int albumIdCol = cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID); int trackCol = cursor.getColumnIndex(MediaStore.Audio.Media.TRACK); int durationCol = cursor.getColumnIndex(MediaStore.Audio.Media.DURATION); do { long id = cursor.getLong(idCol); String title = cursor.getString(titleCol); String artist = cursor.getString(artistCol); String album = cursor.getString(albumCol); long albumId = cursor.getLong(albumIdCol); int track = cursor.getInt(trackCol); long duration = cursor.getLong(durationCol); mSongList.add(new Song(id, title, artist, album, albumId, track, duration)); } while (cursor.moveToNext()); Collections.sort(mSongList, new Comparator<Song>() { @Override public int compare(Song lhs, Song rhs) { Collator c = Collator.getInstance(Locale.getDefault()); c.setStrength(Collator.PRIMARY); return c.compare(lhs.getTitle(), rhs.getTitle()); } }); } if (cursor != null) { cursor.close(); } }
From source file:com.ecyrd.jspwiki.plugin.AbstractReferralPlugin.java
/** * Helper method to initialize the comparator for this page. *///from w w w. j a va2 s .c o m private void initSorter(WikiContext context, Map params) { String order = (String) params.get(PARAM_SORTORDER); if (order == null || order.length() == 0) { // Use the configured comparator m_sorter = context.getEngine().getPageSorter(); } else if (order.equalsIgnoreCase(PARAM_SORTORDER_JAVA)) { // use Java "natural" ordering m_sorter = new PageSorter(JavaNaturalComparator.DEFAULT_JAVA_COMPARATOR); } else if (order.equalsIgnoreCase(PARAM_SORTORDER_LOCALE)) { // use this locale's ordering m_sorter = new PageSorter(LocaleComparator.DEFAULT_LOCALE_COMPARATOR); } else if (order.equalsIgnoreCase(PARAM_SORTORDER_HUMAN)) { // use human ordering m_sorter = new PageSorter(HumanComparator.DEFAULT_HUMAN_COMPARATOR); } else try { Collator collator = new RuleBasedCollator(order); collator.setStrength(Collator.PRIMARY); m_sorter = new PageSorter(new CollatorComparator(collator)); } catch (ParseException pe) { log.info("Failed to parse requested collator - using default ordering", pe); m_sorter = context.getEngine().getPageSorter(); } }
From source file:org.apache.wiki.plugin.AbstractReferralPlugin.java
/** * Helper method to initialize the comparator for this page. *///from ww w.jav a 2s . c o m private void initSorter(WikiContext context, Map<String, String> params) { String order = params.get(PARAM_SORTORDER); if (order == null || order.length() == 0) { // Use the configured comparator m_sorter = context.getEngine().getPageSorter(); } else if (order.equalsIgnoreCase(PARAM_SORTORDER_JAVA)) { // use Java "natural" ordering m_sorter = new PageSorter(JavaNaturalComparator.DEFAULT_JAVA_COMPARATOR); } else if (order.equalsIgnoreCase(PARAM_SORTORDER_LOCALE)) { // use this locale's ordering m_sorter = new PageSorter(LocaleComparator.DEFAULT_LOCALE_COMPARATOR); } else if (order.equalsIgnoreCase(PARAM_SORTORDER_HUMAN)) { // use human ordering m_sorter = new PageSorter(HumanComparator.DEFAULT_HUMAN_COMPARATOR); } else try { Collator collator = new RuleBasedCollator(order); collator.setStrength(Collator.PRIMARY); m_sorter = new PageSorter(new CollatorComparator(collator)); } catch (ParseException pe) { log.info("Failed to parse requested collator - using default ordering", pe); m_sorter = context.getEngine().getPageSorter(); } }
From source file:com.xerox.amazonws.common.AWSQueryConnection.java
/** * Make a http request and process the response. This method also performs automatic retries. * * @param method The HTTP method to use (GET, POST, DELETE, etc) * @param action the name of the action for this query request * @param params map of request params//from www . ja va2 s .c o m * @param respType the class that represents the desired/expected return type */ protected <T> T makeRequest(HttpMethodBase method, String action, Map<String, String> params, Class<T> respType) throws HttpException, IOException, JAXBException { // add auth params, and protocol specific headers Map<String, String> qParams = new HashMap<String, String>(params); qParams.put("Action", action); qParams.put("AWSAccessKeyId", getAwsAccessKeyId()); qParams.put("SignatureVersion", "" + sigVersion); qParams.put("Timestamp", httpDate()); if (headers != null) { for (Iterator<String> i = headers.keySet().iterator(); i.hasNext();) { String key = i.next(); for (Iterator<String> j = headers.get(key).iterator(); j.hasNext();) { qParams.put(key, j.next()); } } } // sort params by key ArrayList<String> keys = new ArrayList<String>(qParams.keySet()); Collator stringCollator = Collator.getInstance(); stringCollator.setStrength(Collator.PRIMARY); Collections.sort(keys, stringCollator); // build param string StringBuilder resource = new StringBuilder(); if (sigVersion == 0) { // ensure Action, Timestamp come first! resource.append(qParams.get("Action")); resource.append(qParams.get("Timestamp")); } else { for (String key : keys) { resource.append(key); resource.append(qParams.get(key)); } } // calculate signature String encoded = urlencode(encode(getSecretAccessKey(), resource.toString(), false)); // build param string, encoding values and adding request signature resource = new StringBuilder(); for (String key : keys) { resource.append("&"); resource.append(key); resource.append("="); resource.append(urlencode(qParams.get(key))); } resource.setCharAt(0, '?'); // set first param delimeter resource.append("&Signature="); resource.append(encoded); // finally, build request object URL url = makeURL(resource.toString()); method.setURI(new URI(url.toString(), true)); method.setRequestHeader(new Header("User-Agent", userAgent)); if (sigVersion == 0) { method.setRequestHeader(new Header("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")); } Object response = null; boolean done = false; int retries = 0; boolean doRetry = false; String errorMsg = ""; do { int responseCode = 600; // default to high value, so we don't think it is valid try { responseCode = getHttpClient().executeMethod(method); } catch (SocketException ex) { // these can generally be retried. Treat it like a 500 error doRetry = true; errorMsg = ex.getMessage(); } // 100's are these are handled by httpclient if (responseCode < 300) { // 200's : parse normal response into requested object if (respType != null) { InputStream iStr = method.getResponseBodyAsStream(); response = JAXBuddy.deserializeXMLStream(respType, iStr); } done = true; } else if (responseCode < 400) { // 300's : what to do? throw new HttpException("redirect error : " + responseCode); } else if (responseCode < 500) { // 400's : parse client error message String body = getStringFromStream(method.getResponseBodyAsStream()); throw new HttpException("Client error : " + getErrorDetails(body)); } else if (responseCode < 600) { // 500's : retry... doRetry = true; String body = getStringFromStream(method.getResponseBodyAsStream()); errorMsg = getErrorDetails(body); } if (doRetry) { retries++; if (retries > maxRetries) { throw new HttpException("Number of retries exceeded : " + action + ", " + errorMsg); } doRetry = false; try { Thread.sleep((int) Math.pow(2.0, retries) * 1000); } catch (InterruptedException ex) { } } } while (!done); return (T) response; }
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 w w w . java 2 s . c o m*/ 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.alfresco.web.data.Sort.java
/** * Constructor/* w ww. j ava2 s.c o m*/ * * @param data a the List of String[] data to sort * @param column the column getter method to use on the row to sort * @param bForward true for a forward sort, false for a reverse sort * @param mode sort mode to use (see IDataContainer constants) */ public Sort(List data, String column, boolean bForward, String mode) { this.data = data; this.column = column; this.bForward = bForward; this.sortMode = mode; if (this.data.size() != 0) { // setup the Collator for our Locale Collator collator = Collator.getInstance(Locale.getDefault()); // set the strength according to the sort mode if (mode.equals(IDataContainer.SORT_CASEINSENSITIVE)) { collator.setStrength(Collator.SECONDARY); } else { collator.setStrength(Collator.IDENTICAL); } this.keys = buildCollationKeys(collator); } }
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)// www .ja v a 2s . 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; }