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:Main.java

public static void setIfNull(int i, List list, String value) {
    if (i >= list.size()) {
        resize(list, i + 1);//from w  w w .  j  av  a  2  s  .c o  m
    }
    if (list.get(i) != null) {
        return;
    }
    list.set(i, value);
}

From source file:net.alegen.datpass.cli.input.Command.java

public static Command create(String input) {
    if (aliases.containsKey(input))
        input = aliases.get(input);/*from   w  w w . java2  s  .  co  m*/
    List args = split(input);
    Command newCommand;
    if (substitutions.containsKey(args.get(0)))
        args.set(0, substitutions.get(args.get(0)));
    if (args.get(0).equals(PROFILE_COMMAND))
        newCommand = new ProfileCommand();
    else if (args.get(0).equals(EXIT_COMMAND))
        newCommand = new ExitCommand();
    else if (args.get(0).equals(PASSWORD_COMMAND))
        newCommand = new PasswordCommand();
    else if (args.get(0).equals(SET_COMMAND) || args.get(0).equals(GET_COMMAND))
        newCommand = new SettingsCommand();
    else
        newCommand = new ErrorCommand();
    newCommand.args = args;
    return newCommand;
}

From source file:Main.java

public static <E> void swapAll(final List<E> list) {
    if (list instanceof RandomAccess) {
        for (int i = 0, j = list.size() - 1; i < j; i++, j--) {
            list.set(i, list.set(j, list.get(i)));
        }/*  w w w  . j  a v a  2s  . c  o  m*/
    } else {
        final ListIterator<E> iteratorI = list.listIterator();
        final ListIterator<E> iteratorJ = list.listIterator(list.size());
        E tmp;

        while (iteratorI.nextIndex() < iteratorJ.nextIndex()) {
            tmp = iteratorI.next();
            iteratorI.set(iteratorJ.previous());
            iteratorJ.set(tmp);
        }
    }
}

From source file:com.couchbase.client.core.config.CouchbasePartitionInfo.java

private static void trimPort(List<String> input) {
    for (int i = 0; i < input.size(); i++) {
        String[] parts = input.get(i).split(":");
        input.set(i, parts[0]);
    }//from   ww w  .j  a  v  a2s.  c o m
}

From source file:Main.java

/**
 * In the given list, sets the element at the given index. If the index is out of
 * the bounds of this list, it is extended up to this index
 * and the gaps are filled with the given fillElement. If the given list is null,
 * an {@link ArrayList} is created. The modified list is returned.
 *//*  w  w  w  .  j a v  a2s  .  c o  m*/
public static <T> List<T> setExtend(List<T> list, int index, T element, T fillElement) {
    if (list == null)
        list = new ArrayList<T>(index + 1);
    while (index >= list.size())
        list.add(fillElement);
    list.set(index, element);
    return list;
}

From source file:de.terministic.serein.core.genome.DoubleGenome.java

public static void limitToBounds(List<Double> genes) {
    for (int i = 0; i < genes.size(); i++) {

        if (genes.get(i) < LOWER_BOUND) {
            genes.set(i, LOWER_BOUND);
        } else if (genes.get(i) > UPPER_BOUND) {
            genes.set(i, UPPER_BOUND);/*from  w  w w .ja  v  a  2  s.c om*/
        }
    }
}

From source file:com.gmail.filoghost.chestcommands.config.AsciiPlaceholders.java

public static List<String> placeholdersToSymbols(List<String> input) {
    if (input == null)
        return null;
    for (int i = 0; i < input.size(); i++) {
        input.set(i, placeholdersToSymbols(input.get(i)));
    }// w w  w.  j  a v a2s. c  o m
    return input;
}

From source file:sh.scrap.scrapper.functions.StringFunctionFactory.java

private static String key(Method method) {
    String[] names = discoverer.getParameterNames(method);
    if (names == null)
        names = new String[0];
    List<String> args = new ArrayList<>(Arrays.asList(names));
    if (args.size() >= 2)
        args.set(1, "main");
    Collections.sort(args);//from   w ww.j  a va2 s.co m
    return method.getName() + ":" + args;
}

From source file:edu.oregonstate.eecs.mcplan.util.ListUtil.java

public static <T> void randomShuffle(final RandomGenerator rng, final List<T> v) {
    for (int i = v.size() - 1; i >= 0; --i) {
        final int idx = rng.nextInt(i + 1);
        final T t = v.get(idx);
        v.set(idx, v.get(i));
        v.set(i, t);/*from   ww  w. j  a  v  a  2  s .co m*/
    }
}

From source file:Main.java

public static <T> void nullFillAndSet(final List<T> list, @Nonnegative final int i, @CheckForNull final T t) {
    checkNotNull(list);//from w  w w. ja v a 2s . c o m
    checkArgument(i >= 0, "i is negative");
    while (list.size() < i + 1) {
        list.add(null);
    }
    list.set(i, t);
}