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:ch.unibas.fittingwizard.application.tools.LPunParser.java

private List<String> removeHeader(List<String> lines) {
    return lines.subList(3, lines.size());
}

From source file:info.magnolia.jcr.util.NodeUtil.java

/**
 * Gets the siblings after this node.//from   w ww  .  ja  v a2  s.com
 * @param node node from which will be siblings retrieved
 * @return list of siblings after the given Node (the given node is excluded)
 */
public static Iterable<Node> getSiblingsAfter(Node node) throws RepositoryException {
    int fromIndex = 0;
    Node parent = node.getParent();
    List<Node> allSiblings = NodeUtil.asList(NodeUtil.getNodes(parent));

    for (Node sibling : allSiblings) {
        if (NodeUtil.isSame(node, sibling)) {
            fromIndex++;
            break;
        }
        fromIndex++;
    }
    return allSiblings.subList(fromIndex, allSiblings.size());
}

From source file:fm.last.lastfmlive.ArtistTagger.java

@Scheduled(fixedDelay = 30000)
public void tagArtists() {
    List<Artist> artists = new ArrayList<Artist>(theBrain.getArtistList(50));
    for (Artist a : artists) {
        if (a.getTags() != null) {
            continue;
        }/*from w w w . j a  va2 s .  co m*/
        List<String> tags = lastfmFacade.getTopTags(a.getName());
        tags = tags.subList(0, tags.size() > 5 ? 5 : tags.size());
        a.setTags(tags);
        theBrain.addTags(tags);
    }
}

From source file:org.avidj.zuul.core.DefaultEmbeddedLockManager.java

private static boolean noLoiteringLockNodes(LockTreeNode root, List<String> path) {
    LockTreeNode current = root;// w w w . jav  a  2s  . c  om
    for (int i = 0, n = path.size(); i < n; i++) {
        String step = path.get(i);
        current = current.children.get(step);
        if (current == null) {
            return true;
        } else {
            synchronized (current) {
                if (!current.hasExclusiveLock() && current.getSharedLocks().isEmpty()
                        && current.children.isEmpty()) {
                    LOG.error("No locks and no children in node: {}", Strings.join(path.subList(0, i + 1)));
                    return false;
                }
            }
        }
    }
    return true;
}

From source file:net.sourceforge.vulcan.spring.jdbc.BuildHistoryMetricsQuery.java

static void splitMetricsByBuildId(List<JdbcBuildOutcomeDto> builds, List<JdbcMetricDto> metrics) {
    final Map<Integer, JdbcBuildOutcomeDto> buildsById = new HashMap<Integer, JdbcBuildOutcomeDto>();

    for (JdbcBuildOutcomeDto build : builds) {
        buildsById.put(build.getPrimaryKey(), build);
    }/*from   w w w.ja  va  2 s . c o  m*/

    final int size = metrics.size();

    final Integer buildId = metrics.get(0).getBuildId();
    if (size == 1) {
        if (buildsById.containsKey(buildId)) {
            buildsById.get(buildId).setMetrics(Collections.<MetricDto>unmodifiableList(metrics));
        } else {
            LOG.error("Got metrics for missing build " + buildId);
        }
        return;
    }

    Integer currentBuildId = buildId;
    int i = 0;
    int j = 1;

    while (j < size) {
        while (j < size && metrics.get(j).getBuildId().equals(currentBuildId)) {
            j++;
        }

        final List<MetricDto> metricsForBuild = Collections.<MetricDto>unmodifiableList(metrics.subList(i, j));

        if (buildsById.containsKey(currentBuildId)) {
            buildsById.get(currentBuildId).setMetrics(metricsForBuild);
        } else {
            LOG.error("Got metrics for missing build " + currentBuildId);
        }

        i = j;

        if (j < size) {
            currentBuildId = metrics.get(j).getBuildId();
        }
    }
}

From source file:fm.last.lastfmlive.TheBrain.java

public List<String> getTags(int maxNumber) {
    List<String> topList = tagChart.sortedView();
    topList = topList.subList(0, topList.size() < maxNumber ? topList.size() : maxNumber);
    return topList;
}

From source file:fm.last.lastfmlive.TheBrain.java

public List<Track> getTrackList(int maxNumber) {
    List<Track> topList = trackChart.sortedView();
    topList = topList.subList(0, topList.size() < maxNumber ? topList.size() : maxNumber);
    return topList;
}

From source file:com.act.lcms.db.analysis.WaveformAnalysis.java

/**
 * This function compresses a given list of time series data based on a period compression value.
 * @param intensityAndTime A list of intensity/time data
 * @param compressionMagnitude This value is the magnitude by which the data is compressed in the time dimension.
 * @return A pair of a list of intensity/time data that is compressed and a mapping from time to max peak intensity in
 * that window./*  w ww. j a v  a  2  s.co m*/
 */
public static Pair<List<XZ>, Map<Double, Double>> compressIntensityAndTimeGraphsAndFindMaxIntensityInEveryTimeWindow(
        List<XZ> intensityAndTime, int compressionMagnitude) {
    ArrayList<XZ> compressedResult = new ArrayList<>();
    Map<Double, Double> timeToIntensity = new HashMap<>();

    if (intensityAndTime == null) {
        System.out.println("intensity time is null");
        System.exit(1);
    }

    for (int i = 0; i < intensityAndTime.size() / compressionMagnitude; i++) {
        int startIndex = i * compressionMagnitude;
        int endIndex = startIndex + compressionMagnitude;
        List<XZ> subListSum = intensityAndTime.subList(startIndex,
                endIndex > intensityAndTime.size() ? intensityAndTime.size() : endIndex);

        Double maxIntensity = 0.0;
        for (XZ xz : subListSum) {
            maxIntensity = Math.max(maxIntensity, xz.getIntensity());
        }

        // Make sure that the size of the sublist has atleast one element in it.
        if (subListSum.size() > 0) {
            compressedResult.add(sumIntensityAndTimeList(subListSum));
            timeToIntensity.put(subListSum.get(START_INDEX).getTime(), maxIntensity);
        }
    }

    return Pair.of(compressedResult, timeToIntensity);
}

From source file:fm.last.lastfmlive.TheBrain.java

public List<Artist> getArtistList(int maxNumber) {
    List<Artist> topList = artistChart.sortedView();
    topList = topList.subList(0, topList.size() < maxNumber ? topList.size() : maxNumber);
    return topList;
}

From source file:org.openimaj.image.dataset.BingImageDataset.java

private static List<ImageDataSourceResponse> performQuery(ImageDataSourceQuery query, int number) {
    if (number <= 0)
        number = 1000;/*from   w w w  . ja  v  a  2s . c  om*/

    query.setOffset(0);
    query.setCount(50);

    final List<ImageDataSourceResponse> images = new ArrayList<ImageDataSourceResponse>();
    for (int i = 0; i < 20; i++) {
        final List<ImageDataSourceResponse> res = performSinglePageQuery(query);

        if (res == null || res.size() == 0)
            break;

        images.addAll(res);

        if (images.size() >= number)
            break;

        query.setOffset(query.getOffset() + 50);
    }

    if (images.size() <= number)
        return images;
    return images.subList(0, number);
}