Search in sources :

Example 81 with TreeMap

use of java.util.TreeMap in project ansj_seg by NLPchina.

the class CoreLibraryMaker method makeDic.

public static void makeDic() throws NumberFormatException, IOException {
    BufferedReader br = IOUtil.getReader("train_file/dic.txt", "utf-8");
    String temp = null;
    TreeMap<String, TreeMap<String, Integer>> dic = new TreeMap<String, TreeMap<String, Integer>>();
    while ((temp = br.readLine()) != null) {
        if (temp.indexOf('#') > -1) {
            continue;
        }
        temp = temp.replace(String.valueOf(((char) 0)), "");
        String[] split = temp.split("\t");
        if (dic.containsKey(split[1])) {
            if (dic.get(split[1]).containsKey(split[0])) {
                System.out.println("err");
            }
            dic.get(split[1]).put(split[0], Integer.parseInt(split[2]));
        } else {
            TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
            tm.put(split[0], Integer.parseInt(split[2]));
            dic.put(split[1], tm);
        }
    }
    IOUtil.writeMap(dic, "train_file/library.txt", IOUtil.UTF8);
}
Also used : BufferedReader(java.io.BufferedReader) TreeMap(java.util.TreeMap)

Example 82 with TreeMap

use of java.util.TreeMap in project CoCoin by Nightonke.

the class CustomViewFragment method select.

private void select() {
    if (RecordManager.getInstance(CoCoinApplication.getAppContext()).RECORDS == null || RecordManager.getInstance(CoCoinApplication.getAppContext()).RECORDS.size() == 0) {
        return;
    }
    start = -1;
    end = 0;
    Sum = 0;
    lastPieSelectedPosition = -1;
    if (from.after(RecordManager.RECORDS.get(RecordManager.RECORDS.size() - 1).getCalendar())) {
        return;
    }
    if (to.before(RecordManager.RECORDS.get(0).getCalendar())) {
        return;
    }
    for (int i = RecordManager.RECORDS.size() - 1; i >= 0; i--) {
        if (RecordManager.RECORDS.get(i).getCalendar().before(from)) {
            end = i + 1;
            break;
        } else if (RecordManager.RECORDS.get(i).getCalendar().before(to)) {
            if (start == -1) {
                start = i;
            }
        }
    }
    startDayCalendar = (Calendar) from.clone();
    startDayCalendar.set(Calendar.HOUR_OF_DAY, 0);
    startDayCalendar.set(Calendar.MINUTE, 0);
    startDayCalendar.set(Calendar.SECOND, 0);
    final long startDay = TimeUnit.MILLISECONDS.toDays(startDayCalendar.getTimeInMillis());
    final long days = TimeUnit.MILLISECONDS.toDays(to.getTimeInMillis()) - startDay + 1;
    TagExpanse = new TreeMap<>();
    Expanse = new HashMap<>();
    originalTargets = new float[(int) days];
    int size = RecordManager.TAGS.size();
    for (int j = 2; j < size; j++) {
        TagExpanse.put(RecordManager.TAGS.get(j).getId(), Double.valueOf(0));
        Expanse.put(RecordManager.TAGS.get(j).getId(), new ArrayList<CoCoinRecord>());
    }
    for (int i = start; i >= end; i--) {
        CoCoinRecord coCoinRecord = RecordManager.RECORDS.get(i);
        TagExpanse.put(coCoinRecord.getTag(), TagExpanse.get(coCoinRecord.getTag()) + Double.valueOf(coCoinRecord.getMoney()));
        Expanse.get(coCoinRecord.getTag()).add(coCoinRecord);
        Sum += coCoinRecord.getMoney();
        originalTargets[(int) (TimeUnit.MILLISECONDS.toDays(coCoinRecord.getCalendar().getTimeInMillis()) - startDay)] += coCoinRecord.getMoney();
    }
    expense.setText(CoCoinUtil.GetInMoney(Sum));
    emptyTip.setVisibility(View.GONE);
    TagExpanse = CoCoinUtil.SortTreeMapByValues(TagExpanse);
    final ArrayList<SliceValue> sliceValues = new ArrayList<>();
    for (Map.Entry<Integer, Double> entry : TagExpanse.entrySet()) {
        if (entry.getValue() >= 1) {
            SliceValue sliceValue = new SliceValue((float) (double) entry.getValue(), CoCoinUtil.GetTagColor(entry.getKey()));
            sliceValue.setLabel(String.valueOf(entry.getKey()));
            sliceValues.add(sliceValue);
        }
    }
    final PieChartData pieChartData = new PieChartData(sliceValues);
    pieChartData.setHasLabels(false);
    pieChartData.setHasLabelsOnlyForSelected(false);
    pieChartData.setHasLabelsOutside(false);
    pieChartData.setHasCenterCircle(SettingManager.getInstance().getIsHollow());
    pie.setPieChartData(pieChartData);
    pie.setChartRotationEnabled(false);
    pie.setVisibility(View.VISIBLE);
    iconRight.setVisibility(View.VISIBLE);
    iconRight.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (lastPieSelectedPosition != -1) {
                pieSelectedPosition = lastPieSelectedPosition;
            }
            pieSelectedPosition = (pieSelectedPosition - 1 + sliceValues.size()) % sliceValues.size();
            SelectedValue selectedValue = new SelectedValue(pieSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
            pie.selectValue(selectedValue);
        }
    });
    iconLeft.setVisibility(View.VISIBLE);
    iconLeft.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (lastPieSelectedPosition != -1) {
                pieSelectedPosition = lastPieSelectedPosition;
            }
            pieSelectedPosition = (pieSelectedPosition + 1) % sliceValues.size();
            SelectedValue selectedValue = new SelectedValue(pieSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
            pie.selectValue(selectedValue);
        }
    });
    // set value touch listener of pie//////////////////////////////////////////////////////////////////
    dateShownString = mContext.getResources().getString(R.string.from) + " " + CoCoinUtil.GetMonthShort(from.get(Calendar.MONTH) + 1) + " " + from.get(Calendar.DAY_OF_MONTH) + " " + from.get(Calendar.YEAR) + " " + mContext.getResources().getString(R.string.to) + " " + CoCoinUtil.GetMonthShort(to.get(Calendar.MONTH) + 1) + " " + to.get(Calendar.DAY_OF_MONTH) + " " + to.get(Calendar.YEAR);
    pie.setOnValueTouchListener(new PieChartOnValueSelectListener() {

        @Override
        public void onValueSelected(int p, SliceValue sliceValue) {
            // snack bar
            String text;
            tagId = Integer.valueOf(String.valueOf(sliceValue.getLabelAsChars()));
            double percent = sliceValue.getValue() / Sum * 100;
            if ("zh".equals(CoCoinUtil.GetLanguage())) {
                text = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + CoCoinUtil.GetPercentString(percent) + "\n" + "于" + CoCoinUtil.GetTagName(tagId);
            } else {
                text = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " (takes " + String.format("%.2f", percent) + "%)\n" + "in " + CoCoinUtil.GetTagName(tagId);
            }
            if ("zh".equals(CoCoinUtil.GetLanguage())) {
                dialogTitle = dateShownString + "\n" + CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " " + "于" + CoCoinUtil.GetTagName(tagId);
            } else {
                dialogTitle = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " " + mContext.getResources().getString(R.string.from) + " " + CoCoinUtil.GetMonthShort(from.get(Calendar.MONTH) + 1) + " " + from.get(Calendar.DAY_OF_MONTH) + " " + from.get(Calendar.YEAR) + "\n" + mContext.getResources().getString(R.string.to) + " " + CoCoinUtil.GetMonthShort(to.get(Calendar.MONTH) + 1) + " " + to.get(Calendar.DAY_OF_MONTH) + " " + to.get(Calendar.YEAR) + " " + "in " + CoCoinUtil.GetTagName(tagId);
            }
            Snackbar snackbar = Snackbar.with(mContext).type(SnackbarType.MULTI_LINE).duration(Snackbar.SnackbarDuration.LENGTH_SHORT).position(Snackbar.SnackbarPosition.BOTTOM).margin(15, 15).backgroundDrawable(CoCoinUtil.GetSnackBarBackground(-3)).text(text).textTypeface(CoCoinUtil.GetTypeface()).textColor(Color.WHITE).actionLabelTypeface(CoCoinUtil.GetTypeface()).actionLabel(mContext.getResources().getString(R.string.check)).actionColor(Color.WHITE).actionListener(new mActionClickListenerForPie());
            SnackbarManager.show(snackbar);
            if (p == lastPieSelectedPosition) {
                return;
            } else {
                lastPieSelectedPosition = p;
            }
        }

        @Override
        public void onValueDeselected() {
        }
    });
    all.setVisibility(View.VISIBLE);
    all.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            List<CoCoinRecord> data = new LinkedList<CoCoinRecord>();
            for (int i = start; i >= end; i--) data.add(RecordManager.RECORDS.get(i));
            if ("zh".equals(CoCoinUtil.GetLanguage())) {
                dialogTitle = dateShownString + "\n" + CoCoinUtil.GetSpendString(Sum) + "于" + CoCoinUtil.GetTagName(tagId);
            } else {
                dialogTitle = CoCoinUtil.GetSpendString(Sum) + " " + mContext.getResources().getString(R.string.from) + " " + CoCoinUtil.GetMonthShort(from.get(Calendar.MONTH) + 1) + " " + from.get(Calendar.DAY_OF_MONTH) + " " + from.get(Calendar.YEAR) + "\n" + mContext.getResources().getString(R.string.to) + " " + CoCoinUtil.GetMonthShort(to.get(Calendar.MONTH) + 1) + " " + to.get(Calendar.DAY_OF_MONTH) + " " + to.get(Calendar.YEAR) + " " + "in " + CoCoinUtil.GetTagName(tagId);
            }
            ((FragmentActivity) mContext).getSupportFragmentManager().beginTransaction().add(new RecordCheckDialogFragment(mContext, data, dialogTitle), "MyDialog").commit();
        }
    });
}
Also used : ArrayList(java.util.ArrayList) SliceValue(lecho.lib.hellocharts.model.SliceValue) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) SelectedValue(lecho.lib.hellocharts.model.SelectedValue) PieChartData(lecho.lib.hellocharts.model.PieChartData) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) View(android.view.View) PieChartView(lecho.lib.hellocharts.view.PieChartView) TextView(android.widget.TextView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) CoCoinRecord(com.nightonke.saver.model.CoCoinRecord) PieChartOnValueSelectListener(lecho.lib.hellocharts.listener.PieChartOnValueSelectListener) FragmentActivity(android.support.v4.app.FragmentActivity) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Snackbar(com.nispok.snackbar.Snackbar)

Example 83 with TreeMap

use of java.util.TreeMap in project CoCoin by Nightonke.

the class CoCoinUtil method SortTreeMapByValues.

public static <K, V extends Comparable<V>> Map<K, V> SortTreeMapByValues(final Map<K, V> map) {
    Comparator<K> valueComparator = new Comparator<K>() {

        public int compare(K k1, K k2) {
            int compare = map.get(k1).compareTo(map.get(k2));
            if (compare == 0)
                return 1;
            else
                return compare;
        }
    };
    TreeMap<K, V> sortedByValues = new TreeMap<K, V>(valueComparator);
    sortedByValues.putAll(map);
    return sortedByValues;
}
Also used : TreeMap(java.util.TreeMap) Point(android.graphics.Point) Comparator(java.util.Comparator)

Example 84 with TreeMap

use of java.util.TreeMap in project android_frameworks_base by ParanoidAndroid.

the class AsmAnalyzer method parseZip.

/**
     * Parses a JAR file and returns a list of all classes founds using a map
     * class name => ASM ClassReader. Class names are in the form "android.view.View".
     */
Map<String, ClassReader> parseZip(List<String> jarPathList) throws IOException {
    TreeMap<String, ClassReader> classes = new TreeMap<String, ClassReader>();
    for (String jarPath : jarPathList) {
        ZipFile zip = new ZipFile(jarPath);
        Enumeration<? extends ZipEntry> entries = zip.entries();
        ZipEntry entry;
        while (entries.hasMoreElements()) {
            entry = entries.nextElement();
            if (entry.getName().endsWith(".class")) {
                ClassReader cr = new ClassReader(zip.getInputStream(entry));
                String className = classReaderToClassName(cr);
                classes.put(className, cr);
            }
        }
    }
    return classes;
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ClassReader(org.objectweb.asm.ClassReader) TreeMap(java.util.TreeMap)

Example 85 with TreeMap

use of java.util.TreeMap in project android_frameworks_base by ParanoidAndroid.

the class AsmGenerator method generate.

/** Generates the final JAR */
public void generate() throws FileNotFoundException, IOException {
    TreeMap<String, byte[]> all = new TreeMap<String, byte[]>();
    for (Class<?> clazz : mInjectClasses) {
        String name = classToEntryPath(clazz);
        InputStream is = ClassLoader.getSystemResourceAsStream(name);
        ClassReader cr = new ClassReader(is);
        byte[] b = transform(cr, true);
        name = classNameToEntryPath(transformName(cr.getClassName()));
        all.put(name, b);
    }
    for (Entry<String, ClassReader> entry : mDeps.entrySet()) {
        ClassReader cr = entry.getValue();
        byte[] b = transform(cr, true);
        String name = classNameToEntryPath(transformName(cr.getClassName()));
        all.put(name, b);
    }
    for (Entry<String, ClassReader> entry : mKeep.entrySet()) {
        ClassReader cr = entry.getValue();
        byte[] b = transform(cr, true);
        String name = classNameToEntryPath(transformName(cr.getClassName()));
        all.put(name, b);
    }
    mLog.info("# deps classes: %d", mDeps.size());
    mLog.info("# keep classes: %d", mKeep.size());
    mLog.info("# renamed     : %d", mRenameCount);
    createJar(new FileOutputStream(mOsDestJar), all);
    mLog.info("Created JAR file %s", mOsDestJar);
}
Also used : InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ClassReader(org.objectweb.asm.ClassReader) TreeMap(java.util.TreeMap)

Aggregations

TreeMap (java.util.TreeMap)4400 Map (java.util.Map)1245 ArrayList (java.util.ArrayList)930 HashMap (java.util.HashMap)871 Test (org.junit.Test)614 List (java.util.List)542 Before (org.junit.Before)505 IOException (java.io.IOException)402 HashSet (java.util.HashSet)301 Set (java.util.Set)268 File (java.io.File)267 SortedMap (java.util.SortedMap)240 TreeSet (java.util.TreeSet)213 LinkedHashMap (java.util.LinkedHashMap)196 Key (org.apache.accumulo.core.data.Key)156 Value (org.apache.accumulo.core.data.Value)156 Iterator (java.util.Iterator)149 NavigableMap (java.util.NavigableMap)124 Collection (java.util.Collection)115 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)111