Commit a30d909a authored by tanyaocheng's avatar tanyaocheng

对侧边栏的分类标签加入了排序

parent 02375a01
...@@ -16,7 +16,10 @@ ...@@ -16,7 +16,10 @@
package org.b3log.solo.repository.impl; package org.b3log.solo.repository.impl;
import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import org.b3log.solo.model.Tag; import org.b3log.solo.model.Tag;
...@@ -32,6 +35,7 @@ import org.b3log.latke.repository.annotation.Repository; ...@@ -32,6 +35,7 @@ import org.b3log.latke.repository.annotation.Repository;
import org.b3log.latke.util.CollectionUtils; import org.b3log.latke.util.CollectionUtils;
import org.b3log.solo.repository.TagArticleRepository; import org.b3log.solo.repository.TagArticleRepository;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -45,6 +49,8 @@ import org.json.JSONObject; ...@@ -45,6 +49,8 @@ import org.json.JSONObject;
@Repository @Repository
public class TagRepositoryImpl extends AbstractRepository implements TagRepository { public class TagRepositoryImpl extends AbstractRepository implements TagRepository {
private final static Comparator<Object> CHINA_COMPARE = Collator.getInstance(java.util.Locale.CHINA);
/** /**
* Public constructor. * Public constructor.
*/ */
...@@ -80,7 +86,10 @@ public class TagRepositoryImpl extends AbstractRepository implements TagReposito ...@@ -80,7 +86,10 @@ public class TagRepositoryImpl extends AbstractRepository implements TagReposito
final JSONObject result = get(query); final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS); final JSONArray array = result.optJSONArray(Keys.RESULTS);
return CollectionUtils.jsonArrayToList(array); List<JSONObject> tagJoList = CollectionUtils.jsonArrayToList(array);
sortJSONTagList(tagJoList);
return tagJoList;
} }
@Override @Override
...@@ -107,4 +116,17 @@ public class TagRepositoryImpl extends AbstractRepository implements TagReposito ...@@ -107,4 +116,17 @@ public class TagRepositoryImpl extends AbstractRepository implements TagReposito
public void setTagArticleRepository(final TagArticleRepository tagArticleRepository) { public void setTagArticleRepository(final TagArticleRepository tagArticleRepository) {
this.tagArticleRepository = tagArticleRepository; this.tagArticleRepository = tagArticleRepository;
} }
private void sortJSONTagList(List<JSONObject> tagJoList) {
Collections.sort(tagJoList, new Comparator<JSONObject>() {
@Override
public int compare(JSONObject o1, JSONObject o2) {
try {
return CHINA_COMPARE.compare(o1.getString("tagTitle"), o2.getString("tagTitle"));
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
});
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment