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

coursierapi.FetchResult Maven / Gradle / Ivy

package coursierapi;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class FetchResult implements Serializable {

    private List> artifacts;
    private List dependencies;

    private FetchResult(List> artifacts, List dependencies) {
        this.artifacts = Collections.unmodifiableList(new ArrayList<>(artifacts));
        this.dependencies = Collections.unmodifiableList(new ArrayList<>(dependencies));
    }

    public static FetchResult of(List> artifacts) {
        return new FetchResult(artifacts, Collections.emptyList());
    }

    public static FetchResult of(List> artifacts, List dependencies) {
        return new FetchResult(artifacts, dependencies);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj instanceof FetchResult) {
            FetchResult other = (FetchResult) obj;
            return this.artifacts.equals(other.artifacts) &&
                    this.dependencies.equals(other.dependencies);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return 37 * (37 * (17 + artifacts.hashCode())) + dependencies.hashCode();
    }

    @Override
    public String toString() {
        StringBuilder b = new StringBuilder("FetchResult(artifacts=[");
        boolean isFirst = true;
        for (Map.Entry entry : artifacts) {
            if (isFirst) {
                isFirst = false;
            } else {
                b.append(", ");
            }

            b.append(entry.getKey().toString());
            b.append(": ");
            b.append(entry.getValue().toString());
        }
        b.append("], dependencies=[");

        isFirst = true;
        for (Dependency dependency : dependencies) {
            if (isFirst) {
                isFirst = false;
            } else {
                b.append(", ");
            }

            b.append(dependency.toString());
        }
        b.append("])");

        return b.toString();
    }

    public List> getArtifacts() {
        return artifacts;
    }

    public List getFiles() {
        ArrayList l = new ArrayList<>();
        for (Map.Entry entry : artifacts) {
            l.add(entry.getValue());
        }
        return l;
    }

    public List getDependencies() {
        return dependencies;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy