Example usage for org.apache.commons.collections.primitives IntList toArray

List of usage examples for org.apache.commons.collections.primitives IntList toArray

Introduction

In this page you can find the example usage for org.apache.commons.collections.primitives IntList toArray.

Prototype

int[] toArray();

Source Link

Document

Returns an array containing all of my elements.

Usage

From source file:com.martinkampjensen.thesis.barriers.neighborhood.AbstractNeighborhood.java

public static final int[][] calculateNeighbors(List<Model> models, Neighborhood neighborhood,
        double maxDistance, boolean allowDebugPrints) {
    final int nModels = models.size();
    final IntList[] lists = new ArrayIntList[nModels];
    final int[][] arrays = new int[nModels][];

    for (int i = 0; i < nModels; i++) {
        lists[i] = new ArrayIntList();
    }//from   w  ww. j  a v a  2  s  .co m

    // For status.
    final long calculationsTotal = (long) nModels * (nModels - 1) / 2;
    final boolean performStatus = (calculationsTotal >= 2500000);
    final long calculationsTwentieth = Math.max(1, (long) Math.floor(calculationsTotal / 20d));
    long calculationsMilestone = calculationsTwentieth;
    long calculationsDone = 0;
    if (performStatus)
        System.err.print("Neighbors calculated: [0%");

    for (int i = 0; i < nModels; i++) {
        final IntList list = lists[i];
        final Model first = models.get(i);

        for (int j = i + 1; j < nModels; j++) {
            final Model second = models.get(j);

            if (neighborhood.isNeighbors(first, second, maxDistance)) {
                list.add(j);
                lists[j].add(i);
            }
        }

        arrays[i] = list.toArray();
        lists[i] = null; // For garbage collection.

        // For status.
        if (performStatus) {
            calculationsDone += nModels - 1 - i;
            if (calculationsDone >= calculationsMilestone && i != nModels - 1) {
                System.err.print("..." + (int) (100 * calculationsDone / (double) calculationsTotal) + "%");
                if (calculationsDone == calculationsTotal)
                    System.err.println("]");
                while (calculationsDone >= calculationsMilestone)
                    calculationsMilestone += calculationsTwentieth;
                calculationsMilestone = Math.min(calculationsMilestone, calculationsTotal);
            }
        }
    }

    if (allowDebugPrints)
        calculateNeighborMeasures(arrays);
    return arrays;
}

From source file:de.walware.statet.r.internal.ui.editors.RArgumentListContextInformation.java

public RArgumentListContextInformation(final int offset, final IRMethod method) {
    fOffset = offset;/*from  w  w  w.j a v a  2  s .c  om*/
    fArgs = method.getArgsDefinition();
    final StringBuilder sb = new StringBuilder();
    final IntList idxs = new ArrayIntList();
    new RLabelProvider().appendArgumentInformation(sb, idxs, fArgs);
    fInformation = sb.toString();
    fInformationIndexes = idxs.toArray();
}

From source file:net.sf.sprockets.app.ui.SprocketsPreferenceFragment.java

/**
 * Set the preference's value(s) as its summary.
 */// w ww  . j  a  v a 2s.c o  m
protected void setSummary(Preference pref) {
    SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
    if (pref instanceof RingtonePreference) {
        String val = prefs.getString(pref.getKey(), null);
        if (!TextUtils.isEmpty(val)) {
            Ringtone tone = RingtoneManager.getRingtone(a, Uri.parse(val));
            if (tone != null) {
                pref.setSummary(tone.getTitle(a));
            }
        } else {
            pref.setSummary(R.string.none);
        }
    } else if (pref instanceof MultiSelectListPreference) {
        Set<String> vals = prefs.getStringSet(pref.getKey(), null);
        if (vals != null) {
            if (!vals.isEmpty()) {
                MultiSelectListPreference multi = (MultiSelectListPreference) pref;
                IntList indexList = new ArrayIntList(vals.size());
                for (String val : vals) { // find selected entry indexes
                    int i = multi.findIndexOfValue(val);
                    if (i >= 0) {
                        indexList.add(i);
                    }
                }
                int[] indexes = indexList.toArray();
                Arrays.sort(indexes); // to display in same order as dialog
                pref.setSummary(TextUtils.join(getString(R.string.delimiter),
                        Elements.slice(multi.getEntries(), indexes)));
            } else {
                pref.setSummary(R.string.none);
            }
        }
    } else if (pref instanceof EditTextPreference) {
        pref.setSummary(prefs.getString(pref.getKey(), null));
    } else if (pref.getClass() == Preference.class) {
        String val = prefs.getString(pref.getKey(), null);
        if (!TextUtils.isEmpty(val)) { // don't clear existing summary
            pref.setSummary(val);
        }
    }
}