Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (c) 2016.
 * This file is part of OFlib.
 *
 * OFlib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * OFlib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OFlib.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.*;

public class Main {
    /**
     * Returns a slice of a collection, up to maxLen in size
     *
     * @param c      the collection to cut
     * @param maxLen the length of the slice
     * @return a slice of {@code c} {@code maxLen} in size, if {@code maxLen} is less than {@code c.size()}, otherwise, return {@code c}
     */
    public static <E> Collection<E> cutMaxLen(Collection<E> c, int maxLen) {
        if (maxLen < c.size()) {
            return new ArrayList<>(c).subList(0, maxLen);
        }
        return c;
    }
}