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.sangupta.clitools.file.LeftTrim.java

@Override
protected boolean processFile(File file) throws IOException {
    // read entire file in memory
    List<String> contents = FileUtils.readLines(file);
    final long initial = file.length();

    // now for each string - trim from end
    for (int index = 0; index < contents.size(); index++) {
        String line = contents.get(index);
        line = StringUtils.stripStart(line, null);
        contents.set(index, line);
    }/*from  ww  w  . j a va 2  s  .c o m*/

    // write back contents of file
    FileUtils.writeLines(file, contents);
    long current = file.length();

    this.bytesSaved.addAndGet(initial - current);
    System.out.println("File " + file.getAbsoluteFile().getAbsolutePath() + " left-trimmed and saved "
            + (initial - current) + " bytes.");
    return true;
}

From source file:com.cloudera.oryx.ml.param.ContinuousAround.java

@Override
public List<Double> getTrialValues(int num) {
    Preconditions.checkArgument(num > 0);
    if (num == 1) {
        return Collections.singletonList(around);
    }// w ww  . ja va 2 s .  c o  m
    List<Double> values = new ArrayList<>(num);
    double value = around - ((num - 1.0) / 2.0) * step;
    for (int i = 0; i < num; i++) {
        values.add(value);
        value += step;
    }
    // Make sure middle value is exact
    if (num % 2 != 0) {
        values.set(num / 2, around);
    }
    return values;
}

From source file:de.innovationgate.wga.server.api.Xml.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private Object convertXMLObjects(Object result, boolean descent) {

    if (result instanceof List && descent) {
        List list = (List) result;
        for (int idx = 0; idx < list.size(); idx++) {
            list.set(idx, convertXMLObjects(list.get(idx), false));
        }//from   ww w.  j a  v a2 s. c o m
    }
    if (result instanceof Text || result instanceof CDATA || result instanceof Attribute) {
        return ((Node) result).getText();
    } else {
        return result;
    }
}

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

/**
 * Splits <tt>str</tt> around matches of the delimiter character.
 *
 * @param   str//from  w  w w .j  a  v  a2s .  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 delimiter character.
 *
 **/
public static String[] fieldSplit(String str, String delimiter, char chrDelim) {
    if ((str.indexOf(chrDelim, 0)) < 0) {
        return StringUtils.splitPreserveAllTokens(str, delimiter);
    } else {
        ArrayList<String> list = new ArrayList<String>();
        String record;
        List<String> streamsList = Arrays.asList(StringUtils.splitPreserveAllTokens(str, delimiter));
        int fEnd;
        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 start field
                    fEnd = record.indexOf(chrDelim, 1); // find end
                    if (fEnd < 0) { //not found
                        if ((i + 1) < streamsList.size()) {
                            streamsList.set(i + 1, record + delimiter + streamsList.get(i + 1));
                        } else {
                            list.add(record);
                        }
                    } else {
                        list.add(record);
                    }
                }
            }
        }
        int resultSize = list.size();
        String[] result = new String[resultSize];
        return list.subList(0, resultSize).toArray(result);
    }
}

From source file:de.micromata.genome.gwiki.utils.html.Html2WikiFragmentVisitor.java

@Override
public void begin(GWikiFragment fragment) {
    if (fragment instanceof GWikiFragmentTable) {
        GWikiFragmentTable table = (GWikiFragmentTable) fragment;
        if (hasChildTable(fragment) == true || hasParentTable() == true
                || hasForeignAttributes(table) == true) {
            GWikiFragment htmltable = convertTableToHtmlTable(table);
            List<GWikiFragment> childs = stack.peek().getChilds();
            for (int i = 0; i < childs.size(); ++i) {
                if (childs.get(i) == table) {
                    childs.set(i, htmltable);
                }/* ww w .ja  v a  2  s  . c om*/
            }
            fragment = htmltable;
        }
    }

    stack.push(fragment);
}

From source file:com.bt.aloha.dao.ConferenceInfoDaoImpl.java

public void update(final ConferenceInfo conferenceInfo) {
    List<Object> paramList = createParams(conferenceInfo);
    // replace version id with new one
    paramList.set(V_ID_POS, conferenceInfo.generateNewVersionId());
    // remove ID//from   w w  w.ja v  a2 s.c om
    paramList.remove(0);
    // add the ID at the end of the list
    paramList.add(conferenceInfo.getId());
    // add old version ID
    String oldVersionId = conferenceInfo.getVersionId();
    paramList.add(oldVersionId);

    Object[] params = paramList.toArray();

    int rowsUpdated = getJdbcTemplate().update(UPDATE_SQL, params, UPDATE_TYPES);
    if (1 != rowsUpdated)
        throw new ConcurrentUpdateException(conferenceInfo.getId(),
                String.format("Info %s modified in database, try again", conferenceInfo.getId()));
}

From source file:com.consol.citrus.admin.launcher.ProcessLauncherTest.java

private ProcessListener getProcessListener(final List<Boolean> callbacks) {
    // reset callbacks
    for (int i = 0; i < callbacks.size(); i++) {
        callbacks.set(i, false);
    }//from w ww.j  ava 2s .c o  m

    return new ProcessListener() {
        public void onProcessStart(String processId) {
            System.out.println("Starting:" + processId + ", " + new Date());
            callbacks.set(0, Boolean.TRUE);
        }

        public void onProcessSuccess(String processId) {
            System.out.println("Success:" + processId);
            callbacks.set(1, Boolean.TRUE);
        }

        public void onProcessFail(String processId, int exitCode) {
            System.err.println("Failed:" + processId + ", errorCode:" + exitCode);
            callbacks.set(2, Boolean.TRUE);
        }

        public void onProcessFail(String processId, Throwable e) {
            System.err.println("Failed:" + processId + ", ex:" + e.getLocalizedMessage());
            e.printStackTrace();
            callbacks.set(3, Boolean.TRUE);
        }

        public void onProcessOutput(String processId, String output) {
            //do nothing as activity was already printed
        }

        public void onProcessActivity(String processId, String output) {
            System.out.println(processId + ":" + output);
        }
    };
}

From source file:com.johan.vertretungsplan.parser.UntisInfoParser.java

private void writeTagByDatum(List<VertretungsplanTag> tage, VertretungsplanTag newTag) {
    int i = 0;//from   ww  w .  j  a  v  a2 s .  co  m
    for (VertretungsplanTag tag : tage) {
        if (tag.getDatum().equals(newTag.getDatum())) {
            tage.set(i, newTag);
            return;
        }
        i++;
    }
    tage.add(newTag);
}

From source file:com.mirth.connect.util.ValueReplacer.java

/**
 * Replaces all values in a list. Uses the default context, which includes the global variable
 * map.//  w ww  . j  ava 2s.  c o  m
 * 
 * @return void
 */
public void replaceValuesInList(List<String> list) {
    for (int i = 0; i <= list.size() - 1; i++) {
        list.set(i, replaceValues(list.get(i)));
    }
}

From source file:com.heisenberg.impl.type.ListType.java

@Override
public Object convertJsonToInternalValue(Object jsonValue) throws InvalidValueException {
    if (jsonValue == null) {
        return null;
    }/* www . ja  v a2s  .co m*/
    if (!(jsonValue instanceof List)) {
        throw new InvalidValueException("Json value must be a list, but was " + jsonValue + " ("
                + jsonValue.getClass().getName() + ")");
    }
    @SuppressWarnings("unchecked")
    List<Object> list = (List<Object>) jsonValue;
    for (int i = 0; i < list.size(); i++) {
        Object elementJsonValue = list.get(i);
        Object elementInternalValue = elementDataType.convertJsonToInternalValue(elementJsonValue);
        list.set(i, elementInternalValue);
    }
    return list;
}