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

org.mapstruct.ap.internal.util.Collections Maven / Gradle / Ivy

There is a newer version: 1.6.3
Show newest version
/**
 *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
 *  and/or other contributors as indicated by the @authors tag. See the
 *  copyright.txt file in the distribution for a full listing of all
 *  contributors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.mapstruct.ap.internal.util;

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

/**
 * Provides utility methods around collections.
 *
 * @author Gunnar Morling
 */
public class Collections {

    private Collections() {
    }

    public static  Set asSet(T... elements) {
        Set set = new HashSet();

        for ( T element : elements ) {
            set.add( element );
        }

        return set;
    }

    public static  List newArrayList(T... elements) {
        List list = new ArrayList();

        list.addAll( Arrays.asList( elements ) );

        return list;
    }

    public static  Set asSet(Collection collection, T... elements) {
        Set set = new HashSet( collection );

        for ( T element : elements ) {
            set.add( element );
        }

        return set;
    }

    public static  Set asSet(Collection collection, Collection... elements) {
        Set set = new HashSet( collection );

        for ( Collection element : elements ) {
            set.addAll( element );
        }

        return set;
    }

    public static  T first(Collection collection) {
        return collection.iterator().next();
    }

    public static  T last(List list) {
        return list.get( list.size() - 1 );
    }

    public static  List join(List a, List b) {
        List result = new ArrayList( a.size() + b.size() );

        result.addAll( a );
        result.addAll( b );

        return result;
    }

    public static  boolean hasNonNullElements(Iterable elements) {
        if ( elements != null ) {
            for ( E e : elements ) {
                if ( e != null ) {
                    return true;
                }
            }
        }
        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy