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 <T> java.util.List<T> randomSample(java.util.List<T> items, int size) {
    size = Math.min(size, items.size());
    java.util.Random rnd = new java.util.Random();
    for (int i = 0; i < size; i++) {
        int pos = i + rnd.nextInt(items.size() - i);
        T tmp = items.get(pos);/*from  ww  w .  ja v  a2 s  . co  m*/
        items.set(pos, items.get(i));
        items.set(i, tmp);
    }
    return items.subList(0, size);
}

From source file:com.fegati.utilities.CSVPreprocessor.java

public static void removeUnwantedColumns(List<String[]> rows, int index) {
    int i = 0;//ww w  . j  ava2 s . co  m
    for (String[] row : rows) {
        rows.set(i, ArrayUtils.remove(row, index));
        i++;
        LOGGER.log(Level.INFO, "Removing column " + index + " of row " + i);
    }
}

From source file:net.estinet.gFeatures.Feature.gRanks.gRanks.java

public static List<String> getPermsFile(File f) throws IOException {
    List<String> perms = Files.readAllLines(Paths.get(f.getPath()), StandardCharsets.UTF_8);
    for (int i = 0; i < perms.size(); i++) {
        perms.set(i, perms.get(i).replace("\r", ""));
        if (perms.get(i).equals("")) {
            if (i != 0)
                i--;//from   w ww .java 2 s  .  c  om
            perms.remove(i);
        }
    }
    return perms;
}

From source file:com.google.codelab.networkmanager.CodelabUtil.java

public static void saveTaskItemToFile(Context context, TaskItem taskItem) {
    List<TaskItem> taskItems = getTaskItemsFromFile(context);
    for (int i = 0; i < taskItems.size(); i++) {
        TaskItem ti = taskItems.get(i);//from  w ww . java 2s. c  om
        if (ti.getId().equals(taskItem.getId())) {
            taskItems.set(i, taskItem);
            break;
        }
    }
    saveTaskItemsToFile(context, taskItems);
}

From source file:Main.java

private static void quoteTokens(List<String> tokens) {
    for (int i = 0; i < tokens.size(); i++) {
        String token = tokens.get(i);
        if ("'".equals(token)) {
            token = addDoubleQuotation(token);
        } else {//from  w ww . ja  v a  2s  . co  m
            token = addSingleQuotation(token);
        }
        tokens.set(i, token);
    }
}

From source file:com.streamreduce.util.JSONUtils.java

@SuppressWarnings("unchecked")
public static List<Object> replaceJSONNullsFromList(List<Object> list) {
    if (list == null) {
        return null;
    }// ww w.j  a v a  2 s  .com

    List<Object> newList = new ArrayList<>(list);

    for (int i = 0; i < newList.size(); i++) {
        Object o = newList.get(i);
        if (o instanceof Map) {
            newList.set(i, replaceJSONNullsFromMap((Map) o));
        } else if (o instanceof List) {
            newList.set(i, replaceJSONNullsFromList((List<Object>) o));
        } else if (JSONNull.getInstance().equals(o)) {
            newList.set(i, null);
        }
    }
    return newList;
}

From source file:com.francetelecom.clara.cloud.commons.InternetDomainNameCleaner.java

/**
 * Validation method used by {@from} to ensure that the domain name is
 * syntactically valid according to RFC 1035.
 *
 * @return Is the domain name syntactically valid?
 *///from  w  ww. j  a  v a  2s  .  c o  m
public static void fixParts(List<String> parts) {
    final int lastIndex = parts.size() - 1;

    // Validate the last part specially, as it has different syntax rules.

    parts.set(lastIndex, getFixedPart(parts.get(lastIndex), true));

    for (int i = 0; i < lastIndex; i++) {
        String part = parts.get(i);
        parts.set(i, getFixedPart(part, false));
    }
}

From source file:com.sk89q.craftbook.sponge.mechanics.area.complex.ComplexArea.java

private static void setToggleState(Sign sign, boolean state) {
    int toToggleOn = state ? 2 : 3;
    int toToggleOff = state ? 3 : 2;
    List<Text> lines = sign.lines().get();
    lines.set(toToggleOff, Text.of(sign.lines().get(toToggleOff).toPlain().replace("-", "")));
    lines.set(toToggleOn, Text.of("-", sign.lines().get(toToggleOn), "-"));
    sign.offer(Keys.SIGN_LINES, lines);//w  ww  . j a  va2s.  c om
}

From source file:Main.java

/**
 * Scramble oder of elements in a list.// w  ww  . j  a v a2  s . c  o  m
 *
 * @param list
 */
public static <E> void scrambleList(List<E> list) {
    if (isNotEmpty(list)) {
        Random generator = new Random();
        for (int i = 0; i < list.size(); i++) {
            int random = generator.nextInt(list.size());
            if (random != i) {
                //Util of vs.(swap)
                E objTemp = list.get(i);
                list.set(i, list.get(random));
                list.set(random, objTemp);
            }
        }
    }
}

From source file:com.flipkart.zjsonpatch.JsonDiff.java

private static void updateCounters(Diff pseudo, int idx, List<Integer> counters) {
    if (Operation.ADD.equals(pseudo.getOperation())) {
        counters.set(idx, counters.get(idx) - 1);
    } else {//www.  ja  va  2  s .  c  om
        if (Operation.REMOVE.equals(pseudo.getOperation())) {
            counters.set(idx, counters.get(idx) + 1);
        }
    }
}