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

com.ca.apim.gateway.cagatewayconfig.ProjectDependencyUtils Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2018 CA. All rights reserved.
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

package com.ca.apim.gateway.cagatewayconfig;

import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.function.Supplier;

import static com.ca.apim.gateway.cagatewayconfig.util.file.DocumentFileUtils.BUNDLE_EXTENSION;
import static java.util.stream.Collectors.toCollection;

/**
 * Utility methods for project dependencies handling.
 */
public class ProjectDependencyUtils {

    private static final String AAR = ".aar";
    private static final String JAR = ".jar";

    private ProjectDependencyUtils() { }

    /**
     * Filter only bundle files.
     *
     * @param files the full collection of files
     * @return bundle files
     */
    @SuppressWarnings("squid:S1319") // we need linkedlist here explicitly
    public static LinkedList filterBundleFiles(Collection files) {
        return filter(files, BUNDLE_EXTENSION, LinkedList::new);
    }

    /**
     * Filter only modular assertion (AAR) files.
     *
     * @param files the full collection of files
     * @return bundle files
     */
    public static Set filterModularAssertionFiles(Collection files) {
        return filter(files, AAR, LinkedHashSet::new);
    }

    /**
     * Filter only jar files.
     *
     * @param files the full collection of files
     * @return bundle files
     */
    public static Set filterJarFiles(Collection files) {
        return filter(files, JAR, LinkedHashSet::new);
    }

    @NotNull
    private static > C filter(Collection files, String filter, Supplier collectionFactory) {
        return files.stream().filter(f -> f.getName().endsWith(filter)).collect(toCollection(collectionFactory));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy