Example usage for java.lang String compareToIgnoreCase

List of usage examples for java.lang String compareToIgnoreCase

Introduction

In this page you can find the example usage for java.lang String compareToIgnoreCase.

Prototype

public int compareToIgnoreCase(String str) 

Source Link

Document

Compares two strings lexicographically, ignoring case differences.

Usage

From source file:fredboat.command.util.MALCommand.java

private boolean handleAnime(TextChannel channel, Member invoker, String terms, String body) {
    String msg = MessageFormat.format(I18n.get(channel.getGuild()).getString("malRevealAnime"),
            invoker.getEffectiveName());

    //Read JSON/*  w  w  w  . j  ava 2  s . c o m*/
    log.info(body);
    JSONObject root = XML.toJSONObject(body);
    JSONObject data;
    try {
        data = root.getJSONObject("anime").getJSONArray("entry").getJSONObject(0);
    } catch (JSONException ex) {
        data = root.getJSONObject("anime").getJSONObject("entry");
    }

    ArrayList<String> titles = new ArrayList<>();
    titles.add(data.getString("title"));

    if (data.has("synonyms")) {
        titles.addAll(Arrays.asList(data.getString("synonyms").split(";")));
    }

    if (data.has("english")) {
        titles.add(data.getString("english"));
    }

    int minDeviation = Integer.MAX_VALUE;
    for (String str : titles) {
        str = str.replace(' ', '+').trim();
        int deviation = str.compareToIgnoreCase(terms);
        deviation = deviation - Math.abs(str.length() - terms.length());
        if (deviation < minDeviation) {
            minDeviation = deviation;
        }
    }

    log.debug("Anime search deviation: " + minDeviation);

    if (minDeviation > 3) {
        return false;
    }

    msg = data.has("title")
            ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malTitle"), msg, data.get("title"))
            : msg;
    msg = data.has("english")
            ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malEnglishTitle"), msg,
                    data.get("english"))
            : msg;
    msg = data.has("synonyms")
            ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malSynonyms"), msg,
                    data.get("synonyms"))
            : msg;
    msg = data.has("episodes")
            ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malEpisodes"), msg,
                    data.get("episodes"))
            : msg;
    msg = data.has("score")
            ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malScore"), msg, data.get("score"))
            : msg;
    msg = data.has("type")
            ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malType"), msg, data.get("type"))
            : msg;
    msg = data.has("status")
            ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malStatus"), msg, data.get("status"))
            : msg;
    msg = data.has("start_date")
            ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malStartDate"), msg,
                    data.get("start_date"))
            : msg;
    msg = data.has("end_date")
            ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malEndDate"), msg,
                    data.get("end_date")) + "\n"
            : msg;

    if (data.has("synopsis")) {
        Matcher m = Pattern.compile("^[^\\n\\r<]+")
                .matcher(StringEscapeUtils.unescapeHtml4(data.getString("synopsis")));
        m.find();
        msg = data.has("synopsis")
                ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malSynopsis"), msg, m.group(0))
                : msg;
    }

    msg = data.has("id") ? msg + "http://myanimelist.net/anime/" + data.get("id") + "/" : msg;

    channel.sendMessage(msg).queue();
    return true;
}

From source file:uf.edu.RegisterUser.java

public void postData() {
    //Data should be verified before calling this code. no verification done here.
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://128.227.176.22:8182/cgi-bin/putData.py");
    try {//ww w  .j  a v  a 2s. com
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("fname", fname));
        nameValuePairs.add(new BasicNameValuePair("lname", lname));
        nameValuePairs.add(new BasicNameValuePair("email", email));
        nameValuePairs.add(new BasicNameValuePair("privacy", privacy));
        nameValuePairs.add(new BasicNameValuePair("profile", profile));
        nameValuePairs.add(new BasicNameValuePair("mac", macaddress));

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = httpclient.execute(httppost, responseHandler).replace('\n', ' ').trim();
        //JSONObject response=new JSONObject(responseBody);
        Log.i(TAG, "Registration Response: " + responseBody);
        if (responseBody.compareToIgnoreCase("success") == 0) {
            Toast.makeText(this, "Registration Successful", Toast.LENGTH_LONG).show();
        } else if (responseBody.compareToIgnoreCase("Error: duplicate record") == 0) {
            Toast.makeText(this, "Already Registered", Toast.LENGTH_LONG).show();
        } else if (responseBody.substring(0, 25 > responseBody.length() ? responseBody.length() : 25)
                .compareToIgnoreCase("Note: changing owner from") == 0) {
            Toast.makeText(this, "Moved already registered device to your account", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this, responseBody, Toast.LENGTH_LONG).show();
        }

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
}

From source file:org.musicmod.android.dialog.PlaylistDialog.java

