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.github.horrorho.inflatabledonkey.cloudkitty.CloudKitty.java

List<CloudKit.ResponseOperation> doRequest(HttpClient httpClient, List<CloudKit.RequestOperation> operations)
        throws IOException {

    if (operations.isEmpty()) {
        return new ArrayList<>();
    }/*from   ww  w.j  av  a2s.com*/

    if (!operations.get(0).hasRequestOperationHeader()) {
        throw new IllegalArgumentException("missing request operation header");
    }
    CloudKit.RequestOperationHeader requestOperationHeader = operations.get(0).getRequestOperationHeader();

    ArrayList<CloudKit.ResponseOperation> responses = new ArrayList<>();

    for (int i = 0; i < operations.size(); i += REQUEST_LIMIT) {
        int fromIndex = i;
        int toIndex = fromIndex + REQUEST_LIMIT;
        toIndex = toIndex > operations.size() ? operations.size() : toIndex;

        List<CloudKit.RequestOperation> subList = operations.subList(fromIndex, toIndex);
        // Ensure we have a operations header.
        if (!subList.get(0).hasRequestOperationHeader()) {
            CloudKit.RequestOperation requestOperation = CloudKit.RequestOperation.newBuilder(subList.get(0))
                    .setRequestOperationHeader(requestOperationHeader).build();
            subList.set(0, requestOperation);
        }

        List<CloudKit.ResponseOperation> subListResponses = doSubListRequest(httpClient, subList);
        responses.addAll(subListResponses);
    }
    return responses;
}

From source file:es.udc.gii.common.eaf.algorithm.mga.MMGAAlgorithm.java

/**
 * Performs the operations needed before each micro-evolution.
 *///from  ww  w .  j a  v  a 2s.  c om
@Override
protected void beforeMicroEvolution() {

    /* If we are at the begining of the algorithm */
    if (getGenerations() == 0) {

        /* Generate the population memory. */
        getPopulation().generate();
        populationMemory = new Population();
        populationMemory.addIndividual(getPopulation().getIndividual(0));
        populationMemory.setSize(1);

        int numberOfInitialSolutions = 0;

        if (getInitialSolutions() != null) {
            numberOfInitialSolutions = getInitialSolutions().size();
        }

        populationMemory.modifyPopulationSize(populationMemorySize - numberOfInitialSolutions);

        /* Evaluate the initial population memory. */
        state = INIT_EVALUATE_STATE;
        evaluate(getProblem(), populationMemory);

        /* Add the initial solutions if any. */
        if (getInitialSolutions() != null) {
            populationMemory.addIndividuals(getInitialSolutions());
        }

        /* Generate a new Pareto-front. */
        paretoFront = new Population();
        paretoFront.addIndividuals(
                MOUtil.findNonDominatedIndividuals(populationMemory.getIndividuals(), MOUtil.FIND_ALL));

    }

    /* Construct the new population for the next micro-evolution. */
    state = REPLACE_STATE;
    int populationSize = getPopulation().getSize();
    List<Individual> newPopulation = new ArrayList<Individual>(populationSize);
    for (int i = 0; i < populationSize; i++) {
        int ind = EAFRandom.nextInt(populationMemorySize);
        Individual selectedFromPopulationMemory = populationMemory.getIndividual(ind);
        newPopulation.set(i, selectedFromPopulationMemory);
    }

    getPopulation().setIndividuals(newPopulation);
    this.setChanged();
    this.notifyObservers();
}

From source file:com.github.rvesse.airline.io.printers.UsagePrinter.java

public UsagePrinter appendTable(Iterable<? extends Iterable<String>> table, int rowSpacing) {
    List<Integer> columnSizes = new ArrayList<>();
    for (Iterable<String> row : table) {
        int column = 0;
        for (String value : row) {
            while (column >= columnSizes.size()) {
                columnSizes.add(0);//from  w  w  w.j a  va2s .c  o m
            }
            int valueLength = value != null ? value.length() : 0;
            columnSizes.set(column, Math.max(valueLength, columnSizes.get(column)));
            column++;
        }
    }

    if (currentPosition.get() != 0) {
        currentPosition.set(0);
        out.append("\n");
    }

    for (Iterable<String> row : table) {
        int column = 0;
        StringBuilder line = new StringBuilder();
        for (String value : row) {
            int columnSize = columnSizes.get(column);
            if (value != null) {
                line.append(value);
                line.append(spaces(columnSize - value.length()));
            } else {
                line.append(spaces(columnSize));
            }
            line.append("   ");
            column++;
        }
        out.append(spaces(indent)).append(trimEnd(line.toString())).append("\n");

        for (int i = 0; i < rowSpacing; i++) {
            out.append('\n');
        }
    }

    return this;
}

From source file:com.amastigote.xdu.query.module.WaterAndElectricity.java

private List<String> query_metInfo() throws IOException {
    Document document = getPage("", METINFO_SUFFIX);
    Elements elements = document.select("td");

    List<String> stringArrayList = new ArrayList<>();

    for (Element td : elements) {
        String tmp = td.text();/*from w w  w  . j a v  a2 s.c o m*/
        if (!"".equals(tmp)) {
            stringArrayList.add(tmp);
        }
    }

    for (int i = 0; i < stringArrayList.size(); i++) {
        stringArrayList.set(i, stringArrayList.get(i).substring(stringArrayList.get(i).indexOf("") + 1));
    }

    /*
     * (stringArrayList):
     *      - 0, ????
     *      - ? [ ?? | ? | ? ]
     *      - , (3n), n???
     *
     *      - ?: ?null!
     */
    return stringArrayList;
}

From source file:com.github.steveash.jg2p.train.EncoderEval.java

public void evalAndPrint(List<InputRecord> inputs, PrintOpts opts) {

    totalPhones = 0;/*ww w  . ja  va  2  s. c o m*/
    totalRightPhones = 0;
    totalWords = 0;
    totalRightWords = 0;
    noCodes = 0;
    rightAnswerInTop.clear();
    examples.clear();
    phoneEditHisto.clear();

    for (InputRecord input : inputs) {

        List<PhoneticEncoder.Encoding> encodings = encoder.encode(input.xWord);
        if (encodings.isEmpty()) {
            noCodes += 1;
            continue;
        }

        totalWords += 1;
        PhoneticEncoder.Encoding encoding = encodings.get(0);

        List<String> expected = input.yWord.getValue();
        int phonesDiff = ListEditDistance.editDistance(encoding.phones, expected, 100);
        totalPhones += expected.size();
        totalRightPhones += (expected.size() - phonesDiff);
        phoneEditHisto.add(phonesDiff);
        if (phonesDiff == 0) {
            totalRightWords += 1;
            rightAnswerInTop.add(0);
        }
        if (phonesDiff > 0) {
            // find out if the right encoding is in the top-k results
            for (int i = 1; i < encodings.size(); i++) {
                PhoneticEncoder.Encoding attempt = encodings.get(i);
                if (attempt.phones.equals(input.yWord.getValue())) {
                    rightAnswerInTop.add(i);
                    break;
                }
            }
        }
        if (collectExamples && phonesDiff > 0) {
            Pair<InputRecord, List<PhoneticEncoder.Encoding>> example = Pair.of(input, encodings);
            List<Pair<InputRecord, List<PhoneticEncoder.Encoding>>> examples = this.examples.get(phonesDiff);
            if (examples.size() < EXAMPLE_COUNT) {
                examples.add(example);
            } else {
                int victim = rand.nextInt(Ints.saturatedCast(totalWords));
                if (victim < EXAMPLE_COUNT) {
                    examples.set(victim, example);
                }
            }
        }

        if (totalWords % 500 == 0 && opts != PrintOpts.SIMPLE) {
            log.info("Processed " + totalWords + " ...");
            if (totalWords % 10_000 == 0) {
                printStats(opts);
            }
        }
    }
    printStats(opts);
}

From source file:ca.travelagency.invoice.Invoice.java

private void swapItems(int srcIndex, int dstIndex) {
    List<InvoiceItem> items = getInvoiceItems();

    InvoiceItem currentItem = items.get(srcIndex);
    InvoiceItem previousItem = items.get(dstIndex);

    currentItem.setIndex(dstIndex);//from w w  w.j  a v a 2 s. c  o  m
    previousItem.setIndex(srcIndex);

    items.set(srcIndex, previousItem);
    items.set(dstIndex, currentItem);
}

