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:cn.guoyukun.spring.jpa.entity.search.utils.SearchableConvertUtils.java

private static void convert(BeanWrapperImpl beanWrapper, Condition condition) {
    String searchProperty = condition.getSearchProperty();

    //??//from w w w.  ja  va2 s . c  o m
    if (condition.getOperator() == SearchOperator.custom) {
        return;
    }

    //???
    if (condition.isUnaryFilter()) {
        return;
    }

    String entityProperty = condition.getEntityProperty();

    Object value = condition.getValue();

    Object newValue = null;
    boolean isCollection = value instanceof Collection;
    boolean isArray = value != null && value.getClass().isArray();
    if (isCollection || isArray) {
        List<Object> list = Lists.newArrayList();
        if (isCollection) {
            list.addAll((Collection) value);
        } else {
            list = Lists.newArrayList(CollectionUtils.arrayToList(value));
        }
        int length = list.size();
        for (int i = 0; i < length; i++) {
            list.set(i, getConvertedValue(beanWrapper, searchProperty, entityProperty, list.get(i)));
        }
        newValue = list;
    } else {
        newValue = getConvertedValue(beanWrapper, searchProperty, entityProperty, value);
    }
    condition.setValue(newValue);
}

From source file:com.github.rinde.opt.localsearch.Swaps.java

static <T> ImmutableList<T> replace(ImmutableList<T> list, IntList indices, ImmutableList<T> elements) {
    checkIndices(indices, elements);//www.j ava 2s.  c  o m
    final List<T> newL = newArrayList(list);
    for (int i = 0; i < indices.size(); i++) {
        newL.set(indices.getInt(i), elements.get(i));
    }
    return ImmutableList.copyOf(newL);
}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step8GoldDataAggregator.java

public static File printHashMap(Map<String, Annotations> annotations, int numberOfAnnotators) {

    File dir = new File(TEMP_DIR);
    CSVPrinter csvFilePrinter;/*from w w w.jav a  2s.co m*/
    FileWriter fileWriter;
    CSVFormat csvFileFormat = CSVFormat.DEFAULT.withRecordSeparator('\n').withDelimiter(',').withQuote(null);

    File filename = null;
    try {
        filename = File.createTempFile(TEMP_CSV, EXT, dir);
        fileWriter = new FileWriter(filename);
        csvFilePrinter = new CSVPrinter(fileWriter, csvFileFormat);
        int count = 0;
        for (Map.Entry entry : annotations.entrySet()) {
            Annotations votes = (Annotations) entry.getValue();
            //Create the CSVFormat object with "\n" as a record delimiter
            if (votes == null) {
                throw new IllegalStateException("There are no votes for " + entry.getKey());
            }
            ArrayList<Integer> trueAnnotators = (ArrayList<Integer>) votes.trueAnnotations;
            ArrayList<Integer> falseAnnotators = (ArrayList<Integer>) votes.falseAnnotations;
            if (trueAnnotators.size() + falseAnnotators.size() < 5) {
                try {
                    throw new IllegalStateException(
                            "There are " + trueAnnotators.size() + " true and " + falseAnnotators.size()
                                    + " false and annotations for " + entry.getKey() + " element");
                } catch (IllegalStateException ex) {
                    ex.printStackTrace();
                }
            }
            List<String> votesString = Arrays.asList(new String[numberOfAnnotators]);
            for (int i = 0; i < numberOfAnnotators; i++) {
                if (trueAnnotators.contains(i)) {
                    votesString.set(i, "true");
                } else if (falseAnnotators.contains(i)) {
                    votesString.set(i, "false");
                } else
                    votesString.set(i, "");
            }

            if (votesString.size() != numberOfAnnotators) {
                throw new IllegalStateException(
                        "Number of annotators is " + votesString.size() + " expected " + numberOfAnnotators);
            } else {
                csvFilePrinter.printRecord(votesString);
            }

            if (count % 1000 == 0) {
                System.out.println("Processed " + count + " instances");
            }
            count++;

        }
        fileWriter.flush();
        fileWriter.close();
        csvFilePrinter.close();

    } catch (Exception e) {
        System.out.println("Error in CsvFileWriter !!!");
        e.printStackTrace();
    }
    System.out.println("Wrote to temporary file " + filename);

    return filename;

}

From source file:org.tsm.concharto.web.eventsearch.SearchSessionUtil.java

@SuppressWarnings("unchecked")
private static void updateEventInSession(HttpServletRequest request, Long eventId, Event event) {
    List<Event> events = (List<Event>) WebUtils.getSessionAttribute(request,
            SearchHelper.SESSION_EVENT_SEARCH_RESULTS);
    if (events != null) {
        for (int i = 0; i < events.size(); i++) {
            if (events.get(i).getId().equals(eventId)) {
                if (event == null) {
                    //the event was deleted, so we should remove it here
                    events.remove(i);/*from w  ww  . j av  a2s.c  o  m*/
                } else {
                    //replace it
                    events.set(i, event);
                }
            }
        }
        WebUtils.setSessionAttribute(request, SearchHelper.SESSION_EVENT_SEARCH_RESULTS, events);
    }
}

From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java