private String makePlaylistName() {

    String template = getString(R.string.new_playlist_name_template);
    int num = 1;//from   ww w . j a va  2s. c om

    String[] cols = new String[] { MediaStore.Audio.Playlists.NAME };
    ContentResolver resolver = getContentResolver();
    String whereclause = MediaStore.Audio.Playlists.NAME + " != ''";
    Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, cols, whereclause, null,
            MediaStore.Audio.Playlists.NAME);

    if (cursor == null) {
        return null;
    }

    String suggestedname;
    suggestedname = String.format(template, num++);

    // Need to loop until we've made 1 full pass through without finding a
    // match. Looping more than once shouldn't happen very often, but will
    // happen if you have playlists named
    // "New Playlist 1"/10/2/3/4/5/6/7/8/9, where making only one pass would
    // result in "New Playlist 10" being erroneously picked for the new
    // name.
    boolean done = false;
    while (!done) {
        done = true;
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            String playlistname = cursor.getString(0);
            if (playlistname.compareToIgnoreCase(suggestedname) == 0) {
                suggestedname = String.format(template, num++);
                done = false;
            }
            cursor.moveToNext();
        }
    }
    cursor.close();
    return suggestedname;
}

From source file:org.yammp.dialog.PlaylistDialog.java

private String makePlaylistName() {

    String template = getString(R.string.new_playlist_name_template);
    int num = 1;/*from   w  w  w  .ja v a 2 s  .c  om*/

    String[] cols = new String[] { MediaStore.Audio.Playlists.NAME };
    ContentResolver resolver = getContentResolver();
    String whereclause = MediaStore.Audio.Playlists.NAME + " != ''";
    Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, cols, whereclause, null,
            MediaStore.Audio.Playlists.NAME);

    if (cursor == null)
        return null;

    String suggestedname;
    suggestedname = String.format(template, num++);

    // Need to loop until we've made 1 full pass through without finding a
    // match. Looping more than once shouldn't happen very often, but will
    // happen if you have playlists named
    // "New Playlist 1"/10/2/3/4/5/6/7/8/9, where making only one pass would
    // result in "New Playlist 10" being erroneously picked for the new
    // name.
    boolean done = false;
    while (!done) {
        done = true;
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            String playlistname = cursor.getString(0);
            if (playlistname.compareToIgnoreCase(suggestedname) == 0) {
                suggestedname = String.format(template, num++);
                done = false;
            }
            cursor.moveToNext();
        }
    }
    cursor.close();
    return suggestedname;
}

From source file:com.andrew.apollo.menu.PlaylistDialog.java

private String makePlaylistName() {

    String template = getString(R.string.new_playlist_name_template);
    int num = 1;/*  www  . j a v a  2  s.co  m*/

    String[] cols = new String[] { Audio.Playlists.NAME };
    ContentResolver resolver = getContentResolver();
    String whereclause = Audio.Playlists.NAME + " != ''";
    Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, cols, whereclause, null,
            Audio.Playlists.NAME);

    if (cursor == null)
        return null;

    String suggestedname;
    suggestedname = String.format(template, num++);

    // Need to loop until we've made 1 full pass through without finding a
    // match. Looping more than once shouldn't happen very often, but will
    // happen if you have playlists named
    // "New Playlist 1"/10/2/3/4/5/6/7/8/9, where making only one pass would
    // result in "New Playlist 10" being erroneously picked for the new
    // name.
    boolean done = false;
    while (!done) {
        done = true;
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            String playlistname = cursor.getString(0);
            if (playlistname.compareToIgnoreCase(suggestedname) == 0) {
                suggestedname = String.format(template, num++);
                done = false;
            }
            cursor.moveToNext();
        }
    }
    cursor.close();
    return suggestedname;
}

From source file:net.pms.util.UMSUtils.java

