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

coursierapi.ResolutionParams Maven / Gradle / Ivy

The newest version!
package coursierapi;

import java.io.Serializable;
import java.util.*;

public class ResolutionParams implements Serializable {

    private Integer maxIterations;
    private final HashMap forceVersions;
    private final HashMap forcedProperties;
    private final HashSet profiles;
    private final HashSet> exclusions;
    private boolean useSystemOsInfo;
    private boolean useSystemJdkVersion;
    private String scalaVersion;

    private ResolutionParams() {
        maxIterations = null;
        forceVersions = new HashMap<>();
        forcedProperties = new HashMap<>();
        profiles = new HashSet<>();
        exclusions = new HashSet<>();
        useSystemOsInfo = true;
        useSystemJdkVersion = true;
        scalaVersion = null;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof ResolutionParams) {
            ResolutionParams other = (ResolutionParams) obj;
            return Objects.equals(this.maxIterations, other.maxIterations) &&
                    this.forcedProperties.equals(other.forcedProperties) &&
                    this.profiles.equals(other.profiles) && this.exclusions.equals(other.exclusions) &&
                    Objects.equals(this.useSystemOsInfo, other.useSystemOsInfo) &&
                    Objects.equals(this.useSystemJdkVersion, other.useSystemJdkVersion) &&
                    Objects.equals(this.scalaVersion, other.scalaVersion);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return 37 * (37 * (37 * (37 * (37 * (37 * (37 * (17 + Objects.hashCode(maxIterations)) + forceVersions.hashCode()) + forcedProperties.hashCode()) + profiles.hashCode()) + exclusions.hashCode()) + Boolean.hashCode(useSystemOsInfo)) + Boolean.hashCode(useSystemJdkVersion)) + Objects.hashCode(scalaVersion);
    }

    @Override
    public String toString() {
        StringBuilder b = new StringBuilder("ResolutionParams(");
        boolean needSep = false;
        if (maxIterations != null) {
            b.append("maxIterations=");
            b.append(maxIterations.toString());
            needSep = true;
        }
        if (!forceVersions.isEmpty()) {
            if (needSep)
                b.append(", ");
            else
                needSep = true;

            b.append("forceVersions=[");
            boolean first = true;
            for (Map.Entry e : forceVersions.entrySet()) {
                if (first)
                    first = false;
                else
                    b.append(", ");
                b.append(e.getKey().toString());
                b.append(":");
                b.append(e.getValue());
            }
            b.append("]");
        }
        if (!forcedProperties.isEmpty()) {
            if (needSep)
                b.append(", ");
            else
                needSep = true;

            b.append("forcedProperties=[");
            boolean first = true;
            for (Map.Entry e : forcedProperties.entrySet()) {
                if (first)
                    first = false;
                else
                    b.append(", ");
                b.append(e.getKey());
                b.append("=");
                b.append(e.getValue());
            }
            b.append("]");
        }
        if (!profiles.isEmpty()) {
            if (needSep)
                b.append(", ");
            else
                needSep = true;

            b.append("profiles=[");
            boolean first = true;
            for (String profile : profiles) {
                if (first)
                    first = false;
                else
                    b.append(", ");
                b.append(profile);
            }
            b.append("]");
        }
        if (!exclusions.isEmpty()) {
            if (needSep)
                b.append(", ");
            else
                needSep = true;

            b.append("exclusions=[");
            boolean first = true;
            for (Map.Entry exclusion : exclusions) {
                if (first)
                    first = false;
                else
                    b.append(", ");
                b.append(exclusion.getKey());
                b.append(":");
                b.append(exclusion.getValue());
            }
            b.append("]");
        }

        if (needSep)
            b.append(", ");
        else
            needSep = true;

        b.append("useSystemOsInfo=");
        b.append(useSystemOsInfo);

        b.append("useSystemJdkVersion=");
        b.append(useSystemJdkVersion);

        if (scalaVersion != null) {
            b.append(", scalaVersion=");
            b.append(scalaVersion);
        }

        b.append(")");
        return b.toString();
    }

    public static ResolutionParams create() {
        return new ResolutionParams();
    }

    public static ResolutionParams of(ResolutionParams params) {
        return new ResolutionParams()
                .withMaxIterations(params.maxIterations)
                .withForceProperties(params.forcedProperties)
                .withForceVersions(params.forceVersions)
                .withProfiles(params.profiles)
                .withExclusions(params.exclusions)
                .withUseSystemOsInfo(params.useSystemOsInfo)
                .withUseSystemJdkVersion(params.useSystemJdkVersion)
                .withScalaVersion(params.scalaVersion);
    }

    public ResolutionParams withMaxIterations(Integer maxIterations) {
        this.maxIterations = maxIterations;
        return this;
    }

    public ResolutionParams forceProperty(String name, String value) {
        this.forcedProperties.put(name, value);
        return this;
    }

    public ResolutionParams forceProperties(Map properties) {
        this.forcedProperties.putAll(properties);
        return this;
    }

    public ResolutionParams withForceProperties(Map properties) {
        this.forcedProperties.clear();
        this.forcedProperties.putAll(properties);
        return this;
    }

    public ResolutionParams forceVersion(Module module, String version) {
        this.forceVersions.put(module, version);
        return this;
    }

    public ResolutionParams forceVersions(Map versions) {
        this.forceVersions.putAll(versions);
        return this;
    }

    public ResolutionParams withForceVersions(Map versions) {
        this.forceVersions.clear();
        this.forceVersions.putAll(versions);
        return this;
    }

    public ResolutionParams addProfile(String profile) {
        this.profiles.add(profile);
        return this;
    }
    public ResolutionParams removeProfile(String profile) {
        this.profiles.remove(profile);
        return this;
    }
    public ResolutionParams withProfiles(Set profiles) {
        this.profiles.clear();
        this.profiles.addAll(profiles);
        return this;
    }

    public ResolutionParams addExclusion(String organization, String moduleName) {
        // FIXME Make the Map.Entry read-only?
        this.exclusions.add(new AbstractMap.SimpleEntry<>(organization, moduleName));
        return this;
    }
    public ResolutionParams removeExclusion(String organization, String moduleName) {
        this.exclusions.remove(new AbstractMap.SimpleEntry<>(organization, moduleName));
        return this;
    }
    public ResolutionParams withExclusions(Set> exclusions) {
        this.exclusions.clear();
        this.exclusions.addAll(exclusions);
        return this;
    }

    public ResolutionParams withUseSystemOsInfo(boolean useSystemOsInfo) {
        this.useSystemOsInfo = useSystemOsInfo;
        return this;
    }

    public ResolutionParams withUseSystemJdkVersion(boolean useSystemJdkVersion) {
        this.useSystemJdkVersion = useSystemJdkVersion;
        return this;
    }

    public ResolutionParams withScalaVersion(String scalaVersion) {
        this.scalaVersion = scalaVersion;
        return this;
    }

    public Integer getMaxIterations() {
        return maxIterations;
    }

    public Map getForcedProperties() {
        return Collections.unmodifiableMap(forcedProperties);
    }

    public Map getForceVersions() {
        return Collections.unmodifiableMap(forceVersions);
    }

    public Set getProfiles() {
        return Collections.unmodifiableSet(profiles);
    }

    public Set> getExclusions() {
        return Collections.unmodifiableSet(exclusions);
    }

    public boolean getUseSystemOsInfo() {
        return useSystemOsInfo;
    }

    public boolean getUseSystemJdkVersion() {
        return useSystemJdkVersion;
    }

    public String getScalaVersion() {
        return scalaVersion;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy