Back to project page Alfred4Android.
The source code is released under:
Apache License
If you think the Android project Alfred4Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.toraleap.collimator.data; /*from www . j ava 2 s. c o m*/ import java.util.ArrayList; import java.util.Comparator; import java.util.List; import org.json.JSONException; import org.json.JSONObject; import android.content.Context; import com.toraleap.collimator.R; /** * ?????????????????????????????????????????????????JSON????????????JSON?????????? * @author uestc.Mobius <mobius@toraleap.com> * @version 2010.1015 */ public final class Expression { private Context mContext; private int mRange; private int mSortMode = Sorter.SORT_DATE; private boolean mSortReverse = true; private String mKey = ""; private String mName; /** * ??????????????????? * @param context ??????????? */ public Expression(Context context) { mContext = context; } /** * ?????JSON??????????????????? * @param context ??????????? * @param json JSON????????? */ public Expression(Context context, String json) { this(context); try { JSONObject obj = new JSONObject(json); mName = obj.optString("name"); mRange = obj.optInt("range"); mSortMode = obj.optInt("sortMode"); mSortReverse = obj.optBoolean("sortReverse"); mKey = obj.optString("key"); } catch (JSONException e) { e.printStackTrace(); } } /** * ????????????????? * @return ????? */ public Comparator<Match> getSorter() { return Sorter.getSorter(mSortMode, mSortReverse); } /** * ????????????????(???????Sorter????)?? * @return ????????? */ public int getSortMode() { return mSortMode; } /** * ????????????????? * @return ????? */ public boolean getSortReverse() { return mSortReverse; } /** * ??????????????????(???array.xml??)?? * @return ??????????? */ public int getRange() { return mRange; } /** * ????????????????????? * @return ?????????? */ public String getKey() { return mKey; } /** * ???????????????? * @return ????????? */ public String getName() { if (mName == null) return mKey; return mName; } /** * ????????????????? * @param sortMode ?????(???????Sorter????) * @param reverse ????? */ public void setSort(int sortMode, boolean reverse) { mSortMode = sortMode; mSortReverse = reverse; } /** * ????????????????? * @param sortMode ?????(???????Sorter????) */ public void setSort(int sortMode) { mSortMode = sortMode; } /** * ????????????????? * @param reverse ????? */ public void setSort(boolean reverse) { mSortReverse = reverse; } /** * ?????????????????(???array.xml??)?? * @param range ??????????? */ public void setRange(int range) { mRange = range; } /** * ???????????????????? * @param key ?????????? */ public void setKey(String key) { mKey = key; } /** * ??????????????? * @return ????????? */ public void setName(String name) { mName = name; } /** * ??????????????????????????????????????? Matcher ??????????????????????????????? Matcher.init ??????????????????????????????????????????????????????????????????????? */ public void matchAsync() { Matcher.matchAsync(matchers()); } /** * ??????????????????????????? Matcher ????????????????????????????????? Matcher ????????? null?? * @return ???????? Matcher ???? ?? null */ public Matcher[] matchers() { String[] keys = mKey.split(" "); List<Matcher> matchers = new ArrayList<Matcher>(keys.length + 1); try { if (mRange > 0) { matchers.add(new Matcher(mContext.getResources().getStringArray(R.array.dialog_filter_range_entriesvalue)[mRange])); } for (int i = 0; i < keys.length; i++) { matchers.add(new Matcher(keys[i])); } return matchers.toArray(new Matcher[matchers.size()]); } catch (Exception e) { e.printStackTrace(); return null; } } /** * ???????????JSON?????????????? * @return JSON????????? */ public String toJSON() { JSONObject obj = new JSONObject(); try { obj.put("name", mName); obj.put("range", mRange); obj.put("sortMode", mSortMode); obj.put("sortReverse", mSortReverse); obj.put("key", mKey); } catch (JSONException e) { e.printStackTrace(); } return obj.toString(); } }