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:de.hub.cs.dbis.aeolus.queries.utils.TimestampMergerTest.java

@SuppressWarnings("unchecked")
private void testExecuteMerge(int numberOfProducers, int numberOfTasks, double duplicatesFraction,
        boolean tsIndexOrName, int minNumberOfAttributes, int maxNumberOfAttributes) {
    int createdTasks = this.mockInputs(numberOfProducers, numberOfTasks, tsIndexOrName, minNumberOfAttributes,
            maxNumberOfAttributes);/*from ww w. j  a v  a  2  s . c  o  m*/

    final int numberOfTuples = createdTasks * 10 + this.r.nextInt(createdTasks * (1 + this.r.nextInt(10)));
    TimestampOrderChecker checkerBolt;
    TimestampMerger merger;
    if (tsIndexOrName) {
        checkerBolt = new TimestampOrderChecker(forwarder, 0, duplicatesFraction != 0);
        merger = new TimestampMerger(checkerBolt, 0);
    } else {
        checkerBolt = new TimestampOrderChecker(forwarder, "ts", duplicatesFraction != 0);
        merger = new TimestampMerger(checkerBolt, "ts");
    }
    TestOutputCollector collector = new TestOutputCollector();

    merger.prepare(null, this.topologyContextMock, new OutputCollector(collector));

    this.input = new LinkedList[createdTasks];
    for (int i = 0; i < createdTasks; ++i) {
        this.input[i] = new LinkedList<Tuple>();
    }
    this.result.clear();

    int numberDistinctValues = 1;
    int counter = 0;
    while (true) {
        int taskId = this.r.nextInt(createdTasks);

        Fields schema = this.contextMock.getComponentOutputFields(this.contextMock.getComponentId(taskId),
                null);
        int numberOfAttributes = schema.size();
        List<Object> value = new ArrayList<Object>(numberOfAttributes);
        for (int i = 0; i < numberOfAttributes; ++i) {
            value.add(new Character((char) (32 + this.r.nextInt(95))));
        }
        Long ts = new Long(numberDistinctValues - 1);
        value.set(schema.fieldIndex("ts"), ts);

        this.result.add(value);
        this.input[taskId].add(new TupleImpl(this.contextMock, value, taskId, null));

        if (++counter == numberOfTuples) {
            break;
        }

        if (1 - this.r.nextDouble() > duplicatesFraction) {
            ++numberDistinctValues;
        }
    }

    int[] max = new int[createdTasks];
    int[][] bucketSums = new int[createdTasks][numberDistinctValues];
    for (int i = 0; i < numberOfTuples; ++i) {
        int taskId = this.r.nextInt(createdTasks);

        while (this.input[taskId].size() == 0) {
            taskId = (taskId + 1) % createdTasks;
        }

        Tuple t = this.input[taskId].removeFirst();
        max[taskId] = t.getLongByField("ts").intValue();
        ++bucketSums[taskId][max[taskId]];
        merger.execute(t);
    }

    int stillBuffered = numberOfTuples;
    int smallestMax = Collections.min(Arrays.asList(ArrayUtils.toObject(max))).intValue();
    for (int i = 0; i < createdTasks; ++i) {
        for (int j = 0; j <= smallestMax; ++j) {
            stillBuffered -= bucketSums[i][j];
        }
    }

    Assert.assertEquals(this.result.subList(0, this.result.size() - stillBuffered),
            collector.output.get(Utils.DEFAULT_STREAM_ID));
    Assert.assertTrue(collector.acked.size() == numberOfTuples - stillBuffered);
    Assert.assertTrue(collector.failed.size() == 0);

}

From source file:com.aol.one.patch.DefaultPatcher.java

private void invokeReplaceMethod(Object object, String fieldName, JsonNode valueNode)
        throws IllegalAccessException, InvocationTargetException, PatchException {

    if (object instanceof Patchable) {
        Patchable patchable = (Patchable) object;
        patchable.replaceValue(fieldName, valueNode);
        return;//from w  w w.jav  a  2s. c om
    }

    boolean isFieldNameNumeric = StringUtils.isNumeric(fieldName);

    if (isFieldNameNumeric && object instanceof java.util.List) {
        List tmpList = (List) object;
        // WARN: inserting JsonNode into list
        // NOTE: not add, but set.
        tmpList.set(Integer.parseInt(fieldName), valueNode);
        return;
    }

    if (isFieldNameNumeric && object instanceof java.util.Map) {
        Map tmpMap = (Map) object;
        // WARN: removing string key from Map, key type of Map not known.
        tmpMap.remove(fieldName);
        // WARN: adding JsonNode into Map
        tmpMap.put(fieldName, valueNode);
        return;
    }

    // first try to find replace+CapitalizedField
    List<String> methodNames = new ArrayList<>();
    methodNames.add("replace" + StringUtils.capitalize(fieldName));
    // next, set + capitalizedField
    methodNames.add("set" + StringUtils.capitalize(fieldName));
    List<MethodData> methodDataList = generateMethodData(methodNames, valueNode);

    // final try, standard method
    List<Class<?>> argTypes = new ArrayList<>();
    argTypes.add(String.class);
    argTypes.add(JsonNode.class);

    List<Object> params = new ArrayList<>();
    params.add(fieldName);
    params.add(valueNode);

    MethodData standardMethodData = new MethodData(STANDARD_REPLACE_METHOD, argTypes, params);
    methodDataList.add(standardMethodData);

    invokeMethodFromMethodDataList(object, methodDataList);
}

From source file:de.tudarmstadt.lt.lm.lucenebased.CountingStringLM.java

public int addNgramAsIds(List<Integer> ngram) throws IllegalAccessException {
    List<String> ngram_s = Arrays.asList(new String[ngram.size()]);
    for (int i = 0; i < ngram.size(); i++) {
        String w = getWord(ngram.get(i));
        ngram_s.set(i, w == null ? String.format("_%d_", ngram.get(i)) : w);
    }//  www. j  a va2 s  .  c om
    return addNgram(ngram_s);
}

From source file:de.micromata.genome.gwiki.umgmt.GWikiUserAuthorization.java

List<String> getRoleListFromUserRoleString(String roleString) {
    if (StringUtils.isEmpty(roleString)) {
        return Collections.emptyList();
    }//from   www .j a  v a  2s  .  co  m
    List<String> roles = Converter.parseStringTokens(roleString, ",", false);
    for (int i = 0; i < roles.size(); ++i) {
        String role = roles.get(i);

        if (role.startsWith("+") == true) {
            role = role.substring(1);
            roles.set(i, role);
        }
    }
    return roles;
}

From source file:edu.uga.cs.fluxbuster.features.FeatureCalculator.java

/**
 * Calculates the previous cluster ratio feature for each cluster generated
 * on a specific run date and within the a specific window
 *
 * @param log_date the run date/* w ww .  j  ava2s.c  o  m*/
 * @param window the number of days previous to use in feature calculation
 * @return a table of results, the keys of the table are cluster ids and the
 *       values are lists of two elements.  The first element is the 
 *       last_growth_ratio_prev_clusters value and the second element is the
 *       last_growth_prefix_ratio_prev_clusters value
 * @throws SQLException if there is and error calculating the feature
 */
public Hashtable<Integer, List<Double>> calculatePrevClusterRatios(Date log_date, int window)
        throws SQLException {
    Hashtable<Integer, List<Double>> retval = new Hashtable<Integer, List<Double>>();

    ArrayList<Date> prevDates = getPrevDates(log_date, window);
    String query1 = properties.getProperty(PREVCLUSTER_QUERY1KEY);
    String query2 = properties.getProperty(PREVCLUSTER_QUERY2KEY);
    String logDateStr = df.format(log_date);
    String completequery = new String();

    StringBuffer addQueryBuff = new StringBuffer();
    for (int i = 0; i < prevDates.size(); i++) {
        String prevDateStr = df.format(prevDates.get(i));
        StringBuffer querybuf = new StringBuffer();
        Formatter formatter = new Formatter(querybuf);
        formatter.format(query1, logDateStr, logDateStr, prevDateStr, prevDateStr, prevDateStr);
        addQueryBuff.append(querybuf.toString());
        if (i < prevDates.size() - 1) {
            addQueryBuff.append(" UNION ");
        }
        formatter.close();
    }

    if (addQueryBuff.length() > 0) {
        StringBuffer querybuf = new StringBuffer();
        Formatter formatter = new Formatter(querybuf);
        formatter.format(query2, logDateStr, logDateStr, addQueryBuff.toString());
        completequery = querybuf.toString();
        formatter.close();
    }

    if (completequery.length() > 0) {
        ResultSet rs = null;
        try {
            rs = dbi.executeQueryWithResult(completequery);
            while (rs.next()) {
                ArrayList<Double> temp = new ArrayList<Double>();
                temp.add(rs.getDouble(3));
                temp.add(rs.getDouble(4));
                retval.put(rs.getInt(1), temp);
            }
        } catch (Exception e) {
            if (log.isErrorEnabled()) {
                log.error(e);
            }
        } finally {
            if (rs != null && !rs.isClosed()) {
                rs.close();
            }
        }
        Hashtable<Integer, Double> queryPerDomain = getQueriesPerDomain(log_date);
        for (Integer clusterid : retval.keySet()) {
            List<Double> values = retval.get(clusterid);
            values.set(0, values.get(0) / queryPerDomain.get(clusterid));
            values.set(1, values.get(1) / queryPerDomain.get(clusterid));
        }
    }

    return retval;
}

From source file:grakn.core.console.test.GraknConsoleIT.java

private String[] addKeyspaceAndUriParams(String[] args) {
    List<String> argList = Lists.newArrayList(args);

    int keyspaceIndex = argList.indexOf("-k") + 1;
    if (keyspaceIndex == 0) {
        argList.add("-k");
        argList.add(GraknConsole.DEFAULT_KEYSPACE);
        keyspaceIndex = argList.size() - 1;
    }/*from  ww w.j  a  va 2 s. c om*/

    argList.set(keyspaceIndex, argList.get(keyspaceIndex) + keyspaceSuffix);

    boolean uriSpecified = argList.contains("-r");
    if (!uriSpecified) {
        argList.add("-r");
        argList.add(server.grpcUri());
    }

    return argList.toArray(new String[argList.size()]);
}

From source file:org.codehaus.griffon.commons.GriffonClassUtils.java

/**
 * Converts a property name into its natural language equivalent eg ('firstName' becomes 'First Name')
 * @param name The property name to convert
 * @return The converted property name/*from w  w w.j ava2 s  . c  o m*/
 */
public static String getNaturalName(String name) {
    List words = new ArrayList();
    int i = 0;
    char[] chars = name.toCharArray();
    for (int j = 0; j < chars.length; j++) {
        char c = chars[j];
        String w;
        if (i >= words.size()) {
            w = "";
            words.add(i, w);
        } else {
            w = (String) words.get(i);
        }

        if (Character.isLowerCase(c) || Character.isDigit(c)) {
            if (Character.isLowerCase(c) && w.length() == 0)
                c = Character.toUpperCase(c);
            else if (w.length() > 1 && Character.isUpperCase(w.charAt(w.length() - 1))) {
                w = "";
                words.add(++i, w);
            }

            words.set(i, w + c);
        } else if (Character.isUpperCase(c)) {
            if ((i == 0 && w.length() == 0) || Character.isUpperCase(w.charAt(w.length() - 1))) {
                words.set(i, w + c);
            } else {
                words.add(++i, String.valueOf(c));
            }
        }

    }

    StringBuffer buf = new StringBuffer();

    for (Iterator j = words.iterator(); j.hasNext();) {
        String word = (String) j.next();
        buf.append(word);
        if (j.hasNext())
            buf.append(' ');
    }
    return buf.toString();
}

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

