Example usage for java.util List set

List of usage examples for java.util List set

Introduction

In this page you can find the example usage for java.util List set.

Prototype

E set(int index, E element);

Source Link

Document

Replaces the element at the specified position in this list with the specified element (optional operation).

Usage

From source file:com.seer.datacruncher.utils.generic.CommonUtils.java

/**
 * Splits <tt>str</tt> around matches of the newline character.
 *
 * @param   str/*  www .j  a  v  a  2 s  .  c o  m*/
 *          the string to split
 *
 * @param   delimiter
 *          the delimiting field string
 *
 * @param   chrDelim
 *          the delimiting character
 *
 * @return  the array of strings computed by splitting string
 *          around matches of the newline character.      
 *         
 **/
public static String[] lineSplit(String str, String delimiter, char chrDelim) {
    String linedelimiter = "\n";
    String spltdelim = "\\";

    if ((str.indexOf(chrDelim, 0)) < 0) {
        return str.split(spltdelim + linedelimiter);
    } else {
        ArrayList<String> list = new ArrayList<String>();
        String record;
        List<String> streamsList = Arrays.asList(str.split(spltdelim + linedelimiter));
        int fStart;
        int fEnd;
        boolean checkfields = true;
        for (int i = 0; i < streamsList.size(); i++) {
            record = streamsList.get(i);
            if ((record.indexOf(chrDelim, 0)) < 0) {
                list.add(record);
            } else {
                if (record.startsWith(chrDelim + "")) { // check in first field
                    fEnd = record.indexOf(chrDelim + delimiter, 1); // find end
                    if (fEnd < 0) { //not found
                        if ((i + 1) < streamsList.size()) {
                            streamsList.set(i + 1, record + linedelimiter + streamsList.get(i + 1));
                        } else {
                            list.add(record);
                        }
                        checkfields = false;
                    } else {
                        checkfields = true;
                    }
                }
                if (checkfields) {
                    fStart = record.indexOf(delimiter + chrDelim, 1);
                    while (fStart < record.length()) {
                        if (fStart > 0) {
                            fEnd = record.indexOf(chrDelim + delimiter, fStart);
                            if (fEnd > 0) {
                                fStart = record.indexOf(delimiter + chrDelim, fEnd);
                                if (fStart < 0) {
                                    list.add(record);
                                    fStart = record.length();
                                }
                            } else {
                                fEnd = record.indexOf(chrDelim, fStart + 2);
                                if (fEnd < 0) {
                                    if ((i + 1) < streamsList.size()) {
                                        streamsList.set(i + 1, record + linedelimiter + streamsList.get(i + 1));
                                    } else {
                                        list.add(record);
                                    }
                                } else {
                                    if (record.charAt(record.length() - 1) == chrDelim) { //last field
                                        list.add(record);
                                    } else {
                                        if ((i + 1) < streamsList.size()) {
                                            streamsList.set(i + 1,
                                                    record + linedelimiter + streamsList.get(i + 1));
                                        } else {
                                            list.add(record);
                                        }
                                    }
                                }
                                fStart = record.length();
                            }
                        } else {
                            fStart = record.length();
                        }
                    }
                }
            }
        }
        int resultSize = list.size();
        String[] result = new String[resultSize];
        return list.subList(0, resultSize).toArray(result);
    }
}

From source file:de.undercouch.citeproc.script.ScriptRunnerBenchmark.java

private void runTest() throws Exception {
    CSL citeproc = new CSL(sys, "ieee");
    citeproc.setOutputFormat("text");

    List<Key> keys = new ArrayList<Key>(db.getEntries().keySet());
    List<String> result = new ArrayList<String>();

    for (Integer r : rnds) {
        Key k = keys.get(r);//from  ww w . ja  va 2s .  co  m
        List<Citation> cs = citeproc.makeCitation(k.getValue());
        for (Citation c : cs) {
            while (result.size() <= c.getIndex()) {
                result.add("");
            }
            result.set(c.getIndex(), c.getText());
        }
    }

    int c = 0;
    for (Integer r : rnds) {
        Key k = keys.get(r);
        List<Citation> cs = citeproc.makeCitation(k.getValue());
        assertEquals(1, cs.size());
        String nc = cs.get(0).getText();
        String pc = result.get(c);
        assertEquals(nc, pc);
        ++c;
    }
}

From source file:com.flexive.shared.structure.FxGroupAssignmentEdit.java

/**
 * Set a new alias, will affect the xpath as well
 *
 * @param alias new alias//w  w  w .j  a v a2s. com
 * @return this
 * @throws FxInvalidParameterException on errors
 */
public FxGroupAssignmentEdit setAlias(String alias) throws FxInvalidParameterException {
    if (StringUtils.isEmpty(alias))
        throw new FxInvalidParameterException("ALIAS", "ex.structure.assignment.noAlias");
    //only react to alias changes
    if (!this.alias.trim().toUpperCase().equals(alias.trim().toUpperCase())) {
        this.alias = alias.trim().toUpperCase();
        List<XPathElement> xpe = XPathElement.splitNew(this.XPath);
        xpe.set(xpe.size() - 1, new XPathElement(this.alias, 1, true));
        this.XPath = XPathElement.toXPathNoMult(xpe);
    }
    return this;
}

From source file:com.unboundid.scim2.common.Path.java

/**
 * Create a new path where the attribute and filter at the specified index
 * is replaced with those provided.//w w w  .ja  v a 2  s .  com
 *
 * @param index The index of the element to replace.
 * @param attribute The replacement attribute.
 * @param valueFilter The replacement value filter.
 * @return The new path.
 */
public Path replace(final int index, final String attribute, final Filter valueFilter) {
    List<Element> newElements = new ArrayList<Element>(this.elements);
    newElements.set(index, new Element(attribute, valueFilter));
    return new Path(schemaUrn, newElements);
}

From source file:com.unboundid.scim2.common.Path.java

/**
 * Create a new path where the attribute at the specified index is replaced
 * with the one provided./*w  ww.  j a  va  2  s. co m*/
 *
 * @param index The index of the element to replace.
 * @param attribute The replacement attribute.
 * @return The new path.
 */
public Path replace(final int index, final String attribute) {
    List<Element> newElements = new ArrayList<Element>(this.elements);
    newElements.set(index, new Element(attribute, this.elements.get(index).getValueFilter()));
    return new Path(schemaUrn, newElements);
}

From source file:com.unboundid.scim2.common.Path.java

/**
 * Create a new path where the filter at the specified index is replaced with
 * the one provided./*from   ww w  .  j  a  va  2 s . c om*/
 *
 * @param index The index of the element to replace.
 * @param valueFilter The replacement value filter.
 * @return The new path.
 */
public Path replace(final int index, final Filter valueFilter) {
    List<Element> newElements = new ArrayList<Element>(this.elements);
    newElements.set(index, new Element(this.elements.get(index).getAttribute(), valueFilter));
    return new Path(schemaUrn, newElements);
}

From source file:techtonic.WellBoreListener.java

@Override
public void actionPerformed(ActionEvent e) {
    List<WitsmlTrajectory> trajectorys = xmlreader.getTrajectorys(wellbore);
    for (int i = 0; i < trajectorys.size(); i++) {

        System.out.println("***************************************************************");

        System.out.println("Wellbore Trajectories " + trajectorys.size());
        System.out.println("Trajectory Stations");
        System.out.println("***************************************************************");
        System.out.println("*/ " + (i + 1) + " == " + trajectorys.get(i).getName() + " has   "
                + trajectorys.get(i).getStations().size() + "  stations");
        System.out.println("***************************************************************");
        System.out.println("***************************************************************");

        //            // trajectories button
        //            JButton btnTrajectory = new JButton("<html><b>Name:  " + trajectorys.get(i).getName()
        //                        + "</b><br/> Status:  " +trajectorys.get(i).getStations().size() + "<br> Type:  " + trajectorys.get(i).getTvdUnit() + "</br></html>");
        ///* w w  w . jav a2s. c o m*/
        //                btnTrajectory.setBounds(5, ((100 * i) + 5), this.trajectoryPanel.getWidth() - 20, 100);
        //
        //                this.trajectoryPanel.add(btnTrajectory);
        //            
        //                trajectoryPanel.validate();
        //                trajectoryPanel.repaint();

        //Set<WitsmlTrajectoryStation> stations = trajectory.getStations();
        //System.out.println(stations);
        List<WitsmlTrajectoryStation> stationsAsList = Arrays
                .asList(new WitsmlTrajectoryStation[trajectorys.get(i).getStations().size()]);
        for (WitsmlTrajectoryStation s : trajectorys.get(i).getStations()) {
            stationsAsList.set(s.getStationNo(), s);
        }

        //            for (WitsmlTrajectoryStation station : stationsAsList) {
        //                System.out.println(
        //                        "tvd: " + station.getTvd() + "  "
        //                        + "md:  " + station.getMd() + "  "
        //                        + "north:  " + station.getNorth() + "  "
        //                        + "east:  " + station.getEast() + "  "
        //                        + "gravity:  " + station.getInclination() + "  "
        //                        + " Turn Rate :"+ station.getTurnRate() + " "
        //                        + " "+ station.getVerticalSectionDistance() + " "
        //                        + " "+ station.getAzimuth()
        //                );
        //            }
        // create a DataSet object for storing xy data 
        XYSeries series = new XYSeries("series name");
        // add data to Dataset (here assume data is in ArrayLists x and y
        int count = 1;
        for (WitsmlTrajectoryStation station : stationsAsList) {

            Value tvd = station.getTvd();

            if (tvd == null) {
                continue;
            }
            Value md = station.getNorth();
            if (md == null) {
                continue;
            }
            //     System.out.println(count + " : ===>> tvd : "+tvd.getValue()+ "; md "+md.getValue());
            series.add(md.getValue(), tvd.getValue());
            count++;
        }

        //            

        XYSeriesCollection data = new XYSeriesCollection();
        data.addSeries(series);

        // create a chart using the createYLineChart method...
        JFreeChart chart = ChartFactory.createXYLineChart("Line Chart", // chart title
                "x", "y", // x and y axis labels
                data); // data

        Techtonic.setChart(chart);
        Techtonic.setcurrentWitsmlTrajectoryStation(stationsAsList);

        ChartPanel cp = new ChartPanel(chart);
        cp.setMouseZoomable(true, true);
        chartPanel.setLayout(new java.awt.BorderLayout());
        chartPanel.add(cp, BorderLayout.CENTER);
        chartPanel.validate();
        System.out.println("");
        System.out.println("");
    }
}

From source file:es.pode.empaquetador.presentacion.basico.asociar.archivos.AsociacionArchivosControllerImpl.java

/**
 * @see es.pode.empaquetador.presentacion.basico.asociar.archivos.AsociacionArchivosController#recuperarDatos(org.apache.struts.action.ActionMapping, es.pode.empaquetador.presentacion.basico.asociar.archivos.RecuperarDatosForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///w  w  w . j  a v a2  s .  com
public final void recuperarDatos(ActionMapping mapping,
        es.pode.empaquetador.presentacion.basico.asociar.archivos.RecuperarDatosForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    AsociarSession asoSes = this.getAsociarSession(request);
    AsociacionArchivosSession asoArcSes = this.getAsociacionArchivosSession(request);
    //       if(asoArcSes.getFicheros()==null)
    //          asoArcSes.setFicheros(new ArrayList());

    EmpaquetadorSession empSes = this.getEmpaquetadorSession(request);
    GestorArchivosSession sesArch = this.getGestorArchivosSession(request);

    String idOde = empSes.getIdLocalizador();
    ArchivoVO arbol = this.getSrvGestorArchivosService().recuperarArbol(idOde);
    if (logger.isDebugEnabled())
        logger.debug("creo la lista de path");

    List listaPath = sesArch.getPath();
    listaPath.set(0, arbol);
    for (int i = 1; i < listaPath.size(); i++) {
        ArchivoVO elemento = (ArchivoVO) listaPath.get(i);
        String nombre = elemento.getNombre();
        ArchivoVO elementoAnterior = (ArchivoVO) listaPath.get(i - 1);
        ArchivoVO[] arrayContenidos = elementoAnterior.getContenidos();

        ArchivoVO hijo = null;
        for (int j = 0; j < arrayContenidos.length && hijo == null; j++) {
            if (arrayContenidos[j].getNombre().equals(nombre)) {
                hijo = arrayContenidos[j];
            }
        }
        listaPath.set(i, hijo);
    }

    ArchivoVO[] lista = null;
    ArchivoVO ultimoEnPath = null;
    if (sesArch.getPath().size() != 1) {
        ultimoEnPath = (ArchivoVO) sesArch.getPath().get(sesArch.getPath().size() - 1);
        if (ultimoEnPath.getCarpetaPadre() == null) {
            lista = this.getSrvGestorArchivosService().listar(idOde, ultimoEnPath.getNombre());
        } else {

            lista = this.getSrvGestorArchivosService().listar(idOde,
                    ultimoEnPath.getCarpetaPadre() + "/" + ultimoEnPath.getNombre());
        }

    } else if (sesArch.getPath().size() == 1) {
        lista = this.getSrvGestorArchivosService().listar(idOde, null);
    }

    form.setFicheros(Arrays.asList(lista));//ArchivoVO

    if (asoArcSes.getFicheros() == null) {
        if (logger.isDebugEnabled())
            logger.debug("lista de ficheros en asosiacionArchivoSession esta vacia... la relleno");
        asoArcSes.setFicheros(new ArrayList());
        asoArcSes.getFicheros().addAll(asoSes.getFicheros());
    }

    form.setFicherosSeleccionados(asoArcSes.getFicheros());//FileVO
    form.setPath(sesArch.getPath());
    form.setArbol((ArchivoVO) sesArch.getPath().get(0));

}

From source file:com.google.uzaygezen.core.RangeListFilter.java

public RangeListFilter<T, V, R> combine(RangeListFilter<T, V, R> higher, int threshold, V gapEstimate) {
    Preconditions.checkArgument(rangeList.size() <= threshold);
    Preconditions.checkArgument(higher.rangeList.size() <= threshold);
    // This trick works for nonnegative numbers.
    int cmp = rangeList.get(rangeList.size() - 1).getEnd().compareTo(higher.rangeList.get(0).getStart());
    int gapSignum = gapEstimate.isZero() ? 0 : 1;
    Preconditions.checkArgument((cmp < 0 & gapSignum >= 0) || (cmp == 0 & gapSignum == 0));
    int concatenatedListSize = rangeList.size() + higher.rangeList.size() + gapSignum - 1;
    if (thresholdExceeded || higher.thresholdExceeded || concatenatedListSize > threshold) {
        if (concatenatedListSize > threshold & !thresholdExceeded & !higher.thresholdExceeded) {
            logger.log(thresholdExceededLogLevel,
                    "Exceeded threshold {0} with input sizes" + " {1} and {2} and gapEstimate={3}.",
                    new Object[] { threshold, rangeList.size(), higher.rangeList.size(), gapEstimate });
        }/*from ww w. j a  v  a2s  .  c  om*/
        return new RangeListFilter<T, V, R>(
                ImmutableList.of(rangeHome.of(rangeList.get(0).getStart(),
                        higher.rangeList.get(higher.rangeList.size() - 1).getEnd())),
                true, thresholdExceededLogLevel, rangeHome);
    }
    List<R> list = new ArrayList<>(concatenatedListSize);
    if (gapSignum == 0) {
        list.addAll(rangeList);
        list.addAll(list.size() - 1, higher.rangeList);
        R lastLowerFilter = list.remove(list.size() - 1);
        assert rangeList.get(rangeList.size() - 1) == lastLowerFilter;
        list.set(rangeList.size() - 1,
                rangeHome.of(lastLowerFilter.getStart(), higher.rangeList.get(0).getEnd()));
    } else {
        list.addAll(rangeList);
        list.addAll(higher.rangeList);
    }
    return new RangeListFilter<T, V, R>(Collections.unmodifiableList(list), false, thresholdExceededLogLevel,
            rangeHome);
}

From source file:com.opensymphony.able.webwork.quickstart.Configuration.java

private void resolve(List list, String wd) {
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            String s = (String) list.get(i);
            list.set(i, resolveDir(s, wd));
        }//from  www .j a v a  2  s.  co  m
    }
}