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.xpn.xwiki.plugin.tag.TagPlugin.java

/**
 * Rename a tag.// w w  w .  ja  v a2 s.c o m
 * 
 * @param tag tag to rename.
 * @param newTag new tag.
 * @param context XWiki context.
 * @return the {@link TagOperationResult result} of the operation
 * @throws XWikiException if document save fails for some reason (Insufficient rights, DB access, etc).
 */
protected TagOperationResult renameTag(String tag, String newTag, XWikiContext context) throws XWikiException {
    List<String> docNamesToProcess = getDocumentsWithTag(tag, context);
    if (StringUtils.equals(tag, newTag) || docNamesToProcess.size() == 0 || StringUtils.isBlank(newTag)) {
        return TagOperationResult.NO_EFFECT;
    }
    List<String> commentArgs = new ArrayList<String>();
    commentArgs.add(tag);
    commentArgs.add(newTag);
    String comment = context.getMessageTool().get("plugin.tag.editcomment.renamed", commentArgs);

    for (String docName : docNamesToProcess) {
        XWikiDocument doc = context.getWiki().getDocument(docName, context);
        List<String> tags = getTagsFromDocument(doc);
        for (int i = 0; i < tags.size(); i++) {
            if (tags.get(i).equalsIgnoreCase(tag)) {
                tags.set(i, newTag);
            }
        }
        setDocumentTags(doc, tags, context);

        // Since we're changing the document we need to set the new author
        doc.setAuthorReference(context.getUserReference());

        context.getWiki().saveDocument(doc, comment, true, context);
    }

    return TagOperationResult.OK;
}

From source file:com.flexive.shared.structure.FxPropertyAssignmentEdit.java

/**
 * Set the alias of this property assignment.
 * Property assignments may define an alias to allow multiple use of the same property but
 * using a different name. The alias is the rightmost part of the XPath used to address an assignment.
 * Will affect the XPath as well.//from w w  w . jav  a2  s. c o m
 *
 * @param alias the alias of this assignment
 * @return this
 * @throws FxInvalidParameterException on errors
 */
public FxPropertyAssignmentEdit setAlias(String alias) throws FxInvalidParameterException {
    if (StringUtils.isEmpty(alias))
        throw new FxInvalidParameterException("ALIAS", "ex.structure.assignment.noAlias");
    //only react to alias changes
    if (!this.alias.trim().toUpperCase().equals(alias.trim().toUpperCase())) {
        this.alias = alias.trim().toUpperCase();
        List<XPathElement> xpe = XPathElement.splitNew(this.XPath);
        xpe.set(xpe.size() - 1, new XPathElement(this.alias, 1, true));
        this.XPath = XPathElement.toXPathNoMult(xpe);
    }
    return this;
}

From source file:uk.ac.susx.tag.method51.webapp.handler.CodingInstanceHandler.java

private void list(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException {

    File f = new File(modelsFolder);
    List<String> names = new ArrayList<>(Arrays.asList(f.list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(Coder.SAMPLE_SUFFIX);
        }/*from   w  w  w  .  j  a v  a 2s .  co m*/
    })));

    for (int i = 0; i < names.size(); ++i) {
        names.set(i, names.get(i).replace(Coder.SAMPLE_SUFFIX, ""));
    }

    Collections.sort(names);
    okHereIsYourJson("models", names, response);
}

From source file:io.pivotal.demo.smartgrid.frontend.timeseries.AggregateCounterTimeSeriesRepository.java

private TimeSeriesCollection aggreagteGridTotalTimeSeries(Map<String, TimeSeriesCollection> result) {
    TimeSeriesCollection totalGridTimeSeriesCollection = new TimeSeriesCollection("grid_h-1");

    for (Map.Entry<String, TimeSeriesCollection> entry : result.entrySet()) {

        TimeSeriesCollection timeSeriesCollection = entry.getValue();

        if (totalGridTimeSeriesCollection.getTimeSeries().isEmpty()) {

            for (TimeSeries timeSeries : timeSeriesCollection.getTimeSeries()) {

                TimeSeries newTimeSeries = new TimeSeries("grid" + timeSeries.getName(),
                        new ArrayList<DataPoint>(timeSeries.getData()));
                totalGridTimeSeriesCollection.getTimeSeries().add(newTimeSeries);
            }//from www. j  a va 2  s.  c o  m

            continue;
        }

        List<TimeSeries> timeSeriesList = timeSeriesCollection.getTimeSeries();
        for (int timeSeriesIndex = 0, timeSeriesCount = timeSeriesList
                .size(); timeSeriesIndex < timeSeriesCount; timeSeriesIndex++) {

            TimeSeries timeSeries = timeSeriesList.get(timeSeriesIndex);
            TimeSeries gridTimeSeries = totalGridTimeSeriesCollection.getTimeSeries().get(timeSeriesIndex);

            List<DataPoint> gridDataPoints = gridTimeSeries.getData();
            List<DataPoint> currentDataPoints = timeSeries.getData();

            for (int dataPointIndex = 0, dataPointCount = currentDataPoints
                    .size(); dataPointIndex < dataPointCount; dataPointIndex++) {

                DataPoint currentDataPoint = currentDataPoints.get(dataPointIndex);
                DataPoint gridDataPoint = gridDataPoints.get(dataPointIndex);

                gridDataPoints.set(dataPointIndex, new DataPoint(gridDataPoint.getTs(),
                        gridDataPoint.getValue() + currentDataPoint.getValue()));
            }
        }
    }
    return totalGridTimeSeriesCollection;
}

From source file:CSVTools.CsvToolsApi.java

/**
 * Remove all spaces from header names by removing leading spaces and
 * replace other spaces with underscore//  w  w  w .  j a  va  2  s.  c  o m
 *
 * @param headers
 * @return
 */
private List<String> replaceSpaceWithDash(List<String> headers) {
    List<String> headersWithNoSpaces = headers;

    for (int i = 0; i < headers.size(); i++) {
        headersWithNoSpaces.set(i, headers.get(i).replaceAll("^\\s+", "").replace(" ", "_"));
        headersWithNoSpaces.set(i, headers.get(i).replace("(", "_").replace(")", "_"));
        headersWithNoSpaces.set(i, headers.get(i).replace("/", "_").replace("\\", "_"));
    }
    return headersWithNoSpaces;

}

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

/**
 * a method that removes infrequent words from a collection of documents
 * @param wordsToSetOfDocs words and the documents they appear in
 * @param docs list of docs/*from  w  ww.j  a va 2 s  . c  om*/
 * @return list of docs without the infrequent words
 */
private List<String> removeInfrequentWords(Map<String, HashSet<Integer>> wordsToSetOfDocs, List<String> docs) {

    int downThreshold = 1; // remove words that appear in only one document
    //(int) (0.005*docs.size()); //remove words that appear in less than 0.5% of documents
    for (String word : wordsToSetOfDocs.keySet()) {
        if (wordsToSetOfDocs.get(word).size() == downThreshold) {
            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:it.geosolutions.unredd.stats.impl.StatsRunner.java

protected void outputStats(Map<MultiKey, List<Result>> results) {

    boolean rangeAlreadyLogged = false;

    for (MultiKey classes : results.keySet()) {

        StringBuilder sb = new StringBuilder();

        //= append all classes
        for (Object o : classes.getKeys()) {
            //                LOGGER.info("Adding class " + o);
            sb.append(o).append(cfg.getOutput().getSeparator());
        }// ww  w.ja  v  a 2  s  . co m

        //= append stats in the requested order
        List<Result> resultList = results.get(classes);
        int statsnum = statsIndexes.size() + (countIndex != null ? 1 : 0);
        //            LOGGER.info(statsnum + " stats requested");
        // prefill outval
        List<Double> outval = new ArrayList<Double>(statsnum);
        for (int i = 0; i < statsnum; i++) {
            outval.add(Double.NaN);
        }

        // fill count stat
        if (countIndex != null) { // COUNT is not a real stat: set it by hand
            Long l = resultList.get(0).getNumAccepted();
            outval.set(countIndex, l.doubleValue());
        }

        // fill computed stats
        for (Result result : resultList) {
            //                LOGGER.info(result);
            Integer idx = statsIndexes.get(result.getStatistic());
            if (idx == null) {
                if (LOGGER.isDebugEnabled()) {
                    if (result.getStatistic() != Statistic.RANGE || !rangeAlreadyLogged) { // display range warning only once
                        LOGGER.debug("Encountered stat not requested (" + result.getStatistic().name() + "): "
                                + result);
                    }
                    rangeAlreadyLogged = result.getStatistic() == Statistic.RANGE;
                } // log
                continue;
            }
            //                 else
            //                    LOGGER.info("Adding " + result.getStatistic());
            outval.set(idx, result.getValue());
        }

        //= put stats in output line
        for (Iterator<Double> it = outval.iterator(); it.hasNext();) {
            Double val = it.next();
            if (!Double.isNaN(val))
                sb.append(val);
            else
                sb.append(cfg.getOutput().getNanValue());

            if (it.hasNext())
                sb.append(cfg.getOutput().getSeparator());
        }

        output(sb);
    }

    closeOutputFile();
    CSVConverter.convertFromCSV(cfg);
}

From source file:com.reactivetechnologies.platform.rest.MethodInvocationHandler.java

/**
 * From params/*from  w  w  w  .jav  a  2 s .c  o m*/
 * @param args
 * @param request
 */
private void extractArgumentsFromParams(List<Object> args, HttpRequest request) {
    //set value from path params
    for (Entry<Integer, String> entry : method.getpParams().entrySet()) {
        args.add(entry.getKey(), Rest.param(request, entry.getValue()));
    }
    //set value from query params
    for (Entry<Integer, String> entry : method.getqParams().entrySet()) {
        if (args.size() > entry.getKey() && args.get(entry.getKey()) != null) {
            //replaces any matching path param!
            args.set(entry.getKey(), request.queryParam(entry.getValue()));

        } else
            args.add(entry.getKey(), request.queryParam(entry.getValue()));
    }
}

From source file:mase.mason.generic.ASAgentEvaluator.java

@Override
protected void postSimulation(MasonSimState sim) {
    super.postSimulation(null);
    List<double[]> concats = new ArrayList<>(states.get(0).size());
    for (int ag = 0; ag < states.get(0).size(); ag++) {
        concats.add(new double[] {});
    }/*from w  w  w.  java 2  s  .  co m*/

    int windowStep = states.size() / windows;
    for (int w = 0; w < windows; w++) {
        int from = w * windowStep;
        int to = (w == windows - 1) ? states.size() : from + windowStep;
        List<double[]> avgs = averageStates(from, to);

        for (int ag = 0; ag < concats.size(); ag++) {
            double[] v1 = concats.get(ag);
            double[] v2 = avgs.get(ag);
            concats.set(ag, ArrayUtils.addAll(v1, v2));
        }
    }

    Collection<EvaluationResult> resList = new ArrayList<>();
    for (double[] c : concats) {
        VectorBehaviourResult vbr = new VectorBehaviourResult(c);
        vbr.setDistance(VectorBehaviourResult.EUCLIDEAN);
        vbr.setLocationEstimator(average);
        resList.add(vbr);
    }
    this.res = new CompoundEvaluationResult(resList);
}

From source file:cn.vlabs.umt.ui.rest.RestUserServiceV7Impl.java

@RestMethod("createUsers")
public List<UMTUser> createUsers(List<UMTUser> users) throws ServiceException {
    int index = 0;
    for (UMTUser umtUser : users) {
        try {/*from   ww w . j  a  va  2  s .  co m*/
            String orgPassword = umtUser.getPassword();
            User user = toUser(umtUser);
            service.create(user, LoginNameInfo.STATUS_ACTIVE);
            umtUser = toUMTUser(user);
            umtUser.setPassword(orgPassword);
            users.set(index++, umtUser);
        } catch (InvalidUserNameException e) {
            throw new ServiceException(ServiceException.ERROR_INTERNAL_ERROR,
                    "????:" + umtUser.getUmtId());
        }
    }
    return users;
}