Example usage for java.util ArrayList remove

List of usage examples for java.util ArrayList remove

Introduction

In this page you can find the example usage for java.util ArrayList remove.

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes the first occurrence of the specified element from this list, if it is present.

Usage

From source file:com.sun.faces.lifecycle.LifecycleImpl.java

public void removePhaseListener(PhaseListener listener) {

    if (listener == null) {
        throw new NullPointerException(Util.getExceptionMessageString(Util.NULL_PARAMETERS_ERROR_MESSAGE_ID));
    }//from   w  ww . j  a v a2  s . c om
    if (log.isDebugEnabled()) {
        log.debug("removePhaseListener(" + listener.getPhaseId().toString() + "," + listener);
    }
    synchronized (listeners) {
        ArrayList temp = (ArrayList) listeners.clone();
        temp.remove(listener);
        listeners = temp;
    }

}

From source file:com.facebook.tsdb.tsdash.server.data.DataTable.java

@SuppressWarnings("unchecked")
private JSONArray generateRows() {
    // figure out the entire time series
    ArrayList<Long> timeSeries = new ArrayList<Long>();
    for (Metric metric : metrics) {
        for (TagsArray t : metric.timeSeries.keySet()) {
            timeSeries = TimeSeries.merge(timeSeries, metric.timeSeries.get(t));
        }/*from  w  w w  .  j  av a2s.  c  o  m*/
    }
    JSONObject nullCell = new JSONObject();
    JSONArray rows = new JSONArray();
    for (long ts : timeSeries) {
        JSONObject row = new JSONObject();
        JSONArray cells = new JSONArray();
        cells.add(newTsCell(ts));
        for (Metric metric : metrics) {
            for (TagsArray t : metric.timeSeries.keySet()) {
                ArrayList<DataPoint> points = metric.timeSeries.get(t);
                if (points.size() > 0 && points.get(0).ts == ts) {
                    cells.add(newDataCell(points.get(0).value));
                    points.remove(0);
                } else {
                    cells.add(nullCell);
                }
            }
        }
        row.put("c", cells);
        rows.add(row);
    }
    return rows;
}

From source file:sim.util.media.chart.TimeSeriesChartGenerator.java

public void moveSeries(int index, boolean up) {
    super.moveSeries(index, up);

    if ((index > 0 && up) || (index < getSeriesCount() - 1 && !up)) // it's not the first or the last given the move
    {//from w w w  .  j a  v  a2s.  c  o  m
        XYSeriesCollection xysc = (XYSeriesCollection) getSeriesDataset();
        // this requires removing everything from the dataset and resinserting, duh
        ArrayList items = new ArrayList(xysc.getSeries());
        xysc.removeAllSeries();

        int delta = up ? -1 : 1;
        // now rearrange
        items.add(index + delta, items.remove(index));

        // rebuild the dataset
        for (int i = 0; i < items.size(); i++)
            xysc.addSeries(((XYSeries) (items.get(i))));
    }
}

From source file:edu.gmu.cs.sim.util.media.chart.TimeSeriesChartGenerator.java

public void moveSeries(int index, boolean up) {
    super.moveSeries(index, up);

    if ((index > 0 && up) || (index < getSeriesCount() - 1 && !up)) // it's not the first or the last given the move
    {//from  w  w  w .  j  a  va 2s .c  om
        XYSeriesCollection xysc = (XYSeriesCollection) getSeriesDataset();
        // this requires removing everything from the dataset and resinserting, duh
        ArrayList items = new ArrayList(xysc.getSeries());
        xysc.removeAllSeries();

        int delta = up ? -1 : 1;
        // now rearrange
        items.add(index + delta, items.remove(index));

        // rebuild the dataset
        for (int i = 0; i < items.size(); i++) {
            xysc.addSeries(((XYSeries) (items.get(i))));
        }
    }
}

From source file:ee.ioc.cs.vsle.synthesize.SpecParser.java

/**
 * Reads a line from an arraylist of specification lines, removes it from
 * the arraylist and returns the line together with its type information
 * //  ww  w  .  j ava 2 s  .  co  m
 * @return a specification line with its type information
 * @param a arraylist of specification lines
 */
static LineType getLine(ArrayList<String> a) throws SpecParseException {
    Matcher matcher;

    while ((a.get(0)).equals("") || a.get(0).trim().startsWith("//")) {
        a.remove(0);
        if (a.isEmpty()) {
            return null;
        }
    }
    final String line = a.get(0);

    a.remove(0);
    if (line.startsWith("alias ")) {
        matcher = PATTERN_ALIAS_FULL.matcher(line);
        if (matcher.find()) {
            if (matcher.group(3).indexOf(".") > -1) {
                throw new SpecParseException(
                        "Alias " + matcher.group(3) + " cannot be declared with compound name");
            }

            LineType.Alias st = new LineType.Alias();
            st.setName(matcher.group(3));
            String vars = matcher.group(4).trim();
            st.setComponents(vars.length() == 0 ? new String[0] : vars.split(" *, *", -1));
            st.setComponentType((matcher.group(2) == null || matcher.group(2).equals("null") ? ""
                    : matcher.group(2).trim()));

            return new LineType(LineType.TYPE_ALIAS, st, line);
        }
        // allow empty alias declaration e.g. "alias x;"
        matcher = PATTERN_ALIAS_DECLARATION.matcher(line);
        if (matcher.find()) {
            if (matcher.group(3).indexOf(".") > -1) {
                throw new SpecParseException(
                        "Alias " + matcher.group(3) + " cannot be declared with compound name");
            }

            LineType.Alias st = new LineType.Alias();
            st.setName(matcher.group(3));
            st.setDeclaration(true);
            st.setComponentType((matcher.group(2) == null || matcher.group(2).equals("null") ? ""
                    : matcher.group(2).trim()));
            return new LineType(LineType.TYPE_ALIAS, st, line);
        }

        return new LineType(LineType.TYPE_ERROR, null, line);

    } else if (line.indexOf("super") >= 0 && (matcher = PATTERN_SUPERCLASSES.matcher(line)).find()) {
        LineType.Superclasses st = new LineType.Superclasses();
        st.setClassNames(matcher.group(1).split("#", -1));
        return new LineType(LineType.TYPE_SUPERCLASSES, st, line);

    } else if (line.trim().startsWith("const")) {
        matcher = PATTERN_CONSTANT.matcher(line);
        if (matcher.find()) {
            LineType.Constant st = new LineType.Constant();
            st.setName(matcher.group(2).trim());
            st.setType(matcher.group(1).trim());
            st.setValue(matcher.group(3).trim());
            return new LineType(LineType.TYPE_CONST, st, line);
        }
        return new LineType(LineType.TYPE_ERROR, null, line);

    } else if (line.indexOf("=") >= 0) { // Extract on solve
                                         // equations
                                         // lets check if it's an alias, e.g. x = [a,b,c];
        matcher = PATTERN_ALIAS_VARS.matcher(line);
        if (matcher.find()) {
            LineType.Alias st = new LineType.Alias();
            st.setName(matcher.group(1));
            String vars = matcher.group(2).trim();
            st.setComponents(vars.length() == 0 ? new String[0] : vars.split(" *, *", -1));
            st.setAssignment(true);

            return new LineType(LineType.TYPE_ALIAS, st, line);
        }

        matcher = PATTERN_ASSIGNMENT.matcher(line);
        if (matcher.find()) {
            LineType.Assignment st = new LineType.Assignment();
            st.setName(matcher.group(1));
            st.setValue(matcher.group(2));
            return new LineType(LineType.TYPE_ASSIGNMENT, st, line);
        }
        matcher = PATTERN_EQUATION.matcher(line);
        if (matcher.find()) {
            LineType.Equation st = new LineType.Equation();
            st.setEq(line);
            return new LineType(LineType.TYPE_EQUATION, st, line);
        }
        return new LineType(LineType.TYPE_ERROR, null, line);

    } else if (line.indexOf("->") >= 0) {
        //axiom
        matcher = PATTERN_AXIOM_FULL.matcher(line);
        if (matcher.find()) {
            LineType.Axiom st = new LineType.Axiom();

            //check for subtasks
            //FIXME - this pattern allows subtasks to be anywhere in the axiom, but they need to come before anything else
            Matcher subMatcher = PATTERN_AXIOM_SUBTASKS.matcher(line);

            while (subMatcher.find()) {
                String subtaskString = subMatcher.group(0);

                Matcher singleSubtaskMatcher = PATTERN_AXIOM_SUBTASK.matcher(subtaskString);

                if (singleSubtaskMatcher.find()) {
                    String context = singleSubtaskMatcher.group(2);
                    String[] subInputs = singleSubtaskMatcher.group(3).trim().split(" *, *", -1);
                    String[] subOutputs = singleSubtaskMatcher.group(4).trim().split(" *, *", -1);

                    st.getSubtasks().put(subtaskString,
                            new String[][] { new String[] { context }, subInputs, subOutputs });
                } else {
                    return new LineType(LineType.TYPE_ERROR, null, line);
                }
            }

            String newLine = line.replaceAll("\\[([^\\]\\[]*) *-> *([^\\]\\[]*)\\]", "#");

            matcher = PATTERN_AXIOM_FULL.matcher(newLine);

            if (matcher.find()) {
                String in = matcher.group(1).trim();
                st.setInputs(in.length() == 0 ? new String[0] : in.split(" *, *", -1));
                String out = matcher.group(2).trim();
                st.setOutputs(out.length() == 0 ? new String[0] : out.split(" *, *", -1));
                st.setMethod(matcher.group(3).trim());
            } else {
                return new LineType(LineType.TYPE_ERROR, null, line);
            }

            return new LineType(LineType.TYPE_AXIOM, st, line);
        }
        //specaxiom
        matcher = PATTERN_AXIOM_SPEC.matcher(line);

        if (matcher.find()) {
            LineType.Axiom st = new LineType.Axiom();
            st.setSpecAxiom(true);
            String in = matcher.group(1).trim();
            st.setInputs(in.length() == 0 ? new String[0] : in.split(" *, *", -1));
            String out = matcher.group(2).trim();
            st.setOutputs(out.length() == 0 ? new String[0] : out.split(" *, *", -1));
            return new LineType(LineType.TYPE_SPECAXIOM, st, line);

        }
        return new LineType(LineType.TYPE_ERROR, null, line);
    } else {
        matcher = PATTERN_DECLARATION.matcher(line);
        if (matcher.find()) {
            LineType.Declaration st = new LineType.Declaration();
            st.setStatic((matcher.group(1) != null));
            st.setType(matcher.group(2).trim());
            st.setNames(matcher.group(6).trim().split(" *, *", -1));
            return new LineType(LineType.TYPE_DECLARATION, st, line);
        }
        return new LineType(LineType.TYPE_ERROR, null, line);
    }
}

From source file:de.decidr.test.database.factories.EntityFactory.java

/**
 * Returns a subset containing numItems items of the given list, in random
 * order.//  ww w  . j a  v  a2s .  c  o  m
 * 
 * @param list
 *            must not be null
 * @param numItems
 *            must be positive
 * @return random subset
 */
@SuppressWarnings("unchecked")
public List getRandomList(List list, int numItems) {
    ArrayList result = new ArrayList(Math.min(list.size(), numItems));

    if (list.isEmpty()) {
        // nothing to do, return empty list
    } else if (list.size() == 1) {
        // (frequent) special case where the input list can serve as a
        // random pool
        result.add(list.get(rnd.nextInt(list.size())));
    } else {
        // create temporary shallow copy that serves as a random pool.
        ArrayList copy = new ArrayList(list.size());
        copy.addAll(list);

        for (int i = 0; i < numItems; i++) {
            result.add(copy.remove(rnd.nextInt(copy.size())));
        }

        copy.clear();
    }

    return result;
}

From source file:alpine.event.framework.BaseEventService.java

private synchronized void removeTrackedEvent(ChainableEvent event) {
    ArrayList<UUID> eventIdentifiers = chainTracker.get(event.getChainIdentifier());
    if (eventIdentifiers == null) {
        return;// w w w  .  ja  v a 2  s .co  m
    }
    eventIdentifiers.remove(event.getEventIdentifier());
    chainTracker.put(event.getChainIdentifier(), eventIdentifiers);
}

From source file:com.github.haixing_hu.bean.DefaultProperty.java

@Override
public final Object removeIndexedValue(final int index) {
    final ArrayList<Object> list = getIndexedValue();
    return list.remove(index);
}

From source file:eplic.core.breakpoint.BreakpointManager.java

/**
 * breakpoint set, normal setIS//w  w  w. j  ava  2s.co m
 * IS?NSbreakpoint
 * 
 * @param nor
 * @param rec
 * @return result set
 */
public ArrayList<ILineBreakpoint> diffResult(ArrayList<ILineBreakpoint> nor, ArrayList<ILineBreakpoint> rec) {
    for (ILineBreakpoint nm : nor) {
        while (rec.indexOf(nm) != -1) {
            rec.remove(nm);
        }
    }
    _result = new ArrayList<ILineBreakpoint>(rec.size());
    for (ILineBreakpoint b : rec) {
        _result.add(b);
    }
    return _result;
}

From source file:edu.oregonstate.eecs.mcplan.domains.spbj.SpBjAction.java

private void uncompleteDealerHand(final SpBjState s) {
    final ArrayList<Card> hand = s.dealerHand();
    while (hand.size() > 1) {
        s.deck().undeal(hand.remove(hand.size() - 1));
    }// ww  w  . ja  va2s  .  co m
    s.r = 0;
}