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

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

Introduction

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

Prototype

boolean add(int element);

Source Link

Document

Appends the specified element to the end of me (optional operation).

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();
    }/*  w  w  w . j  a va2s  .com*/

    // 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.core.rsource.ast.RAst.java

public static int[] computeRExpressionIndex(RAstNode node, final RAstNode baseNode) {
    final IntList topdown = new ArrayIntList();
    while (node != baseNode) {
        final RAstNode parent = node.getRParent();
        switch (parent.getNodeType()) {

        // list//from ww w  . j  a v a  2 s .c o  m
        case SOURCELINES:
        case F_DEF_ARGS:
            // [[1]] = name
        case F_CALL:
            topdown.add(parent.getChildIndex(node) + 1);
            node = parent;
            continue;

        // [[1]] = operator
        case BLOCK:
        case GROUP:
        case SUB_INDEXED_S:
        case SUB_INDEXED_D:
        case NS_GET:
        case NS_GET_INT:
        case SUB_NAMED_PART:
        case SUB_NAMED_SLOT:
        case POWER:
        case SIGN:
        case SEQ:
        case SPECIAL:
        case MULT:
        case ADD:
        case RELATIONAL:
        case NOT:
        case AND:
        case OR:
        case MODEL:
        case A_RIGHT:
        case A_EQUALS:
        case A_LEFT:
        case HELP:
        case C_IF:
        case C_FOR:
        case C_WHILE:
        case C_REPEAT:
        case F_DEF:
            topdown.add(parent.getChildIndex(node) + 2);
            node = parent;
            continue;

        // part of parent element
        case SUB_INDEXED_ARGS:
            if (parent == baseNode) {
                break;
            }
            topdown.add(parent.getChildIndex(node) + 3);
            node = parent.getRParent();
            break;
        case C_IN:
        case F_CALL_ARGS:
            if (parent == baseNode) {
                break;
            }
            topdown.add(parent.getChildIndex(node) + 2);
            node = parent.getRParent();
            break;

        case SUB_INDEXED_ARG:
        case F_DEF_ARG:
        case F_CALL_ARG:
            node = parent;
            continue;

        case ERROR:
        case ERROR_TERM:
        case DUMMY:
            return null;

        default:
            throw new IllegalStateException("Unexpected parent");
        }
    }
    final int l = topdown.size();
    final int[] path = new int[l];
    for (int i = 0; i < l;) {
        path[i] = topdown.get(l - ++i);
    }
    return path;
}

From source file:de.unibayreuth.bayeos.goat.table.MassenTableModel.java

private void removeRows(int[] r) {
    ByteList stat = new ArrayByteList(r.length);
    IntList von = new ArrayIntList(r.length);
    DoubleList wert = new ArrayDoubleList(r.length);

    for (int i = 0; i < r.length; i++) {
        stat.add(statusList.get(r[i]));/*w  w  w. j  a va2  s  .co m*/
        von.add(vonList.get(r[i]));
        wert.add(wertList.get(r[i]));
    }
    statusList.removeAll(stat);
    vonList.removeAll(von);
    wertList.removeAll(wert);
}

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

/**
 * Set the preference's value(s) as its summary.
 *//*from  w w w.j  ava  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);
        }
    }
}

From source file:de.walware.statet.r.ui.RLabelProvider.java

public void appendArgumentInformation(final StringBuilder text, final IntList idxs, final ArgsDefinition args) {
     if (args != null) {
         if (args.size() == 0) {
             text.append("<no arguments>");
         } else {
             final int last = args.size() - 1;
             idxs.add(text.length());
             for (int i = 0; i < last; i++) {
                 appendArg(text, args.get(i));
                 text.append(", "); //$NON-NLS-1$
                 idxs.add(text.length() - 1);
             }/*w  w  w . j ava 2 s .c  o  m*/
             appendArg(text, args.get(last));
         }
     } else {
         text.append("<unkown>");
     }
 }

From source file:de.walware.docmlet.tex.internal.ui.editors.LtxCommandCompletionProposal.java