@SuppressWarnings("ConstantConditions")
public static void updateSubscriptionCategoryTitleAt(final Context context, final String category,
        final String newTitle, final int position) {
    final LinkedListMultimap<String, String> subscriptions = getSubscriptions(context);
    final String title = getSubscriptionTitleAt(context, position);

    final List<String> values = subscriptions.get(title);
    final boolean newCategory = !values.get(0).equals(category);

    if (newCategory || !newTitle.equals(title)) {
        if (newCategory) {
            final List<String> newValues = new ArrayList<>(subscriptions.removeAll(title));
            newValues.set(0, category);

            subscriptions.putAll(newTitle, newValues);
        } else {/*from  ww w .j a va 2s.c o m*/
            subscriptions.putAll(newTitle, subscriptions.removeAll(title));
        }

        saveSubscriptions(context, subscriptions);

        updateCurrentFeedPosition(context, newTitle);
    }
}

From source file:eu.tsp.sal.WSN.java

/**
 * Initializes a random population with a fixed number of 1s (m)
 * @param   M       fixed number of OA/*from  w ww  . ja  v  a2  s.  c o m*/
 * @param   len     lenth of chromosome
 * @param   popSize population size
 */
private static ElitisticListPopulation randomPopulationWithFixedOA(int M, int len, int popSize) {
    List<Chromosome> popList = new ArrayList();

    for (int i = 0; i < popSize; i++) {
        List<Integer> rList = new ArrayList<Integer>(len);

        // Level 1 encoding with a fixed number of 1s
        for (int j = 0; j < len; j++)
            rList.add(0);
        int count = 0;
        while (count < M) {
            int index = GeneticAlgorithm.getRandomGenerator().nextInt(len);
            if (rList.get(index) == 0) {
                rList.set(index, 1);
                count++;
            }
        }

        // Level 2 encoding
        // update 0 with a random number according to the algorithm
        // random of (cj, cj + M)
        int c = 2;
        for (int j = 0; j < rList.size(); j++) {
            int e = rList.get(j);
            if (e == 1)
                continue;
            else {
                int val = c + GeneticAlgorithm.getRandomGenerator().nextInt(M);
                rList.set(j, val);
                c += M;
            }
        }

        Chromosome randChrom = new SensorIndividual(rList);
        popList.add(randChrom);

    }
    return new ElitisticListPopulation(popList, popList.size(), ELITISM_RATE);
}

From source file:Main.java

public static <E> void reverse(List<E> list, final int begin, final int end) {
    if (end <= begin)
        throw new IllegalArgumentException("end <= begin");

    if (end - begin == 1)
        return;//from   w  ww  .  j a  va2 s  .  com

    List<E> reversed = new ArrayList<E>(end - begin);

    for (int i = begin; i != end; ++i) {
        final int j = begin + (end - i - 1);
        reversed.add(list.get(j));
    }

    for (int i = 0; i != reversed.size(); ++i)
        list.set(begin + i, reversed.get(i));
}

From source file:PackageUtils.java

public static String getPackageNameByNameSpaceURI(String nameSpaceURI) {
    int idx = nameSpaceURI.indexOf(':');
    String scheme = "";
    if (idx >= 0) {
        scheme = nameSpaceURI.substring(0, idx);
        if ("http".equalsIgnoreCase(scheme) || "urn".equalsIgnoreCase(scheme)) {
            nameSpaceURI = nameSpaceURI.substring(idx + 1);
        }//from  w w  w . j ava  2 s .co m
    }

    List<String> tokens = tokenize(nameSpaceURI, "/: ");
    if (tokens.size() == 0) {
        return null;
    }

    if (tokens.size() > 1) {
        String lastToken = tokens.get(tokens.size() - 1);
        idx = lastToken.lastIndexOf('.');
        if (idx > 0) {
            lastToken = lastToken.substring(0, idx);
            tokens.set(tokens.size() - 1, lastToken);
        }
    }

    String domain = tokens.get(0);
    idx = domain.indexOf(':');
    if (idx >= 0) {
        domain = domain.substring(0, idx);
    }
    List<String> r = reverse(tokenize(domain, "urn".equals(scheme) ? ".-" : "."));
    if ("www".equalsIgnoreCase(r.get(r.size() - 1))) {
        // remove leading www
        r.remove(r.size() - 1);
    }

    // replace the domain name with tokenized items
    tokens.addAll(1, r);
    tokens.remove(0);

    // iterate through the tokens and apply xml->java name algorithm
    for (int i = 0; i < tokens.size(); i++) {

        // get the token and remove illegal chars
        String token = tokens.get(i);
        token = removeIllegalIdentifierChars(token);

        // this will check for reserved keywords
        if (containsReservedKeywords(token)) {
            token = '_' + token;
        }

        tokens.set(i, token.toLowerCase());
    }

    // concat all the pieces and return it
    return combine(tokens, '.');
}

From source file:com.dungnv.vfw5.base.utils.StringUtils.java

public static List<String> trimString(List<String> list, Boolean isLower) {

    String str = null;//from   w  w  w  .  j  ava2s. c o m
    for (int i = 0; i < list.size(); i++) {
        str = list.get(i);
        formatString(str);
        list.set(i, str);
    }
    return list;
}

From source file:com.dungnv.vfw5.base.utils.StringUtils.java

public static void escapeHTMLString(List escapeObjectList) {
    Object obj = null;//from   w w  w .j ava 2s.  co m
    for (int i = 0; i < escapeObjectList.size(); i++) {
        obj = escapeObjectList.get(i);
        escapeHTMLString(obj);
        escapeObjectList.set(i, obj);
    }
}