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.innovationgate.webgate.api.jdbc.PortletRegistryImplV4.java

@Override
public void updatePortlet(WGPortlet portletToUpdate) throws WGAPIException {

    startProfileEdit();/* w  ww . j av  a  2 s  .  c om*/

    if (portletToUpdate.isRoot()) {
        throw new WGIllegalArgumentException("Cannot update the root portlet");
    }

    List regs = _profile.getPortletkeys();
    for (int idx = 0; idx < regs.size(); idx++) {
        String reg = (String) regs.get(idx);
        WGPortlet portlet = deserializePortlet(reg, portletToUpdate.getApplicationDb());

        // We do not need to check appDb here bc. in this portlet registry impl the appDb is implicitly contained in the portlet key
        if (portlet.getKey().equals(portletToUpdate.getKey())) {
            regs.set(idx, serializePortlet(portletToUpdate));
            return;
        }
    }

    throw new WGIllegalArgumentException(
            "No portlet of id '" + portletToUpdate.getKey() + "' has yet been registered");
}

From source file:cn.com.sinosoft.util.exception.NestableDelegate.java

/**
 * Trims the stack frames. The first set is left untouched. The rest
 * of the frames are truncated from the bottom by comparing with
 * one just on top.//from  w w  w. ja  va 2  s .co  m
 *
 * @param stacks The list containing String[] elements
 * @since 2.0
 */
protected void trimStackFrames(List stacks) {
    for (int size = stacks.size(), i = size - 1; i > 0; i--) {
        String[] curr = (String[]) stacks.get(i);
        String[] next = (String[]) stacks.get(i - 1);

        List currList = new ArrayList(Arrays.asList(curr));
        List nextList = new ArrayList(Arrays.asList(next));
        ExceptionUtils.removeCommonFrames(currList, nextList);

        int trimmed = curr.length - currList.size();
        if (trimmed > 0) {
            currList.add("\t... " + trimmed + " more");
            stacks.set(i, currList.toArray(new String[currList.size()]));
        }
    }
}

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

