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:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ManagePagePreprocessor.java

private void replaceEncodedQuotesInList(ProcessDataGetterN3 pn, List<String> values) {
    int i;/*from  ww  w.j a v a 2 s  . c om*/
    int len = values.size();
    for (i = 0; i < len; i++) {
        String value = values.get(i);
        if (value.contains("&quot;") || value.contains("&#39;")) {
            value = pn.replaceEncodedQuotesWithEscapedQuotes(value);
            values.set(i, value);
        }
    }
}

From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.SubstituteVariableVisitor.java

@Override
public Void visitAssignOperator(AssignOperator op, Pair<LogicalVariable, LogicalVariable> pair)
        throws AlgebricksException {
    List<LogicalVariable> variables = op.getVariables();
    int n = variables.size();
    for (int i = 0; i < n; i++) {
        if (variables.get(i).equals(pair.first)) {
            variables.set(i, pair.second);
        } else {/*from w ww . ja  v a 2 s  .c om*/
            op.getExpressions().get(i).getValue().substituteVar(pair.first, pair.second);
        }
    }
    // Substitute variables stored in ordering property
    if (op.getExplicitOrderingProperty() != null) {
        List<OrderColumn> orderColumns = op.getExplicitOrderingProperty().getOrderColumns();
        for (int i = 0; i < orderColumns.size(); i++) {
            OrderColumn oc = orderColumns.get(i);
            if (oc.getColumn().equals(pair.first)) {
                orderColumns.set(i, new OrderColumn(pair.second, oc.getOrder()));
            }
        }
    }
    substVarTypes(op, pair);
    return null;
}

From source file:gov.nih.nci.caintegrator.application.query.ResultHandlerImpl.java

/**
 * This function assumes a QueryResult with no columns, just rows, and it fills in the columns
 * and values for each row.// w  w w .j a v  a 2 s.  co  m
 * @param queryResult - object that contains the rows.
 * @param dao
 */
private void addColumns(QueryResult queryResult, CaIntegrator2Dao dao) {
    Query query = queryResult.getQuery();
    Collection<ResultColumn> columns = query.retrieveVisibleColumns();
    columns = removeUnauthorizedColumns(columns, query, dao);
    Collection<ResultRow> resultRows = queryResult.getRowCollection();
    for (ResultRow row : resultRows) {
        List<ResultValue> valueList = new ArrayList<ResultValue>();
        for (int i = 0; i < columns.size(); i++) {
            valueList.add(null);
        }
        for (ResultColumn column : columns) {
            EntityTypeEnum entityType = column.getEntityType();
            ResultValue resultValue = new ResultValue();
            resultValue.setColumn(column);
            resultValue.setValue(null);
            valueList.set(column.getColumnIndex(), resultValue);
            switch (entityType) {
            case IMAGESERIES:
                resultValue.setValue(handleImageSeriesRow(row, column));
                break;
            case SAMPLE:
                resultValue.setValue(handleSampleRow(row, column));
                break;
            case SUBJECT:
                resultValue.setValue(handleSubjectRow(row, column));
                break;
            default:
                // Might need to throw some sort of error in this case?
                resultValue.setValue(null);
                break;
            }
        }
        row.setValueCollection(valueList);
    }
}

From source file:edu.unc.cs.gamma.rvo.KdTree.java

/**
 * Recursive method for building an obstacle k-D tree.
 *
 * @param obstacles A list of obstacles.
 * @return An obstacle k-D tree node.//from w  ww .j  a v  a 2s .c o m
 */
private static ObstacleTreeNode buildObstacleTreeRecursive(List<Obstacle> obstacles) {
    if (obstacles.isEmpty()) {
        return null;
    }

    final ObstacleTreeNode node = new ObstacleTreeNode();

    int optimalSplit = 0;
    int minLeft = obstacles.size();
    int minRight = obstacles.size();

    for (int i = 0; i < obstacles.size(); i++) {
        int leftSize = 0;
        int rightSize = 0;

        final Obstacle obstacleI1 = obstacles.get(i);
        Obstacle obstacleI2 = obstacleI1.next;

        // Compute optimal split node.
        for (int j = 0; j < obstacles.size(); j++) {
            if (i == j) {
                continue;
            }

            final Obstacle obstacleJ1 = obstacles.get(j);
            final Obstacle obstacleJ2 = obstacleJ1.next;

            final double j1LeftOfI = RVOMath.leftOf(obstacleI1.point, obstacleI2.point, obstacleJ1.point);
            final double j2LeftOfI = RVOMath.leftOf(obstacleI1.point, obstacleI2.point, obstacleJ2.point);

            if (j1LeftOfI >= -RVOMath.EPSILON && j2LeftOfI >= -RVOMath.EPSILON) {
                leftSize++;
            } else if (j1LeftOfI <= RVOMath.EPSILON && j2LeftOfI <= RVOMath.EPSILON) {
                rightSize++;
            } else {
                leftSize++;
                rightSize++;
            }

            final Pair<Integer, Integer> pair1 = new Pair<>(FastMath.max(leftSize, rightSize),
                    FastMath.min(leftSize, rightSize));
            final Pair<Integer, Integer> pair2 = new Pair<>(FastMath.max(minLeft, minRight),
                    FastMath.min(minLeft, minRight));

            if (!(pair1.getFirst() < pair2.getFirst()
                    || pair1.getFirst() <= pair2.getFirst() && pair1.getSecond() < pair2.getSecond())) {
                break;
            }
        }

        final Pair<Integer, Integer> pair1 = new Pair<>(FastMath.max(leftSize, rightSize),
                FastMath.min(leftSize, rightSize));
        final Pair<Integer, Integer> pair2 = new Pair<>(FastMath.max(minLeft, minRight),
                FastMath.min(minLeft, minRight));

        if (pair1.getFirst() < pair2.getFirst()
                || pair1.getFirst() <= pair2.getFirst() && pair1.getSecond() < pair2.getSecond()) {
            minLeft = leftSize;
            minRight = rightSize;
            optimalSplit = i;
        }
    }

    // Build split node.
    final List<Obstacle> leftObstacles = new ArrayList<>(minLeft);

    for (int n = 0; n < minLeft; n++) {
        leftObstacles.add(null);
    }

    final List<Obstacle> rightObstacles = new ArrayList<>(minRight);

    for (int n = 0; n < minRight; n++) {
        rightObstacles.add(null);
    }

    int leftCounter = 0;
    int rightCounter = 0;

    final Obstacle obstacleI1 = obstacles.get(optimalSplit);
    final Obstacle obstacleI2 = obstacleI1.next;

    for (int j = 0; j < obstacles.size(); j++) {
        if (optimalSplit == j) {
            continue;
        }

        final Obstacle obstacleJ1 = obstacles.get(j);
        final Obstacle obstacleJ2 = obstacleJ1.next;

        final double j1LeftOfI = RVOMath.leftOf(obstacleI1.point, obstacleI2.point, obstacleJ1.point);
        final double j2LeftOfI = RVOMath.leftOf(obstacleI1.point, obstacleI2.point, obstacleJ2.point);

        if (j1LeftOfI >= -RVOMath.EPSILON && j2LeftOfI >= -RVOMath.EPSILON) {
            leftObstacles.set(leftCounter++, obstacles.get(j));
        } else if (j1LeftOfI <= RVOMath.EPSILON && j2LeftOfI <= RVOMath.EPSILON) {
            rightObstacles.set(rightCounter++, obstacles.get(j));
        } else {
            // Split obstacle j.
            final double t = RVOMath.det(obstacleI2.point.subtract(obstacleI1.point),
                    obstacleJ1.point.subtract(obstacleI1.point))
                    / RVOMath.det(obstacleI2.point.subtract(obstacleI1.point),
                            obstacleJ1.point.subtract(obstacleJ2.point));

            final Vector2D splitPoint = obstacleJ1.point
                    .add(obstacleJ2.point.subtract(obstacleJ1.point).scalarMultiply(t));

            final Obstacle newObstacle = new Obstacle();
            newObstacle.point = splitPoint;
            newObstacle.previous = obstacleJ1;
            newObstacle.next = obstacleJ2;
            newObstacle.convex = true;
            newObstacle.direction = obstacleJ1.direction;

            newObstacle.id = Simulator.instance.obstacles.size();

            Simulator.instance.obstacles.add(newObstacle);

            obstacleJ1.next = newObstacle;
            obstacleJ2.previous = newObstacle;

            if (j1LeftOfI > 0.0) {
                leftObstacles.set(leftCounter++, obstacleJ1);
                rightObstacles.set(rightCounter++, newObstacle);
            } else {
                rightObstacles.set(rightCounter++, obstacleJ1);
                leftObstacles.set(leftCounter++, newObstacle);
            }
        }
    }

    node.obstacle = obstacleI1;
    node.left = buildObstacleTreeRecursive(leftObstacles);
    node.right = buildObstacleTreeRecursive(rightObstacles);

    return node;
}

From source file:cn.vlabs.duckling.vwb.service.login.UMT2LoginAction.java

private void replaceUserPrincipal(List<Principal> principals, UserPrincipal userp) {
    if (principals != null) {
        for (int i = 0; i < principals.size(); i++) {
            if (principals.get(i) instanceof cn.vlabs.commons.principal.UserPrincipal) {
                UserPrincipal up = (UserPrincipal) principals.get(i);
                UserPrincipal newup = new UserPrincipal(userp.getName(), up.getDisplayName(), up.getEmail(),
                        userp.getAuthBy());
                principals.set(i, newup);
                break;
            }/*w  w w.  j  av  a  2  s  . c  o m*/
        }
    }
}

From source file:banner.tagging.dictionary.DictionaryTagger.java

private void add2Part(String part1, String part2, Collection<EntityType> types) {
    List<String> tokens = new ArrayList<String>();
    tokens.add(part1 + part2);/*from  w  w w.  j av a  2 s .  c  om*/
    tokens.add(part2);
    add(tokens, types);
    tokens = new ArrayList<String>();
    tokens.add(part1);
    tokens.add(part2);
    add(tokens, types);
    tokens.add(1, "-");
    add(tokens, types);
    tokens.set(1, "/");
    add(tokens, types);
}

From source file:com.gargoylesoftware.htmlunit.source.BrowserVersionFeaturesSource.java

private void generate(final File dir, final String toSearchFor, final BrowserVersion[] versions)
        throws IOException {
    final File propertiesFolder = new File(root_,
            "src/main/resources/com/gargoylesoftware/htmlunit/javascript/configuration");
    final File featuresFile = new File(root_,
            "src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java");
    for (final File f : dir.listFiles()) {
        if (f.isDirectory()) {
            if (!".svn".equals(f.getName())) {
                generate(f, toSearchFor, versions);
            }/* w w w .  j  a  v  a 2 s. c  o m*/
        } else if (!"JavaScriptConfiguration.java".equals(f.getName())) {
            final List<String> lines = FileUtils.readLines(f);
            boolean modified = false;
            for (int i = 0; i < lines.size(); i++) {
                String line = lines.get(i);
                if (line.contains(toSearchFor)) {
                    line = line.replace(toSearchFor,
                            ".hasFeature(BrowserVersionFeatures." + GENERATED_PREFIX + generatedNext_ + ")");
                    lines.set(i, line);
                    modified = true;

                    final List<String> featuresLines = FileUtils.readLines(featuresFile);
                    featuresLines.add(featuresLines.size() - 4, "");
                    featuresLines.add(featuresLines.size() - 4,
                            "    /** Was originally " + toSearchFor + ". */");
                    featuresLines.add(featuresLines.size() - 4,
                            "    " + GENERATED_PREFIX + generatedNext_ + ",");
                    FileUtils.writeLines(featuresFile, featuresLines);

                    for (final File file : propertiesFolder.listFiles(new FileFilter() {
                        public boolean accept(final File pathname) {
                            for (final BrowserVersion version : versions) {
                                if (pathname.getName().equals(version.getNickname() + ".properties")) {
                                    return true;
                                }
                            }
                            return false;
                        }
                    })) {
                        final List<String> features = FileUtils.readLines(file);
                        features.add(GENERATED_PREFIX + generatedNext_);
                        Collections.sort(features);
                        FileUtils.writeLines(file, features);
                    }
                    generatedNext_++;
                }
            }
            if (modified) {
                FileUtils.writeLines(f, lines);
            }
        }
    }
}

