Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.SortedSet;

import com.google.common.collect.Sets;

public class Main {
    /**
     * Return the top elements of a sorted set.
     *
     * @param originalSet
     * @param nTopElements
     * @return
     */
    public static <T extends Comparable<T>> SortedSet<T> getTopElements(final SortedSet<T> originalSet,
            final int nTopElements) {
        final SortedSet<T> filteredElements = Sets.newTreeSet();
        int i = 0;
        for (final T element : originalSet) {
            if (i >= nTopElements) {
                break;
            }
            filteredElements.add(element);
            i++;
        }
        return filteredElements;
    }
}