@Override
protected void doApply(final char trigger, final int stateMask, final int caretOffset,
        final int replacementOffset, final int replacementLength) throws BadLocationException {
    final ApplyData data = getApplyData();
    final IDocument document = data.getDocument();

    final StringBuilder replacement = new StringBuilder(fCommand.getControlWord());
    if ((stateMask & 0x1) == 0x1) {
        replacement.insert(0, '\\');
    }//from  w w  w  .  j  av  a  2 s. c o m
    int cursor = replacement.length();
    int mode = 0;
    IntList positions = null;
    if (fCommand == IEnvDefinitions.VERBATIM_verb_COMMAND) {
        mode = 201;
    } else if ((fCommand.getType() & TexCommand.MASK_MAIN) != TexCommand.ENV) {
        final List<Argument> args = fCommand.getArguments();
        if (args != null && !args.isEmpty()) {
            final boolean isFirstOptional = args.get(0).isOptional();
            int idxFirstRequired = -1;
            for (int i = (isFirstOptional) ? 1 : 0; i < args.size(); i++) {
                final Argument arg = args.get(i);
                if (arg.isRequired()) {
                    idxFirstRequired = i;
                    break;
                }
            }
            if (idxFirstRequired >= 0) {
                if (replacementOffset + replacementLength < document.getLength() - 1
                        && (document.getChar(replacementOffset + replacementLength) == '{' || (isFirstOptional
                                && document.getChar(replacementOffset + replacementLength) == '['))) {
                    cursor++;
                    mode = 10;
                } else if (!isFollowedByOpeningBracket(data, replacementOffset + replacementLength,
                        isFirstOptional)) {
                    replacement.append('{');
                    cursor++;
                    mode = 11;
                }
                if (mode >= 10) {
                    if (mode == 11 && !isClosedBracket(data, replacementOffset,
                            replacementOffset + replacementLength)) {
                        replacement.append('}');

                        positions = new ArrayIntList();
                        mode = 0;
                        if (isFirstOptional) {
                            positions.add(mode);
                        }
                        mode++;
                        positions.add(mode++);
                        for (int i = idxFirstRequired + 1; i < args.size(); i++) {
                            if (args.get(i).isRequired()) {
                                replacement.append("{}");
                                mode++;
                                positions.add(mode++);
                            } else if (positions.get(positions.size() - 1) != mode) {
                                positions.add(mode);
                            }
                        }
                        if (positions.get(positions.size() - 1) != mode) {
                            positions.add(mode);
                        }
                        mode = 110 + 1;
                        // add multiple arguments
                    }
                }
            }
        }
    }
    document.replace(replacementOffset, replacementLength, replacement.toString());
    setCursorPosition(replacementOffset + cursor);
    if (mode > 100 && mode < 200) {
        createLinkedMode(data, replacementOffset + cursor - (mode - 110), positions).enter();
    } else if (mode > 200 && mode < 300) {
        createLinkedVerbMode(data, replacementOffset + cursor);
    }
    if ((fCommand.getType() & TexCommand.MASK_MAIN) == TexCommand.GENERICENV) {
        reinvokeAssist(data.getViewer());
    }
}

From source file:org.apache.niolex.common.primitive.IntListMain.java

/**
 * @param args/*from  w  w w  .j  av a  2  s .  co m*/
 */
public static void main(String[] args) {
    StopWatch w = new StopWatch(1);
    w.begin(true);
    // This is slower!
    for (int i = 0; i < 1000; ++i) {
        IntList inList = new ArrayIntList(10000);
        Stop s = w.start();
        for (int j = 0; j < 10000; ++j) {
            inList.add(j);
        }
        s.stop();
    }
    w.done();
    w.print();
    // ------------
    w = new StopWatch(1);
    w.begin(true);
    for (int i = 0; i < 1000; ++i) {
        ArrayList<Integer> oList = new ArrayList<Integer>(10000);
        Stop s = w.start();
        for (int j = 0; j < 10000; ++j) {
            oList.add(j);
        }
        s.stop();
    }
    w.done();
    w.print();
}