From source file:com.callidusrobotics.ui.MessageBox.java

protected List<String> getMessageTokens(final String string, final boolean preformatted) {
    final List<String> tokens = new LinkedList<String>(
            Arrays.asList(string.split(preformatted ? "\n" : "\\s+")));

    if (preformatted) {
        for (int i = 0; i < tokens.size(); i++) {
            String token = tokens.get(i);

            if (!token.isEmpty() && token.charAt(0) == ' ') {
                token = token.trim();/*from w  ww  . j a  v  a 2s.co m*/
                token = StringUtils.leftPad(token, token.length() + 1);
                tokens.set(i, token);
            }
        }
    }

    return tokens;
}

From source file:fr.inria.atlanmod.neoemf.map.datastore.estores.impl.DirectWriteMapResourceWithListsEStoreImpl.java

protected Object set(PersistentEObject object, EAttribute eAttribute, int index, Object value) {
    if (!eAttribute.isMany()) {
        Object oldValue = map.put(new Tuple2<Id, String>(object.id(), eAttribute.getName()),
                serializeToMapValue(eAttribute, value));
        return parseMapValue(eAttribute, oldValue);
    } else {/*  w w w . j  a va  2 s. com*/
        @SuppressWarnings("unchecked")
        List<Object> list = (List<Object>) getFromMap(object, eAttribute);
        Object oldValue = list.get(index);
        list.set(index, serializeToMapValue(eAttribute, value));
        map.put(new Tuple2<Id, String>(object.id(), eAttribute.getName()), list.toArray());
        return parseMapValue(eAttribute, oldValue);
    }
}

From source file:fr.inria.atlanmod.neoemf.map.datastore.estores.impl.DirectWriteMapResourceWithListsEStoreImpl.java

protected Object set(PersistentEObject object, EReference eReference, int index,
        PersistentEObject referencedObject) {
    updateContainment(object, eReference, referencedObject);
    updateInstanceOf(referencedObject);/*from  w  w  w.j a v  a 2  s  .  co m*/
    if (!eReference.isMany()) {
        Object oldId = map.put(new Tuple2<Id, String>(object.id(), eReference.getName()),
                referencedObject.id());
        return oldId != null ? eObject((Id) oldId) : null;
    } else {
        @SuppressWarnings("unchecked")
        List<Object> list = (List<Object>) getFromMap(object, eReference);
        Object oldId = list.get(index);
        list.set(index, referencedObject.id());
        map.put(new Tuple2<Id, String>(object.id(), eReference.getName()), list.toArray());
        return oldId != null ? eObject((Id) oldId) : null;
    }
}

From source file:com.linkedin.pinot.core.startree.SumStarTreeIndexTest.java

@Override
protected Map<List<Integer>, List<Double>> compute(Operator filterOperator) {
    BlockDocIdIterator docIdIterator = filterOperator.nextBlock().getBlockDocIdSet().iterator();

    Map<List<Integer>, List<Double>> results = new HashMap<>();
    int docId;//from ww w  .  java 2  s .  c o m
    while ((docId = docIdIterator.next()) != Constants.EOF) {
        // Array of dictionary Ids (zero-length array for non-group-by query)
        List<Integer> groupKeys = new ArrayList<>(_numGroupByColumns);
        for (int i = 0; i < _numGroupByColumns; i++) {
            _groupByValIterators[i].skipTo(docId);
            groupKeys.add(_groupByValIterators[i].nextIntVal());
        }

        List<Double> sums = results.get(groupKeys);
        if (sums == null) {
            sums = new ArrayList<>(_numMetricColumns);
            for (int i = 0; i < _numMetricColumns; i++) {
                sums.add(0.0);
            }
            results.put(groupKeys, sums);
        }
        for (int i = 0; i < _numMetricColumns; i++) {
            _metricValIterators[i].skipTo(docId);
            int dictId = _metricValIterators[i].nextIntVal();
            sums.set(i, sums.get(i) + _metricDictionaries[i].getDoubleValue(dictId));
        }
    }

    return results;
}