本文整理汇总了Java中org.apache.commons.lang.StringUtils.reverse方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.reverse方法的具体用法?Java StringUtils.reverse怎么用?Java StringUtils.reverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.StringUtils
的用法示例。
在下文中一共展示了StringUtils.reverse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: musicGetInfoItunes
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
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;
}
示例2: trimFileExtension
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private static String trimFileExtension(String s){
String rev=StringUtils.reverse(s);
if (s.contains(".")) {
return StringUtils.reverse(rev.substring(rev.indexOf(".")));
}
else return s;
}