private List<String> query_payInfo(Duration duration) throws IOException {
    getPageAttributes(PAYINFO_SUFFIX);//w  w  w  .  j a v a2  s  .  c  om
    String OUTPUT_DATA = "But_Seach3=";
    switch (duration) {
    case ONE_MONTH:
        OUTPUT_DATA += ONE_MONTH;
        break;
    case THREE_MONTH:
        OUTPUT_DATA += THREE_MONTH;
        break;
    default:
        throw new IllegalArgumentException("Bad parameter, check document for help");
    }
    OUTPUT_DATA += "&__VIEWSTATE=";
    OUTPUT_DATA += VIEWSTATE;
    OUTPUT_DATA += "&HiddenField_webName=";
    OUTPUT_DATA += "&HiddenField_UserID=";
    OUTPUT_DATA += ID;

    Document document = getPage(OUTPUT_DATA, PAYINFO_SUFFIX);
    Elements elements = document.select("td");

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

    for (Element td : elements) {
        String tmp = td.text();
        if (!"".equals(tmp)) {
            stringArrayList.add(tmp);
        }
    }

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

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

From source file:de.hub.cs.dbis.aeolus.utils.TimestampMergerTest.java

@SuppressWarnings("unchecked")
private void testExecuteMerge(int numberOfProducers, int numberOfTasks, double duplicatesFraction,
        boolean tsIndexOrName, int minNumberOfAttributes, int maxNumberOfAttributes) {
    int createdTasks = this.mockInputs(numberOfProducers, numberOfTasks, tsIndexOrName, minNumberOfAttributes,
            maxNumberOfAttributes);//from ww w  .  jav a2  s . co m

    final int numberOfTuples = createdTasks * 10 + this.r.nextInt(createdTasks * (1 + this.r.nextInt(10)));
    TimestampOrderChecker checkerBolt;
    TimestampMerger merger;
    if (tsIndexOrName) {
        checkerBolt = new TimestampOrderChecker(forwarder, 0, duplicatesFraction != 0);
        merger = new TimestampMerger(checkerBolt, 0);
    } else {
        checkerBolt = new TimestampOrderChecker(forwarder, "ts", duplicatesFraction != 0);
        merger = new TimestampMerger(checkerBolt, "ts");
    }
    TestOutputCollector collector = new TestOutputCollector();

    merger.prepare(null, this.topologyContextMock, new OutputCollector(collector));

    this.input = new LinkedList[createdTasks];
    for (int i = 0; i < createdTasks; ++i) {
        this.input[i] = new LinkedList<Tuple>();
    }
    this.result.clear();

    int numberDistinctValues = 1;
    int counter = 0;
    while (true) {
        int taskId = this.r.nextInt(createdTasks);

        Fields schema = this.contextMock.getComponentOutputFields(this.contextMock.getComponentId(taskId),
                null);
        int numberOfAttributes = schema.size();
        List<Object> value = new ArrayList<Object>(numberOfAttributes);
        for (int i = 0; i < numberOfAttributes; ++i) {
            value.add(new Character((char) (32 + this.r.nextInt(95))));
        }
        Long ts = new Long(numberDistinctValues - 1);
        value.set(schema.fieldIndex("ts"), ts);

        this.result.add(value);
        this.input[taskId].add(new TupleImpl(this.contextMock, value, taskId, null));

        if (++counter == numberOfTuples) {
            break;
        }

        if (1 - this.r.nextDouble() > duplicatesFraction) {
            ++numberDistinctValues;
        }
    }

    int[] max = new int[createdTasks];
    for (int i = 0; i < max.length; ++i) {
        max[i] = -1;
    }
    int[][] bucketSums = new int[createdTasks][numberDistinctValues];
    for (int i = 0; i < numberOfTuples; ++i) {
        int taskId = this.r.nextInt(createdTasks);

        while (this.input[taskId].size() == 0) {
            taskId = (taskId + 1) % createdTasks;
        }

        Tuple t = this.input[taskId].removeFirst();
        max[taskId] = t.getLongByField("ts").intValue();
        ++bucketSums[taskId][max[taskId]];
        merger.execute(t);
    }

    int stillBuffered = numberOfTuples;
    int smallestMax = Collections.min(Arrays.asList(ArrayUtils.toObject(max))).intValue();
    for (int i = 0; i < createdTasks; ++i) {
        for (int j = 0; j <= smallestMax; ++j) {
            stillBuffered -= bucketSums[i][j];
        }
    }
    List<List<Object>> expectedResult = this.result.subList(0, this.result.size() - stillBuffered);

    if (expectedResult.size() > 0) {
        Assert.assertEquals(expectedResult, collector.output.get(Utils.DEFAULT_STREAM_ID));
    } else {
        Assert.assertNull(collector.output.get(Utils.DEFAULT_STREAM_ID));
    }
    Assert.assertTrue(collector.acked.size() == numberOfTuples - stillBuffered);
    Assert.assertTrue(collector.failed.size() == 0);

}

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

@Override
public Void visitProjectOperator(ProjectOperator op, Pair<LogicalVariable, LogicalVariable> pair)
        throws AlgebricksException {
    List<LogicalVariable> usedVariables = op.getVariables();
    int n = usedVariables.size();
    for (int i = 0; i < n; i++) {
        LogicalVariable v = usedVariables.get(i);
        if (v.equals(pair.first)) {
            usedVariables.set(i, pair.second);
        }//from www . j  a va2 s.  c om
    }
    substVarTypes(op, pair);
    return null;
}