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

io.lindstrom.mpd.support.Utils Maven / Gradle / Ivy

There is a newer version: 0.16
Show newest version
package io.lindstrom.mpd.support;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Utils {
    private static final Class UNMODIFIABLE_LIST_CLASS =
            Collections.unmodifiableList(Collections.emptyList()).getClass();

    public static  List unmodifiableList(List list) {
        if (list == null) {
            return Collections.emptyList();
        } else if (UNMODIFIABLE_LIST_CLASS.isInstance(list)) {
            return list;
        } else {
            return Collections.unmodifiableList(list);
        }
    }

    @SafeVarargs
    public static  List varargsToList(T head, T ...tail) {
        if (tail.length == 0) {
            return Collections.singletonList(head);
        } else {
            List list = new ArrayList<>();
            list.add(head);
            for (int i = 0; i < tail.length; i++) {
                list.add(tail[i]);
            }
            return list;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy