Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class Main {
    public static <T extends Comparable> List range(List<T> list, Object min, Object max) {
        List<T> des = newArrayList();
        for (T o : list) {
            if ((o.compareTo(min) >= 0) && (o.compareTo(max) <= 0)) {
                des.add(o);
            }
        }
        return des;
    }

    public static <T> List range(List<T> list, Object min, Object max, Comparator<? super T> comparator) {
        List<T> des = newArrayList();
        for (T o : list) {
            if ((comparator.compare(o, (T) min) >= 0) && comparator.compare(o, (T) max) <= 0) {
                des.add(o);
            }
        }
        return des;
    }

    public static <T> List newArrayList() {
        return new ArrayList<T>();
    }

    public static <T> void add(List<? super T> source, Object o) {
        source.add((T) o);
    }
}