Example usage for java.util List subList

List of usage examples for java.util List subList

Introduction

In this page you can find the example usage for java.util List subList.

Prototype

List<E> subList(int fromIndex, int toIndex);

Source Link

Document

Returns a view of the portion of this list between the specified fromIndex , inclusive, and toIndex , exclusive.

Usage

From source file:com.fengduo.bee.commons.core.lang.CollectionUtils.java

public static <T extends Object> T mergeList(List<T> list, List<String> ignore) {
    if (list == null || list.isEmpty()) {
        return null;
    }/*from   www.  j  a  va2s  .  c  om*/
    if (list.size() == 1) {
        return list.get(0);
    }
    if (list.size() == 2) {
        try {
            merge(list.get(0), list.get(1), ignore);
            return list.get(0);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(), e);
        }
    }
    try {
        merge(list.get(0), mergeList(list.subList(1, list.size()), ignore), ignore);
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.getMessage(), e);
    }
    return list.get(0);
}

From source file:dap4.cdm.DapNetcdfFile.java

/**
 * Primary read entry point.//  www .  j av a  2  s  . co m
 * This is the primary implementor of Variable.read.
 *
 * @param cdmvar  A top-level variable
 * @param section the section of databuffer to read.
 *                There must be a Range for each Dimension in the variable,
 *                in order. Note: no nulls allowed.
 * @return An Array object for accessing the databuffer
 * @throws IOException           if read error
 * @throws InvalidRangeException if invalid section
 */

@Override
protected Array readData(Variable cdmvar, Section section) throws IOException, InvalidRangeException {
    // The section is applied wrt to the DataDMR, so it
    // takes into account any constraint used in forming the dataDMR.
    // We use the Section to produce a view of the underlying variable array.

    assert this.dsp != null;
    Array result = cdmvar.read();
    if (section != null) {
        if (cdmvar.getRank() != section.getRank())
            throw new InvalidRangeException(String.format("Section rank != %s rank", cdmvar.getFullName()));
        List<Range> ranges = section.getRanges();
        // Case out the possibilities
        if (CDMUtil.hasVLEN(ranges)) {
            ranges = ranges.subList(0, ranges.size() - 1);// may produce empty list
        }
        if (ranges.size() > 0 && !CDMUtil.isWhole(ranges, cdmvar))
            result = result.sectionNoReduce(ranges);
    }
    return result;
}

From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.GenItunesFile.java

private void genTracksForMedia() throws IOException {
    List<Media> medias = db.getMedia();
    List<Media> smedias = medias.subList(3, 100);
    List<Title> titles = new ArrayList<Title>();
    for (Media media : smedias) {
        List<Title> tl = media.getTitleList();
        titles.addAll(tl);/*from w ww  .  jav  a 2s.  c o  m*/
    }
    genTracks(titles, smedias);
    genPlayList(smedias);
}

From source file:com.yahoo.sql4d.insert.RTInsertMeta.java

private JSONObject getFireHose() {
    Map<String, Object> finalMap = new LinkedHashMap<>();
    finalMap.put("type", "local");
    finalMap.put("baseDir", tmpFolder);
    String fileName = UUID.randomUUID().toString() + ".csv";
    finalMap.put("filter", fileName);
    if (values.isEmpty()) {
        throw new IllegalStateException("No values to insert !!");
    }//from w  w w. j a va2 s.c  o m
    Map<String, Object> parserMap = new LinkedHashMap<>();
    try {
        File file = new File(tmpFolder + File.separator + fileName);
        FileUtils.write(file, Joiner.on(",").join(values));
        System.out.println("Written to " + file);
        Object timestamp = values.get(0);
        String timestampFormat = TimeUtils.detectFormat(timestamp.toString());
        Map<String, String> tsSpec = ImmutableMap.<String, String>builder().put("column", "timestamp")
                .put("format", (timestampFormat != null) ? timestampFormat : "auto").build();
        parserMap.put("timestampSpec", tsSpec);

        List<String> dims = new ArrayList<>(fetchDimensions.keySet());
        List<String> metrics = getMetrics(aggregations);

        Map<String, Object> data = ImmutableMap.<String, Object>builder().put("format", "csv")
                .put("dimensions", dims.subList(1, dims.size()))
                .put("columns", Lists.newArrayList(concat(dims, metrics))).build();
        parserMap.put("data", data);
    } catch (IOException ex) {
        Logger.getLogger(RTInsertMeta.class.getName()).log(Level.SEVERE, null, ex);
    }
    finalMap.put("parser", parserMap);
    return new JSONObject(finalMap);
}

From source file:flex.messaging.io.ASRecordSet.java

/**
 * @param columnNames/*from  w  w w .  j ava2 s.  co m*/
 * @param rows ArrayList containing a ArrayList for each row
 */
public void populate(String[] columnNames, List<List<Object>> rows) {
    this.rows = rows;

    List<List<Object>> initialData = rows.subList(0,
            (initialRowCount > rows.size() ? rows.size() : initialRowCount)); // NOTE: sublist semantics are [fromIndex, toIndex]
    setInitialData(initialData);
    setTotalCount(rows.size());
    setColumnNames(columnNames);
}

From source file:com.graphaware.neo4j.webexpo.database.DataGenerator.java

/**
 * Find a number of random attendees.//  w  w  w.  j  av  a2  s . co m
 *
 * @param number of attendees to find.
 * @return the given number of random attendees.
 */
public List<String> findRandomAttendees(int number) {
    List<String> allAttendees = findAllAttendees();
    Collections.shuffle(allAttendees);
    return allAttendees.subList(0, number);
}

From source file:com.netflix.simianarmy.basic.chaos.BasicChaosInstanceSelector.java

private Collection<String> selectNInstances(Collection<String> instances, int n, String selected) {
    logger().info("Randomly selecting {} from {} instances, excluding {}",
            new Object[] { n, instances.size(), selected });
    List<String> copy = Lists.newArrayList();
    for (String instance : instances) {
        if (!instance.equals(selected)) {
            copy.add(instance);/*  w  w w.  ja  va2s  .c om*/
        }
    }
    if (n >= copy.size()) {
        return copy;
    }
    Collections.shuffle(copy);
    return copy.subList(0, n);
}

From source file:com.ssbusy.controller.account.OrderHistoryController.java

private Map<String, Object> wrapOrder(Order o, boolean listAll) {
    Map<String, Object> ret = new HashMap<String, Object>();
    ret.put("id", o.getId());
    ret.put("timestamp", o.getSubmitDate().getTime());
    ret.put("itemCount", o.getItemCount());
    ret.put("orderNum", o.getOrderNumber());
    ret.put("amount", o.getTotal());
    ret.put("status", o.getStatus().getType());
    ret.put("statusName", toString(o.getStatus()));
    List<OrderItem> items = o.getOrderItems();
    ret.put("oiCount", items.size());
    if (!listAll && items.size() > 2)
        items = items.subList(0, 2);
    List<Map<String, Object>> its = new ArrayList<Map<String, Object>>(items.size());
    ret.put("items", its);
    for (OrderItem oi : items) {
        Map<String, Object> m = new HashMap<String, Object>();
        its.add(m);/*from w  ww  . j  a  v  a 2 s. co  m*/
        m.put("quantity", oi.getQuantity());
        m.put("price", oi.getPriceBeforeAdjustments(true));
        Product p = null;
        if (oi instanceof SkuAccessor) {
            Sku sku = ((SkuAccessor) oi).getSku();
            if (sku != null) {
                p = sku.getProduct();
                m.put("id", p.getId());
                m.put("name", p.getName());
                m.put("url", p.getUrl());
                if (listAll)
                    m.put("media", p.getMedia().get("primary"));
            }
        } // TODO else
    }
    return ret;
}

From source file:net.cloudkit.enterprises.infrastructure.freemarker.method.MessageMethod.java

@SuppressWarnings("rawtypes")
@Override//from w  ww.j a  v  a 2 s.  c  o m
public Object exec(List arguments) {
    if ((arguments != null) && (!arguments.isEmpty()) && (arguments.get(0) != null)
            && (StringUtils.isNotEmpty(arguments.get(0).toString()))) {
        String str1 = null;
        String str2 = arguments.get(0).toString();
        if (arguments.size() > 1) {
            Object[] arrayOfObject = arguments.subList(1, arguments.size()).toArray();
            str1 = SpringHelper.getMessage(str2, arrayOfObject);
        } else {
            str1 = SpringHelper.getMessage(str2, new Object[0]);
        }
        return new SimpleScalar(str1);
    }
    return null;
}

From source file:info.mikaelsvensson.devtools.analysis.db2eventlog.Db2EventLogReportGenerator.java

@Override
public void generateReport(File outputFile, ReportPrinter reportPrinter) throws IOException {
    PrintStream stream = new PrintStream(outputFile);

    printHeader(stream,/*from  w  ww  . j  av a2  s . c o m*/
            "Report for " + _report.getStartTime().toString() + " to " + _report.getStopTime().toString() + " ("
                    + (_report.getStopTime().getTime() - _report.getStartTime().getTime()) / (1000 * 60)
                    + " minutes)");

    List<QueryStatistics> values = new ArrayList<QueryStatistics>(_report.getRecords().values());

    printHeader(stream, "Queries Sorted by Total Execution Time (only top 10 queries shown)");
    sortQueryDataByTime(values);
    printQueryData(values.subList(0, Math.min(10, values.size())), stream);

    printHeader(stream, "Queries Sorted by Total Number of Calls (all queries shown)");
    sortQueryDataBySamples(values);
    printQueryData(values, stream);

    stream.close();
}