Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.Serializable;
import java.util.Arrays;

import java.util.Collections;

import java.util.LinkedList;
import java.util.List;

public class Main {
    /**
     * Convert any object into a list
     * @param source
     * @return
     */
    public static List asList(Object source) {
        if (source instanceof Iterable) {
            Iterable new_name = (Iterable) source;
            return asList(new_name);
        } else {
            return asList(Arrays.asList(source));
        }
    }

    /**
     * Build a list of bean from the provided iterable
     * @param source any kind of iterable
     * @return a {@link Serializable} {@link List} containing the same element set
     */
    public static <Bean> List<Bean> asList(Iterable<Bean> source) {
        if (source instanceof List && source instanceof Serializable) {
            return (List<Bean>) source;
        } else if (source == null) {
            return Collections.emptyList();
        } else {
            List<Bean> returned = new LinkedList<Bean>();
            for (Bean b : source) {
                returned.add(b);
            }
            return returned;
        }
    }
}