Commit fcad963f authored by Liang Ding's avatar Liang Ding

🎨 清理代码 & 重构

parent e537917c
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository.impl;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -38,18 +37,21 @@ import org.json.JSONArray; ...@@ -38,18 +37,21 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Tag repository. * Tag repository.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.1.1, Nov 29, 2011 * @version 1.1.1.1, Nov 23, 2016
* @since 0.3.1 * @since 0.3.1
*/ */
@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); /**
* Tag-Article relation repository.
*/
@Inject
private TagArticleRepository tagArticleRepository;
/** /**
* Public constructor. * Public constructor.
...@@ -58,12 +60,6 @@ public class TagRepositoryImpl extends AbstractRepository implements TagReposito ...@@ -58,12 +60,6 @@ public class TagRepositoryImpl extends AbstractRepository implements TagReposito
super(Tag.TAG); super(Tag.TAG);
} }
/**
* Tag-Article relation repository.
*/
@Inject
private TagArticleRepository tagArticleRepository;
@Override @Override
public JSONObject getByTitle(final String tagTitle) throws RepositoryException { public JSONObject getByTitle(final String tagTitle) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Tag.TAG_TITLE, FilterOperator.EQUAL, tagTitle)).setPageCount(1); final Query query = new Query().setFilter(new PropertyFilter(Tag.TAG_TITLE, FilterOperator.EQUAL, tagTitle)).setPageCount(1);
...@@ -117,13 +113,14 @@ public class TagRepositoryImpl extends AbstractRepository implements TagReposito ...@@ -117,13 +113,14 @@ public class TagRepositoryImpl extends AbstractRepository implements TagReposito
this.tagArticleRepository = tagArticleRepository; this.tagArticleRepository = tagArticleRepository;
} }
private void sortJSONTagList(List<JSONObject> tagJoList) { private void sortJSONTagList(final List<JSONObject> tagJoList) throws RepositoryException {
Collections.sort(tagJoList, new Comparator<JSONObject>() { Collections.sort(tagJoList, new Comparator<JSONObject>() {
@Override @Override
public int compare(JSONObject o1, JSONObject o2) { public int compare(final JSONObject o1, final JSONObject o2) {
try { try {
return CHINA_COMPARE.compare(o1.getString("tagTitle"), o2.getString("tagTitle")); return Collator.getInstance(java.util.Locale.CHINA)
} catch (JSONException e) { .compare(o1.getString(Tag.TAG_TITLE), o2.getString(Tag.TAG_TITLE));
} catch (final JSONException e) {
throw new RuntimeException(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