From source file:com.mythesis.profileanalysis.Utils.java

/**
 * a method that removes most frequent words from a collection of documents
 * @param wordsToSetOfDocs words and the documents they appear in
 * @param docs list of docs/*from  www .  j  a v a  2  s . c o  m*/
 * @return list of docs without the most frequent words
 */
private List<String> removeFrequentWords(Map<String, HashSet<Integer>> wordsToSetOfDocs, List<String> docs) {

    int upperThreshold = (int) (0.7 * docs.size()); //remove words that appear in more than 70% of documents
    for (String word : wordsToSetOfDocs.keySet()) {
        if (wordsToSetOfDocs.get(word).size() > upperThreshold) {
            for (int i = 0; i < docs.size(); i++) {
                String regex = "\\b" + word + "\\b";
                String content = docs.get(i).replaceAll(regex, " ");
                docs.set(i, content);
            }
        }
    }

    return docs;

}

From source file:com.sangupta.fileanalysis.formats.ApacheLogFileHandler.java

private static List<String> parseLogLine(final String logLine) {
    List<String> tokens = parseBaseTokens(logLine);

    // bifurcate the request method etc as well
    int endIndex = tokens.size();
    for (int index = 0; index < endIndex; index++) {
        String token = tokens.get(index);

        // check for http verb
        if (FileAnalysisHelper.startsWithAny(token, HTTP_VERBS)) {
            int space = token.indexOf(' ');
            if (space != -1) {
                String verb = token.substring(0, space);
                if (FileAnalysisHelper.isAnyOf(verb, HTTP_VERBS)) {
                    // add a new token here - verb comes first
                    tokens.add(index, verb);
                    index++;//ww w .jav a 2 s .  co  m
                    endIndex++;

                    // extract protocol
                    int lastSpace = token.lastIndexOf(' ');
                    if (lastSpace != space) {
                        String protocol = token.substring(lastSpace + 1);
                        tokens.add(index + 1, protocol);
                        index++;
                        endIndex++;
                    }

                    // trim the current path
                    if (space != lastSpace) {
                        token = token.substring(space + 1, lastSpace);
                        tokens.set(index - 1, token);
                    } else {
                        token = token.substring(space + 1);
                        tokens.set(index - 1, token);
                    }

                    continue;
                }
            }
        }

        // check for OS
        if (FileAnalysisHelper.containsAny(token, OS_DECIPHER_WORDS)
                && FileAnalysisHelper.containsAny(token, BROWSER_DECIPHER_WORDS)) {
            String os = decipherOSFromUserAgent(token);
            if (os != null) {
                tokens.add(index, os);
                index++;
                endIndex++;
                continue;
            }
        }
    }

    return tokens;
}

From source file:org.psikeds.common.interceptor.RequestIdGenerationInterceptor.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private void addRequestIdToParams(final T message, final String reqid) {
    List parameters = message.getContent(List.class);
    if (parameters == null) {
        parameters = new ArrayList<String>();
    }/*from   w  ww  .j  av a 2s  .co  m*/
    if (parameters.isEmpty()) {
        LOGGER.trace("Adding new Parameter for Request-Id.");
        parameters.add(reqid);
    } else {
        LOGGER.trace("Replacing last Parameter with Request-Id.");
        parameters.set(parameters.size() - 1, reqid);
    }
    message.setContent(List.class, parameters);
}