private List<String> query_useInfo(Duration duration) throws IOException {
    getPageAttributes(USEINFO_SUFFIX);//  w  w  w. jav a  2  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, USEINFO_SUFFIX);
    Elements elements = document.select("td");

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

    for (Element td : elements) {
        String tmp = td.text();
        tmp = tmp.replaceAll(" ", "");
        if (!"".equals(tmp)) {
            if (tmp.contains("???")) {
                stringArrayList.add(tmp.substring(0, tmp.indexOf("???")));
                stringArrayList.add(tmp.substring(tmp.indexOf("???")));
                continue;
            }
            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, ????
     *      - ? [ ? |  | ? | ?/? | ??? ]
     *      - , (5n), n???
     *
     *      - ?: ?null!
     */
    return stringArrayList;
}

From source file:com.github.brandtg.StlDecomposition.java

/**
 * Constructs the STL decomposition of a time series.
 *
 * <p>/*w w  w  . ja  va2  s .  com*/
 *   times.length == series.length
 * </p>
 */
public StlResult decompose(double[] times, double[] series) {
    double[] trend = new double[series.length];
    double[] seasonal = new double[series.length];
    double[] remainder = new double[series.length];
    double[] robustness = null;
    double[] detrend = new double[series.length];
    double[] combinedSmoothed = new double[series.length];

    for (int l = 0; l < config.getNumberOfRobustnessIterations(); l++) {
        for (int k = 0; k < config.getNumberOfInnerLoopPasses(); k++) {
            // Step 1: De-trending
            for (int i = 0; i < series.length; i++) {
                detrend[i] = series[i] - trend[i];
            }

            // Get cycle sub-series with padding on either side
            int numberOfObservations = config.getNumberOfObservations();
            CycleSubSeries cycle = new CycleSubSeries(times, series, robustness, detrend, numberOfObservations);
            cycle.compute();
            List<double[]> cycleSubseries = cycle.getCycleSubSeries();
            List<double[]> cycleTimes = cycle.getCycleTimes();
            List<double[]> cycleRobustnessWeights = cycle.getCycleRobustnessWeights();

            // Step 2: Cycle-subseries Smoothing
            for (int i = 0; i < cycleSubseries.size(); i++) {
                double[] smoothed = loessSmooth(cycleTimes.get(i), cycleSubseries.get(i),
                        config.getSeasonalComponentBandwidth(), cycleRobustnessWeights.get(i));
                cycleSubseries.set(i, smoothed);
            }

            // Combine smoothed series into one
            for (int i = 0; i < cycleSubseries.size(); i++) {
                double[] subseriesValues = cycleSubseries.get(i);
                for (int cycleIdx = 0; cycleIdx < subseriesValues.length; cycleIdx++) {
                    combinedSmoothed[numberOfObservations * cycleIdx + i] = subseriesValues[cycleIdx];
                }
            }

            // Step 3: Low-Pass Filtering of Smoothed Cycle-Subseries
            double[] filtered = lowPassFilter(combinedSmoothed, robustness);

            // Step 4: Detrending of Smoothed Cycle-Subseries
            for (int i = 0; i < seasonal.length; i++) {
                seasonal[i] = combinedSmoothed[i] - filtered[i];
            }

            // Step 5: Deseasonalizing
            for (int i = 0; i < series.length; i++) {
                trend[i] = series[i] - seasonal[i];
            }

            // Step 6: Trend Smoothing
            trend = loessSmooth(times, trend, config.getTrendComponentBandwidth(), robustness);
        }

        // --- Now in outer loop ---

        // Calculate remainder
        for (int i = 0; i < series.length; i++) {
            remainder[i] = series[i] - trend[i] - seasonal[i];
        }

        // Calculate robustness weights using remainder
        robustness = robustnessWeights(remainder);
    }

    if (config.isPeriodic()) {
        for (int i = 0; i < config.getNumberOfObservations(); i++) {
            // Compute weighted mean for one season
            double sum = 0.0;
            int count = 0;
            for (int j = i; j < config.getNumberOfDataPoints(); j += config.getNumberOfObservations()) {
                sum += seasonal[j];
                count++;
            }
            double mean = sum / count;

            // Copy this to rest of seasons
            for (int j = i; j < config.getNumberOfDataPoints(); j += config.getNumberOfObservations()) {
                seasonal[j] = mean;
            }
        }

        // Recalculate remainder
        for (int i = 0; i < series.length; i++) {
            remainder[i] = series[i] - trend[i] - seasonal[i];
        }
    }

    return new StlResult(times, series, trend, seasonal, remainder);
}

From source file:com.amalto.core.storage.hibernate.SystemScatteredTypeMapping.java

Object _setValues(Session session, DataRecord from, Wrapper to) {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    TypeMapping mapping = mappings.getMappingFromUser(from.getType());
    Collection<FieldMetadata> fields;
    if (mapping != null) {
        fields = mapping.getUser().getFields();
    } else {//from  w  w w . j a  v a2s .  c  om
        fields = from.getType().getFields();
    }
    for (FieldMetadata field : fields) {
        FieldMetadata mappedDatabaseField;
        if (mapping != null) {
            mappedDatabaseField = mapping.getDatabase(field);
        } else {
            mappedDatabaseField = getDatabase(field);
        }
        if (mappedDatabaseField == null) {
            continue;
            // throw new IllegalStateException("Field '" + field.getName() + "' was expected to have a database mapping");
        }
        if (field instanceof ContainedTypeFieldMetadata) {
            if (!(mappedDatabaseField instanceof ReferenceFieldMetadata)) {
                throw new IllegalStateException("Contained elements are expected to be mapped to reference.");
            }
            ReferenceFieldMetadata referenceFieldMetadata = (ReferenceFieldMetadata) mappedDatabaseField;
            if (!field.isMany()) {
                DataRecord referencedObject = (DataRecord) readValue(from, field, mappedDatabaseField, session);
                if (referencedObject != null) {
                    TypeMapping mappingFromUser = mappings.getMappingFromUser(referencedObject.getType());
                    ComplexTypeMetadata referencedType = mappingFromUser != null ? mappingFromUser.getDatabase()
                            : referencedObject.getType();
                    Wrapper existingValue = (Wrapper) to.get(referenceFieldMetadata.getName());
                    boolean needCreate = existingValue == null;
                    if (!needCreate) {
                        ComplexTypeMetadata existingType = ((StorageClassLoader) contextClassLoader)
                                .getTypeFromClass(existingValue.getClass());
                        needCreate = !existingType.equals(referencedType);
                    }
                    Wrapper object = needCreate ? createObject(contextClassLoader, referencedType)
                            : existingValue;
                    to.set(referenceFieldMetadata.getName(), _setValues(session, referencedObject, object));
                    if (needCreate) {
                        session.persist(object);
                    }
                } else {
                    to.set(referenceFieldMetadata.getName(), null);
                }
            } else {
                List<DataRecord> dataRecords = (List<DataRecord>) readValue(from, field, mappedDatabaseField,
                        session);
                Object value;
                if (mapping != null) {
                    value = to.get(mapping.getDatabase(field).getName());
                } else {
                    value = to.get(getDatabase(field).getName());
                }
                if (dataRecords != null) {
                    List<Wrapper> existingValue = (List<Wrapper>) value;
                    if (existingValue != null) {
                        ((PersistentList) existingValue).forceInitialization();
                    }
                    List<Wrapper> objects = existingValue == null ? new ArrayList<Wrapper>(dataRecords.size())
                            : existingValue;
                    int i = 0;
                    for (DataRecord dataRecord : dataRecords) {
                        if (i < objects.size() && objects.get(i) != null) {
                            objects.set(i, (Wrapper) _setValues(session, dataRecord, objects.get(i)));
                        } else {
                            Wrapper object = createObject(contextClassLoader, dataRecord.getType());
                            objects.add((Wrapper) _setValues(session, dataRecord, object));
                            session.persist(object);
                        }
                        i++;
                    }
                    // TMDM-5257: Remove the deleted items
                    while (objects.size() > dataRecords.size()) {
                        objects.remove(objects.size() - 1);
                    }
                    to.set(referenceFieldMetadata.getName(), objects);
                } else {
                    if (value != null && value instanceof List) {
                        ((List) value).clear();
                    }
                }
            }
        } else if (field instanceof ReferenceFieldMetadata) {
            if (!field.isMany()) {
                DataRecord referencedObject = (DataRecord) readValue(from, field, mappedDatabaseField, session);
                if (referencedObject != null) {
                    Collection<FieldMetadata> keyFields = referencedObject.getType().getKeyFields();
                    Object referenceId;
                    if (keyFields.size() > 1) {
                        List<Object> referenceIdList = new LinkedList<Object>();
                        for (FieldMetadata keyField : keyFields) {
                            referenceIdList
                                    .add(readValue(referencedObject, keyField, mappedDatabaseField, session));
                        }
                        referenceId = referenceIdList;
                    } else {
                        referenceId = readValue(referencedObject, keyFields.iterator().next(),
                                mappedDatabaseField, session);
                    }
                    to.set(mappedDatabaseField.getName(),
                            getReferencedObject(contextClassLoader, session,
                                    mappings.getMappingFromUser(referencedObject.getType()).getDatabase(),
                                    referenceId));
                } else {
                    to.set(mappedDatabaseField.getName(), null);
                }
            } else {
                List<DataRecord> referencedObjectList = (List<DataRecord>) readValue(from, field,
                        mappedDatabaseField, session);
                if (referencedObjectList != null) {
                    List<Object> wrappers = new LinkedList<Object>();
                    for (DataRecord dataRecord : referencedObjectList) {
                        Collection<FieldMetadata> keyFields = dataRecord.getType().getKeyFields();
                        Object referenceId;
                        if (keyFields.size() > 1) {
                            List<Object> referenceIdList = new LinkedList<Object>();
                            for (FieldMetadata keyField : keyFields) {
                                referenceIdList
                                        .add(readValue(dataRecord, keyField, mappedDatabaseField, session));
                            }
                            referenceId = referenceIdList;
                        } else {
                            referenceId = readValue(dataRecord, keyFields.iterator().next(),
                                    mappedDatabaseField, session);
                        }
                        wrappers.add(getReferencedObject(contextClassLoader, session, dataRecord.getType(),
                                referenceId));
                    }
                    to.set(mappedDatabaseField.getName(), wrappers);
                } else {
                    Object value = to.get(mappedDatabaseField.getName());
                    if (value != null && value instanceof List) {
                        ((List) value).clear();
                    }
                }
            }
        } else {
            if (mappedDatabaseField.isMany()) {
                List<Object> oldValues = (List<Object>) to.get(mappedDatabaseField.getName());
                List<Object> newValues = (List<Object>) readValue(from, field, mappedDatabaseField, session);
                if (oldValues != null) {
                    resetList(oldValues, newValues);
                } else {
                    to.set(mappedDatabaseField.getName(), newValues);
                }
            } else {
                to.set(mappedDatabaseField.getName(), readValue(from, field, mappedDatabaseField, session));
            }
        }
    }
    return to;
}

From source file:dkpro.similarity.uima.io.MeterCorpusReader.java

@Override
public List<CombinationPair> getAlignedPairs() throws ResourceInitializationException {
    List<CombinationPair> pairs = new ArrayList<CombinationPair>();

    List<File> sourceDirs = listDirectories(new File(inputDir.getAbsolutePath() + "/PA/annotated"));
    for (File sourceDir : sourceDirs) {
        File sourceFile = new ArrayList<File>(FileUtils.listFiles(sourceDir, new String[] { "sgml" }, false))
                .get(0);/*from   w  w  w . ja  v a2 s .c o m*/

        File suspiciousDir = new File(
                sourceDir.getAbsolutePath().replace("PA", "newspapers").replace("annotated", "rawtexts"));

        Collection<File> suspiciousFiles = FileUtils.listFiles(suspiciousDir, new String[] { "txt" }, false);

        for (File suspiciousFile : suspiciousFiles) {
            try {
                // Source files has a 13-line header. Remove it first.
                List<String> sourceLines = FileUtils.readLines(sourceFile);
                for (int i = 0; i < 13; i++) {
                    sourceLines.remove(0);
                }

                // Also remove the 5-line footer
                for (int i = 0; i < 5; i++) {
                    sourceLines.remove(sourceLines.size() - 1);
                }

                // Besides that, lines may end with a "<" character. Remove it, too.
                for (int i = 0; i < sourceLines.size(); i++) {
                    String line = sourceLines.get(i);

                    if (line.endsWith("<")) {
                        line = line.substring(0, line.length() - 1);
                        sourceLines.set(i, line);
                    }
                }

                String source = StringUtils.join(sourceLines, LF);
                String suspicious = FileUtils.readFileToString(suspiciousFile);

                // Get IDs
                String sourceID = sourceFile.getAbsolutePath()
                        .substring(sourceFile.getAbsolutePath().indexOf("meter") + 6);
                sourceID = sourceID.substring(0, sourceID.length() - 5);
                sourceID = sourceID.replace("annotated/", "");

                String suspiciousID = suspiciousFile.getAbsolutePath()
                        .substring(suspiciousFile.getAbsolutePath().indexOf("meter") + 6);
                suspiciousID = suspiciousID.substring(0, suspiciousID.length() - 4);
                suspiciousID = suspiciousID.replace("rawtexts/", "");

                CombinationPair pair = new CombinationPair(inputDir.getAbsolutePath());
                pair.setID1(suspiciousID);
                pair.setID2(sourceID);
                pair.setText1(suspicious);
                pair.setText2(source);

                pairs.add(pair);
            } catch (IOException e) {
                throw new ResourceInitializationException(e);
            }
        }
    }

    return pairs;
}

From source file:bard.pubchem.xml.PubChemXMLParserFactory.java

protected void populateAssayResultsFromXML(PCAssay assay, Node assayDescriptionNode) {
    List<Node> assayResultNodes = assayDescriptionNode
            .selectNodes("../../../PC-AssaySubmit_data/PC-AssayResults");
    if (assayResultNodes.size() == 0)
        return;//  ww  w .jav  a2  s  . c  o  m

    for (Node resultNode : assayResultNodes) {
        PCAssayResult result = new PCAssayResult();

        String val = resultNode.selectSingleNode("PC-AssayResults_sid").valueOf("text()");
        result.setSID(Long.parseLong(val));

        val = resultNode.selectSingleNode("PC-AssayResults_outcome").valueOf("@value");
        val = val.substring(0, 1).toUpperCase() + val.substring(1);
        result.setOutcome(val);

        val = resultNode.selectSingleNode("PC-AssayResults_rank").valueOf("text()");
        result.setRankScore(Integer.parseInt(val));

        List<Node> assayDataNodes = resultNode.selectNodes("PC-AssayResults_data/PC-AssayData");

        List<String> all = GrowthList.decorate(new ArrayList<String>(assay.getColumns().size() - 2));
        result.setAllValues(all);
        for (Node node : assayDataNodes) {
            val = node.valueOf("PC-AssayData_tid/text()");
            int index = Integer.parseInt(val) - 1;
            val = node.selectSingleNode(".//*[starts-with(name(),'PC-AssayData_value_')]").getText();
            all.set(index, val);
        }
        assay.getResults().add(result);
    }

}

From source file:com.rr.missouri.ui.reports.reportController.java

@RequestMapping(value = "/getCriteriaList.do", method = RequestMethod.POST)
public @ResponseBody ModelAndView getCriteriaList(HttpSession session,
        @RequestParam(value = "startDate", required = true) String startDate,
        @RequestParam(value = "endDate", required = true) String endDate,
        @RequestParam(value = "entity3Ids", required = true) List<Integer> entity3Ids,
        @RequestParam(value = "reportIds", required = true) List<Integer> reportIds) throws Exception {
    List<programOrgHierarchy> orgHierarchyList = hierarchymanager.getProgramOrgHierarchy(programId);

    //need to rearrange date 

    SimpleDateFormat dateformat = new SimpleDateFormat("MM/dd/yyyy");
    Date sd = dateformat.parse(startDate);
    Date ed = dateformat.parse(endDate);

    //set up report request
    reportRequest rr = new reportRequest();
    rr.setProgramId(programId);/*from   www . j  av  a 2  s  . c  o m*/
    rr.setProgramHeirarchyId(orgHierarchyList.get(orgHierarchyList.size() - 1).getId());
    rr.setStartDateTime(sd);
    rr.setEndDateTime(ed);
    rr.setEntity3Ids(entity3Ids);
    rr.setReportIds(reportIds);

    reportCriteriaField rcf = reportmanager.getreportCriteriaFieldByOrder(programId, reportIds.get(0), 1);

    //if it contains null, we switch out to not provided
    List<reportChoices> criteriaList = reportmanager.getCriteriaListWithCW(rcf, rr);
    if (criteriaList.size() > 0) {
        //we check for null and replace
        if (criteriaList.get(0).getDisplayVal() == null) {
            reportChoices rc = new reportChoices();
            rc.setDisplayVal("Not Provided");
            rc.setInsertVal("^^^^^");
            criteriaList.set(0, rc);
        }
    }

    ModelAndView mav = new ModelAndView();
    mav.setViewName("/reports/criteriaDiv");
    mav.addObject("criteriaList", criteriaList);
    mav.addObject("reportCriteriaField", rcf);

    return mav;
}

From source file:com.indeed.imhotep.sql.IQLTranslator.java

/**
 * Handles converting queries of the form GROUP BY diff(field, filter1, filter2, limit) SELECT metric
 * to queries like: GROUP BY field[top limit by abs(filter1*metric-filter2*metric)] select abs(filter1*metric-filter2*metric), filter1*metric, filter2*metric.
 * This properly handles the case where filtered and grouped by field has multiple terms per doc (e.g. grp, rcv).
 * Modifies the passed in lists.//  w  w w.  j  a  v  a  2  s  .  c om
 */
private static void handleDiffGrouping(List<Grouping> groupings, List<Stat> stats) {
    for (int i = 0; i < groupings.size(); i++) {
        final Grouping grouping = groupings.get(i);
        if (!(grouping instanceof DiffGrouping)) {
            continue;
        }
        final Stat selectStat = stats.get(0);

        DiffGrouping diff = (DiffGrouping) grouping;
        Stat filter1 = diff.getFilter1();
        Stat filter2 = diff.getFilter2();

        Stat stat1 = mult(filter1, selectStat);
        Stat stat2 = mult(filter2, selectStat);

        Stat diffStat = abs(sub(stat1, stat2));
        stats.set(0, diffStat);
        // TODO: make client understand
        if (stats.size() > 1) {
            stats.set(1, stat1);
        } else {
            stats.add(stat1);
        }
        if (stats.size() > 2) {
            stats.set(2, stat2);
        } else {
            stats.add(stat2);
        }
        groupings.set(i, new FieldGrouping(diff.getField(), diff.getTopK(), diffStat, false));
    }
}

From source file:com.rr.wabshs.ui.reports.reportController.java

@RequestMapping(value = "/getCriteriaList.do", method = RequestMethod.POST)
public @ResponseBody ModelAndView getCriteriaList(HttpSession session,
        @RequestParam(value = "startDate", required = true) String startDate,
        @RequestParam(value = "endDate", required = true) String endDate,
        @RequestParam(value = "entity3Ids", required = true) List<Integer> entity3Ids,
        @RequestParam(value = "reportIds", required = true) List<Integer> reportIds) throws Exception {
    List<programOrgHierarchy> orgHierarchyList = hierarchymanager.getProgramOrgHierarchy(programId);

    //need to rearrange date 

    SimpleDateFormat dateformat = new SimpleDateFormat("MM/dd/yyyy");
    Date sd = dateformat.parse(startDate);
    Date ed = dateformat.parse(endDate);

    //set up report request
    reportRequest rr = new reportRequest();
    rr.setProgramId(programId);//from w  w  w . ja  va 2 s  . co m
    rr.setProgramHeirarchyId(orgHierarchyList.get(orgHierarchyList.size() - 1).getId());
    rr.setStartDateTime(sd);
    rr.setEndDateTime(ed);
    rr.setEntity3Ids(entity3Ids);
    rr.setReportIds(reportIds);

    reportCriteriaField rcf = reportmanager.getreportCriteriaFieldByOrder(programId, reportIds.get(0), 1);

    //if it contains null, we switch out to not provided
    List<reportChoices> criteriaList = reportmanager.getCriteriaListWithCW(rcf, rr, entity3Ids);
    if (criteriaList.size() > 0) {
        //we check for null and replace
        if (criteriaList.get(0).getDisplayVal() == null) {
            reportChoices rc = new reportChoices();
            rc.setDisplayVal("Not Provided");
            rc.setInsertVal("^^^^^");
            criteriaList.set(0, rc);
        }
    }

    ModelAndView mav = new ModelAndView();
    mav.setViewName("/reports/criteriaDiv");
    mav.addObject("criteriaList", criteriaList);
    mav.addObject("reportCriteriaField", rcf);

    return mav;
}