All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.microwww.ttp.util.DataUtil Maven / Gradle / Ivy

There is a newer version: 0.0.6-release
Show newest version
package com.github.microwww.ttp.util;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public final class DataUtil {

    private DataUtil() {
    }

    public static List toList(Object o) {
        if (o instanceof List) {
            return (List) o;
        } else if (o instanceof Collection) {
            return new ArrayList<>((Collection) o);
        } else if (o.getClass().isArray()) {
            int size = Array.getLength(o);
            List list = new ArrayList<>();
            for (int i = 0; i < size; i++) {
                list.add(Array.get(o, i));
            }
            return list;
        }
        throw new UnsupportedOperationException("Result must is ARRAY / LIST / COLLECTION");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy