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

com.netflix.gradle.plugins.utils.WrapUtil.groovy Maven / Gradle / Ivy

There is a newer version: 11.10.0
Show newest version
package com.netflix.gradle.plugins.utils

import org.gradle.api.DomainObjectSet
import org.gradle.api.internal.CollectionCallbackActionDecorator
import org.gradle.api.internal.DefaultDomainObjectSet

/**
 * copied from org.gradle.util.WrapUtil
 * WrapUtil.java
 */
class WrapUtil {
    /**
     * Wraps the given items in a mutable unordered set.
     */
    @SafeVarargs
    @SuppressWarnings("varargs")
    static  Set toSet(T... items) {
        Set coll = new HashSet()
        Collections.addAll(coll, items)
        return coll
    }

    /**
     * Wraps the given items in a mutable domain object set.
     */
    @SafeVarargs
    @SuppressWarnings("varargs")
    static  DomainObjectSet toDomainObjectSet(Class type, T... items) {
        DefaultDomainObjectSet set = new DefaultDomainObjectSet(type, CollectionCallbackActionDecorator.NOOP)
        set.addAll(Arrays.asList(items))
        return set
    }

    /**
     * Wraps the given items in a mutable ordered set.
     */
    @SafeVarargs
    @SuppressWarnings("varargs")
    static  Set toLinkedSet(T... items) {
        Set coll = new LinkedHashSet()
        Collections.addAll(coll, items)
        return coll
    }

    /**
     * Wraps the given items in a mutable sorted set.
     */
    @SafeVarargs
    @SuppressWarnings("varargs")
    static  SortedSet toSortedSet(T... items) {
        SortedSet coll = new TreeSet()
        Collections.addAll(coll, items)
        return coll
    }

    /**
     * Wraps the given items in a mutable sorted set using the given comparator.
     */
    @SafeVarargs
    @SuppressWarnings("varargs")
    static  SortedSet toSortedSet(Comparator comp, T... items) {
        SortedSet coll = new TreeSet(comp)
        Collections.addAll(coll, items)
        return coll
    }

    /**
     * Wraps the given items in a mutable list.
     */
    @SafeVarargs
    @SuppressWarnings("varargs")
    static  List toList(T... items) {
        ArrayList coll = new ArrayList()
        Collections.addAll(coll, items)
        return coll
    }

    /**
     * Wraps the given items in a mutable list.
     */
    static  List toList(Iterable items) {
        ArrayList coll = new ArrayList()
        for (T item : items) {
            coll.add(item)
        }
        return coll
    }

    /**
     * Wraps the given key and value in a mutable unordered map.
     */
    static  Map toMap(K key, V value) {
        Map map = new HashMap()
        map.put(key, value)
        return map
    }

    @SafeVarargs
    @SuppressWarnings("varargs")
    static  T[] toArray(T... items) {
        return items
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy