Example usage for java.util ArrayList clone

List of usage examples for java.util ArrayList clone

Introduction

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

Prototype

public Object clone() 

Source Link

Document

Returns a shallow copy of this ArrayList instance.

Usage

From source file:pltag.parser.Chart.java

@SuppressWarnings("unchecked")
private ArrayList<BuildBlock> combineRestrictList(ArrayList<BuildBlock> arrayList,
        ArrayList<BuildBlock> arrayList2) {
    if (arrayList == null) {
        return arrayList2;
    }//w ww.j a v  a2  s  .  c o  m
    if (arrayList2 == null) {
        return arrayList;
    }
    ArrayList<BuildBlock> alc = (ArrayList<BuildBlock>) arrayList.clone();
    alc.addAll(arrayList2);
    return alc;
}

From source file:com.bailen.radioOnline.servlet.servlet.java

@RequestMapping(value = "/artistasFav", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody ModelAndView artistasFav() {

    ModelAndView model = new ModelAndView("identificado");
    if (!banderaPlus) {
        try {/*  w ww.  j a va2s  . c o  m*/
            backward = "artistasFav";
            ArrayList<Cancion> canciones = new ArrayList<>();
            Cancion[] inter = reja.artistFav(usuario.getApiKey());
            if (inter.length == 0) {
                inter = reja.random(usuario.getApiKey());
            }
            for (int i = 0; i < inter.length; ++i) {
                canciones.add(inter[i]);
            }
            model.addObject("canciones", canciones);
            canc = (ArrayList<Cancion>) canciones.clone();
            cancActual = 0;
            model.addObject("actual", cancActual);
            model.addObject("usuario", usuario);
            model.addObject("persona", persona);
            model.addObject("puntuaciones", puntuaciones);
            return model;
        } catch (Exception e) {
            model = new ModelAndView("errorPage");
            model.addObject("error", e.getMessage());
            return model;
        }
    } else {
        try {
            backward = "artistasFav";
            banderaPlus = false;
            ArrayList<Cancion> canciones = new ArrayList<>();
            Cancion[] inter = reja.artistFav(usuario.getApiKey());
            if (inter.length == 0) {
                inter = reja.random(usuario.getApiKey());
            }
            for (int i = 0; i < inter.length; ++i) {
                canciones.add(inter[i]);
            }
            for (int i = 0; i < canciones.size(); ++i) {
                canc.add(canciones.get(i));
            }
            model.addObject("actual", cancActual);
            model.addObject("usuario", usuario);
            model.addObject("persona", persona);
            model.addObject("canciones", canc);
            model.addObject("puntuaciones", puntuaciones);

            return model;
        } catch (Exception e) {
            model = new ModelAndView("errorPage");
            model.addObject("error", e.getMessage());
            return model;
        }
    }

}

From source file:com.bailen.radioOnline.servlet.servlet.java

@RequestMapping(value = "/favourites", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody ModelAndView favourites() {

    ModelAndView model = new ModelAndView("identificado");
    if (!banderaPlus) {
        backward = "favourites";
        try {/* w w  w  . j a v  a 2 s .  com*/
            ArrayList<Cancion> canciones = new ArrayList<>();
            Cancion[] inter = reja.favourites(usuario.getApiKey());
            if (inter.length == 0) {
                inter = reja.random(usuario.getApiKey());
            }
            for (int i = 0; i < inter.length; ++i) {
                canciones.add(inter[i]);
            }
            model.addObject("canciones", canciones);
            canc = (ArrayList<Cancion>) canciones.clone();
            cancActual = 0;
            model.addObject("actual", cancActual);
            model.addObject("usuario", usuario);
            model.addObject("persona", persona);
            model.addObject("puntuaciones", puntuaciones);
            return model;
        } catch (Exception e) {
            model = new ModelAndView("errorPage");
            model.addObject("error", e.getMessage());
            return model;
        }
    } else {
        try {
            backward = "favourites";
            banderaPlus = false;
            ArrayList<Cancion> canciones = new ArrayList<>();
            Cancion[] inter = reja.favourites(usuario.getApiKey());
            if (inter.length == 0) {
                inter = reja.random(usuario.getApiKey());
            }
            for (int i = 0; i < inter.length; ++i) {
                canciones.add(inter[i]);
            }
            for (int i = 0; i < canciones.size(); ++i) {
                canc.add(canciones.get(i));
            }
            model.addObject("actual", cancActual);
            model.addObject("usuario", usuario);
            model.addObject("persona", persona);
            model.addObject("canciones", canc);
            model.addObject("puntuaciones", puntuaciones);

            return model;
        } catch (Exception e) {
            model = new ModelAndView("errorPage");
            model.addObject("error", e.getMessage());
            return model;
        }
    }

}

From source file:de.tuebingen.uni.sfs.germanet.api.GermaNet.java

/**
 * Returns a <code>List</code> of all <code>LexUnits</code> in the specified
 * <code>wordCategory</code>.
 * @param wordCategory the <code>WordCategory</code>, (e.g.
 * <code>WordCategory.verben</code>)
 * @return a <code>List</code> of all <code>LexUnits</code> in the specified
 * <code>wordCategory</code>. If no <code>LexUnits</code> were found, this
 * is a <code>List</code> containing no <code>LexUnits</code>.
 *//* w  w w  .  ja  v a  2  s.co  m*/
public List<LexUnit> getLexUnits(WordCategory wordCategory) {
    ArrayList<LexUnit> rval = new ArrayList<LexUnit>();
    HashMap<String, ArrayList<LexUnit>> map;
    map = wordCategoryMap.get(wordCategory);

    for (ArrayList<LexUnit> luList : map.values()) {
        rval.addAll((ArrayList<LexUnit>) luList.clone());
    }
    rval.trimToSize();
    return rval;
}

From source file:org.opencyc.constraintsolver.ForwardCheckingSearcher.java

/**
 * Returns the number of constraint rules applicable to variable and one or more
 * of the other variables./*from  w ww .  j  a va  2 s  . c o  m*/
 *
 * @param variable the variable which must be used in the counted constraint rules
 * @param variables the counted constraint rules must use only these variables and no others.
 * @return the number of constraint rules applicable to variable and one or more
 * of the other variables
 */
protected int constraintDegree(CycVariable variable, ArrayList variables) {
    int degree = 0;
    ArrayList ruleVariables = null;
    for (int i = 0; i < constraintProblem.constraintRules.size(); i++) {
        ConstraintRule rule = (ConstraintRule) constraintProblem.constraintRules.get(i);
        ruleVariables = rule.getVariables();
        if (ruleVariables.contains(variable) && variables.containsAll(ruleVariables)) {
            degree++;
            if (verbosity > 8) {
                ArrayList candidateVariables = (ArrayList) variables.clone();
                candidateVariables.remove(variable);
                System.out.println("ConstraintRule " + rule.cyclify() + "\n  between " + variable
                        + " and candidate variables " + candidateVariables);
            }
        }
    }
    if (verbosity > 8)
        System.out.println("Constraint degree for " + variable + " is " + degree);
    return degree;
}

From source file:de.stkl.gbgvertretungsplan.sync.SyncAdapter.java

private List<List<String>> parseRows(Element root) {
    Element table = root.select("table.mon_list").first();
    // each row has categories.size() categories, build a two dimensional array:
    // <row-index><category-index> = <value>
    // rows[0] is the name of the class, if multiple classes are set there, split them (separator: ,)
    List<List<String>> allRows = new ArrayList<List<String>>();
    Elements rows = table.select("tr:gt(0)");
    for (Element row : rows) {
        int i = 0;
        ArrayList<String> newrow = new ArrayList<String>();

        String[] pendingClasses = null;
        // each category
        for (Element categ : row.select("td")) {
            if (i == 0) { // split class field by separator(,) if needed
                String text = categ.text();
                pendingClasses = text.split(",");
            }/*from   ww  w. j av  a 2s  .  c om*/
            // dont add class if multiple classes are given
            if (i != 0 || (pendingClasses == null || pendingClasses.length == 0))
                newrow.add(categ.text());
            //                Log.i(LOG_TAG, categ.text());
            i++;
        }

        // add row with category info to allRows array, if not multiple classes
        if (pendingClasses == null || pendingClasses.length == 0)
            allRows.add(newrow);
        // otherwise set class names to multiple rows
        else {
            for (String classN : pendingClasses) {
                ArrayList<String> n = (ArrayList<String>) newrow.clone();
                n.add(0, classN.trim());
                allRows.add(n);
            }
        }
    }

    return allRows;
}

From source file:userinterface.properties.GUIGraphPicker.java

/** Creates new form GUIGraphPicker 
 *    @wbp.parser.constructor//from  www.ja  va  2s .c  om
 * @param parent The parent.
 * @param plugin The GUIPlugin (GUIMultiProperties)
 * @param experiment The experiment for which to plot a graph.
 * @param graphHandler The graph handler in which to display the graph.
 * @param resultsKnown If true, simply plot existing results (experiment has been done). 
 * If false, attach listeners to the results such that plot is made when results become available.
 */

public GUIGraphPicker(GUIPrism parent, GUIPlugin plugin, GUIExperiment experiment, GUIGraphHandler graphHandler,
        boolean resultsKnown) {
    super(parent, true);
    setTitle("New Graph Series");

    this.gui = parent;
    this.plugin = plugin;

    this.experiment = experiment;
    this.graphHandler = graphHandler;
    this.resultsCollection = experiment.getResults();

    // graphCancelled will be set explicitly to false when the OK button is pressed
    // (this means if the user closes the dialog, this counts as a cancel)
    this.graphCancelled = true;

    this.multiSeries = new Vector<DefinedConstant>();

    initComponents();
    setResizable(false);

    init();
    setLocationRelativeTo(getParent()); // centre
    getRootPane().setDefaultButton(lineOkayButton);

    /* Wait untill OK or Cancel is pressed. */
    setVisible(true);

    /* If OK was pressed. */
    if (!graphCancelled && this.plotType2d.isSelected()) {
        /* Collect series keys. */
        Vector<SeriesKey> seriesKeys = new Vector<SeriesKey>();

        /* Collect series Values */
        ArrayList<Values> seriesValues = new ArrayList<Values>();

        /* Add single constant values to each serie */
        seriesValues.add(otherValues);

        for (int i = 0; i < multiSeries.size(); i++) {
            ArrayList<Values> temp = (ArrayList<Values>) seriesValues.clone();
            seriesValues.clear();

            // For each of the possible value in the range
            for (int j = 0; j < multiSeries.get(i).getNumSteps(); j++) {
                // Clone the list
                ArrayList copy = (ArrayList<Values>) temp.clone();

                // For each element in the list
                for (int k = 0; k < copy.size(); k++) {
                    Values v = new Values();
                    Values cp = (Values) copy.get(k);
                    v.addValues(cp);
                    v.addValue(multiSeries.get(i).getName(), multiSeries.get(i).getValue(j));
                    seriesValues.add(v);
                }
            }
        }

        /* Do all series settings. */
        for (int serie = 0; serie < seriesValues.size(); serie++) //each combination of series
        {
            Values values = seriesValues.get(serie);
            String seriesName = (seriesValues.size() > 1) ? values.toString() : seriesNameField.getText();
            // For properties that return an interval, we add a pair of series
            // (the pair is stored as a linked list)
            if (experiment.getPropertyType() instanceof TypeInterval) {
                SeriesKey key = graphModel2D.addSeries(seriesName + " (min)");
                key.next = graphModel2D.addSeries(seriesName + " (max)");
                seriesKeys.add(key);
            } else {
                seriesKeys.add(graphModel2D.addSeries(seriesName));
            }
        }

        /* If there are results already, then lets render them! */
        if (resultsKnown && resultsCollection.getCurrentIteration() > 0) {
            for (int series = 0; series < seriesValues.size(); series++) //each combination of series
            {
                Values values = seriesValues.get(series);
                SeriesKey seriesKey = seriesKeys.get(series);

                /** Range over x-axis. */
                for (int i = 0; i < rangingConstantX.getNumSteps(); i++) {
                    Object value = rangingConstantX.getValue(i);

                    /** Values used in the one experiment for this series. */
                    Values useThis = new Values();
                    useThis.addValues(values);
                    useThis.addValue(rangerX, value);

                    /** Get this particular result. **/
                    try {
                        Object result = resultsCollection.getResult(useThis);

                        double x = 0, y = 0;
                        boolean validX = true;

                        if (value instanceof Double) {
                            x = ((Double) value).doubleValue();
                        } else if (value instanceof Integer) {
                            x = ((Integer) value).intValue();
                        } else {
                            validX = false;
                        }

                        // Add point to graph (if of valid type)
                        if (validX) {
                            if (result instanceof Double) {
                                y = ((Double) result).doubleValue();
                                graphModel2D.addPointToSeries(seriesKey, new PrismXYDataItem(x, y));
                            } else if (result instanceof Integer) {
                                y = ((Integer) result).intValue();
                                graphModel2D.addPointToSeries(seriesKey, new PrismXYDataItem(x, y));
                            } else if (result instanceof Interval) {
                                Interval interval = (Interval) result;
                                if (interval.lower instanceof Double) {
                                    y = ((Double) interval.lower).doubleValue();
                                    graphModel2D.addPointToSeries(seriesKey, new PrismXYDataItem(x, y));
                                    y = ((Double) interval.upper).doubleValue();
                                    graphModel2D.addPointToSeries(seriesKey.next, new PrismXYDataItem(x, y));
                                } else if (result instanceof Integer) {
                                    y = ((Integer) interval.lower).intValue();
                                    graphModel2D.addPointToSeries(seriesKey, new PrismXYDataItem(x, y));
                                    y = ((Integer) interval.upper).intValue();
                                    graphModel2D.addPointToSeries(seriesKey.next, new PrismXYDataItem(x, y));
                                }
                            }
                        }
                    } catch (PrismException pe) {
                        // No result found. 
                    }
                }
            }
        } else if (!resultsKnown && resultsCollection.getCurrentIteration() == 0) {
            for (int series = 0; series < seriesValues.size(); series++) //each combination of series
            {
                Values values = seriesValues.get(series);
                SeriesKey seriesKey = seriesKeys.get(series);

                GraphResultListener listener = new GraphResultListener(graphModel2D, seriesKey, rangerX,
                        values);
                resultsCollection.addResultListener(listener);
            }
        }
    } else if (!graphCancelled && this.plotType3d.isSelected()) {

        graphModel3D.setAxisLabels(selectAxisConstantCombo.getSelectedItem().toString(),
                selectYaxisConstantCombo.getSelectedItem().toString(), "Result");
        GraphResultListener3D listener = new GraphResultListener3D(graphModel3D, rangingConstantX,
                rangingConstantY, seriesNameField.getText());
        resultsCollection.addResultListener(listener);

    }
}

From source file:de.tuebingen.uni.sfs.germanet.api.GermaNet.java

/**
 * Returns a <code>List</code> of all <code>LexUnits</code> with the
 * specified <code>WordCategory</code> in which <code>orthForm</code> occurs
 * as main orthographical form -- in case <code>considerAllOrthForms</code>
 * is true. Else returns a <code>List</code> of all <code>LexUnits</code> in
 * which <code>orthForm</code> occurs as main orthographical form, as
 * orthographical variant, as old orthographical form, or as old
 * orthographic variant -- in case/*w ww  .  ja  v  a2 s.co m*/
 * <code>considerAllOrthForms</code> is false. It uses the
 * <code>ignoreCase</code> flag as set in the constructor.
 * @param orthForm the <code>orthForm</code> to be found
 * @param wordCategory the <code>WordCategory</code> of the
 * <code>LexUnits</code> to be found (eg <code>WordCategory.nomen</code>)
 * @param considerMainOrthFormOnly considering main orthographical form only
 * (<code>true</code>) or all variants (<code>false</code>)
 * @return a <code>List</code> of <code>LexUnits</code> with the specified
 * <code>orthForm</code> and <code>wordCategory</code>.
 */
public List<LexUnit> getLexUnits(String orthForm, WordCategory wordCategory, boolean considerMainOrthFormOnly) {
    List<LexUnit> rval = null;
    ArrayList<LexUnit> tmpList;
    HashMap<String, ArrayList<LexUnit>> map;
    String mapForm = orthForm;

    if (ignoreCase) {
        mapForm = orthForm.toLowerCase();
    }

    if (considerMainOrthFormOnly) {
        map = wordCategoryMap.get(wordCategory);
    } else {
        map = wordCategoryMapAllOrthForms.get(wordCategory);
    }

    if (map != null) {
        tmpList = map.get(mapForm);
        if (tmpList == null) {
            rval = new ArrayList<LexUnit>(0);
        } else {
            rval = (List<LexUnit>) tmpList.clone();
        }
    }
    return rval;
}

From source file:Data.Storage.java

/**
 * helper for adding xml, goes over each element and add it to the storage, recursively
 * @param path current path to save items
 * @param xmlData data being saved as an xml Element
 *///www  . j ava  2 s.com
private void recurseOverElements(ArrayList<String> path, Element xmlData) {
    String[] thePath = new String[path.size()];
    path.toArray(thePath);

    List<Element> elements = (List<Element>) xmlData.elements();
    //different if an array
    boolean isArray = false;
    if (elements.size() > 1)
        isArray = elements.get(0).getName().equals(elements.get(1).getName());

    //if its an array then it should be saved as an array
    if (isArray && getAsDataStorage(thePath).toArray().size() < 1) {
        put(thePath, new JSONArray());
    }
    int i = 0;
    for (Element element : elements) {
        String key = isArray ? String.valueOf(i++) : element.getName();
        ArrayList<String> tempPath = (ArrayList<String>) path.clone();
        tempPath.add(key.replace(Converter.nsReplacer, ":"));
        addXmlWithPath(tempPath, element);
    }
}

From source file:org.sakaiproject.chat2.model.impl.ChatManagerImpl.java

/**
 * This method is called whenever the observed object is changed. An
 * application calls an <tt>Observable</tt> object's
 * <code>notifyObservers</code> method to have all the object's
 * observers notified of the change.//from w  ww . j a  v a2 s  .  co  m
 * 
 * This operates within its own Thread so normal rules and conditions don't apply
 *
 * @param o   the observable object.
 * @param arg an argument passed to the <code>notifyObservers</code>
 *            method.
 */
@SuppressWarnings("unchecked")
public void update(Observable o, Object arg) {
    if (arg instanceof Event) {
        Event event = (Event) arg;

        Reference ref = getEntityManager().newReference(event.getResource());

        if (event.getEvent().equals(ChatFunctions.CHAT_FUNCTION_NEW)) {

            // get the actual message and distribute it. Otherwise each
            // observer will fetch their own copy of the message.

            String id = ref.getId();
            if (id == null)
                return;
            ChatMessage message = getMessage(ref.getId());
            if (message == null)
                return;

            //String[] messageParams = event.getResource().split(":");

            ArrayList<RoomObserver> observers = (ArrayList<RoomObserver>) roomListeners.get(ref.getContainer());

            // originally we did the iteration inside synchronized.
            // however that turns out to hold the lock too long
            // a shallow copy of an arraylist shouldn't be bad.
            // we currently call removeRoom from receivedMessage in
            // some cases, so it can't be locked or we will deadlock
            if (observers != null) {
                synchronized (observers) {
                    observers = (ArrayList) observers.clone();
                }
                for (Iterator<RoomObserver> i = observers.iterator(); i.hasNext();) {
                    RoomObserver observer = i.next();

                    observer.receivedMessage(ref.getContainer(), message);
                }
            }

        } else if (event.getEvent().equals(ChatFunctions.CHAT_FUNCTION_DELETE_CHANNEL)) {
            //String chatChannelId = event.getResource();

            ArrayList<RoomObserver> observers = (ArrayList<RoomObserver>) roomListeners.get(ref.getId());

            if (observers != null) {
                synchronized (observers) {
                    observers = (ArrayList) observers.clone();
                }
                for (Iterator<RoomObserver> i = observers.iterator(); i.hasNext();) {
                    RoomObserver observer = i.next();

                    observer.roomDeleted(ref.getId());
                }
            }
        }
    }
}