public static void sort(List<File> files, int method) {
    switch (method) {
    case SORT_NO_SORT: // no sorting
        break;//  w  w w . j  a v a 2 s.  c o  m
    case SORT_LOC_NAT: // Locale-sensitive natural sort
        Collections.sort(files, new Comparator<File>() {
            @Override
            public int compare(File f1, File f2) {
                String filename1ToSort = FileUtil.renameForSorting(f1.getName());
                String filename2ToSort = FileUtil.renameForSorting(f2.getName());

                return NaturalComparator.compareNatural(collator, filename1ToSort, filename2ToSort);
            }
        });
        break;
    case SORT_INS_ASCII: // Case-insensitive ASCIIbetical sort
        Collections.sort(files, new Comparator<File>() {
            @Override
            public int compare(File f1, File f2) {
                String filename1ToSort = FileUtil.renameForSorting(f1.getName());
                String filename2ToSort = FileUtil.renameForSorting(f2.getName());

                return filename1ToSort.compareToIgnoreCase(filename2ToSort);
            }
        });
        break;
    case SORT_MOD_OLD: // Sort by modified date, oldest first
        Collections.sort(files, new Comparator<File>() {
            @Override
            public int compare(File f1, File f2) {
                return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
            }
        });
        break;
    case SORT_MOD_NEW: // Sort by modified date, newest first
        Collections.sort(files, new Comparator<File>() {
            @Override
            public int compare(File f1, File f2) {
                return Long.valueOf(f2.lastModified()).compareTo(f1.lastModified());
            }
        });
        break;
    case SORT_RANDOM: // Random
        Collections.shuffle(files, new Random(System.currentTimeMillis()));
        break;
    case SORT_LOC_SENS: // Same as default
    default: // Locale-sensitive A-Z
        Collections.sort(files, new Comparator<File>() {
            @Override
            public int compare(File f1, File f2) {
                String filename1ToSort = FileUtil.renameForSorting(f1.getName());
                String filename2ToSort = FileUtil.renameForSorting(f2.getName());

                return collator.compare(filename1ToSort, filename2ToSort);
            }
        });
        break;
    }
}

From source file:org.dspace.content.comparator.NameAscendingComparator.java

@Override
public int compare(DSpaceObject dso1, DSpaceObject dso2) {
    if (dso1 == dso2) {
        return 0;
    } else if (dso1 == null) {
        return -1;
    } else if (dso2 == null) {
        return 1;
    } else {/*from ww  w . j  a va2 s.  c  om*/
        String name1 = StringUtils.trimToEmpty(dso1.getName());
        String name2 = StringUtils.trimToEmpty(dso2.getName());

        //When two DSO's have the same name, use their UUID to put them in an order
        if (name1.equals(name2)) {
            return ObjectUtils.compare(dso1.getID(), dso2.getID());
        } else {
            return name1.compareToIgnoreCase(name2);
        }
    }
}

From source file:com.aliyun.odps.flume.sink.OdpsSink.java

private OdpsEventSerializer createSerializer(String serializerType) {
    if (serializerType.compareToIgnoreCase(OdpsDelimitedTextSerializer.ALIAS) == 0
            || serializerType.compareTo(OdpsDelimitedTextSerializer.class.getName()) == 0) {
        return new OdpsDelimitedTextSerializer();
    }//from   w w w  . ja  va  2s . c o  m

    try {
        return (OdpsEventSerializer) Class.forName(serializerType).newInstance();
    } catch (Exception e) {
        throw new IllegalArgumentException(
                "Unable to instantiate serializer: " + serializerType + " on sink: " + getName(), e);
    }
}

From source file:net.pms.dlna.protocolinfo.MimeType.java

/**
 * Creates a new {@link MimeType} instance using the given values.
 *
 * @param type the first part of the mime-type.
 * @param subtype the second part of the mime-type.
 * @param parameters a {@link Map} of additional parameters for this
 *            mime-type./* w ww.  j a va2  s  .  com*/
 */
public MimeType(String type, String subtype, Map<String, String> parameters) {
    this.type = type == null ? ANY : type;
    this.subtype = subtype == null ? ANY : subtype;
    if (parameters == null) {
        this.parameters = Collections.EMPTY_MAP;
    } else {
        TreeMap<String, String> map = new TreeMap<String, String>(new Comparator<String>() {

            @Override
            public int compare(String o1, String o2) {
                return o1.compareToIgnoreCase(o2);
            }

        });
        for (Entry<String, String> entry : parameters.entrySet()) {
            map.put(entry.getKey(), entry.getValue());
        }
        this.parameters = Collections.unmodifiableSortedMap(map);
    }
    this.stringValue = generateStringValue();
}

From source file:org.apache.hadoop.chukwa.hicc.TimeHandler.java

public long parseDateShorthand(String d) {
    Calendar now = Calendar.getInstance();
    long l = now.getTimeInMillis();
    d = d.trim();/*from   w  w  w.  j  av  a  2s . c  o m*/
    if (d.compareToIgnoreCase("now") == 0) {
        // do nothing because it is default to now.
    } else {
        Options options = new Options(false);
        options.setCompatibilityMode(true);
        options.setNow(now);
        try {
            Span span = Chronic.parse(d, options);
            l = span.getBegin() * 1000;
        } catch (Exception e) {
            // exception when parsing
            log.error("parse error for: " + d);
        }
    }

    /*
     * debug 
     */
    /*
         SimpleDateFormat sf =
    new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date ld=new Date(l);
            
    log.error("Convert:"+d+" to "+Long.toString(l)+" - "+sf.format(ld)+ "-"+ld.getTime());
    */

    return l;
}