Java Code Examples for org.apache.commons.lang.StringUtils.reverse()

The following are Jave code examples for showing how to use reverse() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: media_information_service   File: MediaOperations.java   Source Code and License Vote up 5 votes
private static String trimFileExtension(String s){
    String rev=StringUtils.reverse(s);
    if (s.contains(".")) {
        return StringUtils.reverse(rev.substring(rev.indexOf(".")));
    }
    else return s;
}
 
Example 2
Project: media_information_service   File: APIOperations.java   Source Code and License Vote up 4 votes
public static LinkedList<MusicInfo> musicGetInfoItunes(String name, String max_result, String orderBy, String artist, String year) throws UnirestException
    {
        String name_request = name.replace(" ", "%20");
        String artist_request = artist.trim().replace(" ", "%20");
        LinkedList<MusicInfo> lis = new LinkedList<MusicInfo>();
        String urlRequest = "";
        if (!artist_request.equals("")) urlRequest="https://itunes.apple.com/search" + "?term=" + name_request+"%20"+artist_request+"&media=music";
        else urlRequest="https://itunes.apple.com/search" + "?term=" + name_request+"&media=music";
        String year_request=year;
        if (year_request.trim().equals("") || year.length()<4) year_request="";
        HttpResponse<JsonNode> jsonResponse = Unirest.get(urlRequest).asJson();
        //System.out.println(jsonResponse.getBody());
        JSONObject jsonObject = new JSONObject(jsonResponse.getBody());
        JSONArray jArray = jsonObject.getJSONArray("array");

        int iteration = 0;
        //Generate list of results
        for (int i = 0; i < jArray.length(); i++) {
            JSONArray resultInfo = jArray.getJSONObject(i).getJSONArray("results");
            for (int k = 0; k < resultInfo.length(); k++) {
                JSONObject result = resultInfo.getJSONObject(k);
                MusicInfo b = new MusicInfo();
                b.setTitle(result.getString("trackName"));
                if (result.has("artistName")) b.setArtist(result.getString("artistName"));
                if (result.has("primaryGenreName")) b.setGenre(result.getString("primaryGenreName"));
                if (result.has("releaseDate")) {
                    String y=result.getString("releaseDate");
                    b.setReleaseDate(y.substring(0,y.indexOf("T")));
                }
                if(result.has("artworkUrl100")) {
                    String link_reverse=StringUtils.reverse(result.getString("artworkUrl100"));
                    link_reverse=StringUtils.replace(link_reverse,"001","215",2);
                    b.setLinkImage(StringUtils.reverse(link_reverse));
                    //iTunes cover link doesn't support HTTPS
                }
                if (result.has("collectionName")) b.setCollection(result.getString("collectionName"));
                if (result.has("description")) b.setOverview(result.getString("description"));
                if (result.has("previewUrl")) b.setLinkpreview(result.getString("previewUrl"));
                if(b.getReleaseDate().substring(0,4).equals(year) || year_request.equals("")) lis.add(b);
                //System.out.println(b);
                if (!max_result.equals("all") && iteration == Integer.parseInt(max_result) - 1) break;
                iteration++;
            }
        }

    if (lis.size() > 0 && (!orderBy.equals("relevance") && !orderBy.equals(""))) {
        Collections.sort(lis, new Comparator<MusicInfo>() {
            @Override
            public int compare(final MusicInfo object1, final MusicInfo object2) {
                if (orderBy.equals("newest")) return object2.getReleaseDate().compareTo(object1.getReleaseDate());
                else return object1.getReleaseDate().compareTo(object2.getReleaseDate());
            }
        });
    }
    return lis;
}