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

com.arch.util.CollectionUtils Maven / Gradle / Ivy

There is a newer version: 18.12.0
Show newest version
package com.arch.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public final class CollectionUtils {

    private CollectionUtils() {
    }

    public static  List transform(final Class type,
                                        final Collection collection) {
        final List list = new ArrayList<>();
        for (Object value : collection) {
            list.add(type.cast(value));
        }
        return list;
    }

    public static , I> T transform(
            final T instance, final Class objectType,
            final Collection collection) {
        for (Object value : collection) {
            instance.add(objectType.cast(value));
        }
        return instance;
    }

    public static  T[] addItemArray(T[] arrayObj, T item)  {
        int newSize = arrayObj.length + 1;
        T[] newItens = Arrays.copyOf(arrayObj, newSize);
        newItens[newSize - 1] = item;
        return newItens;
    }

    public static boolean isNullOrEmpty(Collection collection) {
        return collection == null || collection.isEmpty();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy