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

org.apache.maven.model.Repository Maven / Gradle / Ivy

The newest version!
// =================== DO NOT EDIT THIS FILE ====================
//  Generated by Modello Velocity from model-v3.vm
//  template, any modifications will be overwritten.
// ==============================================================
package org.apache.maven.model;

import java.io.Serializable;
import java.util.AbstractList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.maven.api.annotations.Generated;
import org.apache.maven.api.annotations.Nonnull;

@Generated
public class Repository
    extends RepositoryBase
    implements Serializable, Cloneable
{

    public Repository() {
        this(org.apache.maven.api.model.Repository.newInstance());
    }

    public Repository(org.apache.maven.api.model.Repository delegate) {
        this(delegate, null);
    }

    public Repository(org.apache.maven.api.model.Repository delegate, BaseObject parent) {
        super(delegate, parent);
    }

    public Repository clone(){
        return new Repository(getDelegate());
    }

    @Override
    public org.apache.maven.api.model.Repository getDelegate() {
        return (org.apache.maven.api.model.Repository) super.getDelegate();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || !(o instanceof Repository)) {
            return false;
        }
        Repository that = (Repository) o;
        return Objects.equals(this.delegate, that.delegate);
    }

    @Override
    public int hashCode() {
        return getDelegate().hashCode();
    }

    public RepositoryPolicy getReleases() {
        return getDelegate().getReleases() != null ? new RepositoryPolicy(getDelegate().getReleases(), this) : null;
    }

    public void setReleases(RepositoryPolicy releases) {
        if (!Objects.equals(releases, getReleases())){
            if (releases != null) {
                update(getDelegate().withReleases(releases.getDelegate()));
                releases.childrenTracking = this::replace;
            } else {
                update(getDelegate().withReleases(null));
            }
        }
    }

    public RepositoryPolicy getSnapshots() {
        return getDelegate().getSnapshots() != null ? new RepositoryPolicy(getDelegate().getSnapshots(), this) : null;
    }

    public void setSnapshots(RepositoryPolicy snapshots) {
        if (!Objects.equals(snapshots, getSnapshots())){
            if (snapshots != null) {
                update(getDelegate().withSnapshots(snapshots.getDelegate()));
                snapshots.childrenTracking = this::replace;
            } else {
                update(getDelegate().withSnapshots(null));
            }
        }
    }

    public InputLocation getLocation(Object key) {
        org.apache.maven.api.model.InputLocation loc = getDelegate().getLocation(key);
        return loc != null ? new InputLocation(loc) : null;
    }

    public void setLocation(Object key, InputLocation location) {
        update(org.apache.maven.api.model.Repository.newBuilder(getDelegate(), true)
                        .location(key, location.toApiLocation()).build());
    }

    public InputLocation getImportedFrom() {
        org.apache.maven.api.model.InputLocation loc = getDelegate().getImportedFrom();
        return loc != null ? new InputLocation(loc) : null;
    }

    public void setImportedFrom(InputLocation location) {
        update(org.apache.maven.api.model.Repository.newBuilder(getDelegate(), true)
                        .importedFrom(location.toApiLocation()).build());
    }

    public Set getLocationKeys() {
        return getDelegate().getLocationKeys();
    }

    protected boolean replace(Object oldDelegate, Object newDelegate) {
        if (super.replace(oldDelegate, newDelegate)) {
            return true;
        }
        if (oldDelegate == getDelegate().getReleases()) {
            update(getDelegate().withReleases((org.apache.maven.api.model.RepositoryPolicy) newDelegate));
            return true;
        }
        if (oldDelegate == getDelegate().getSnapshots()) {
            update(getDelegate().withSnapshots((org.apache.maven.api.model.RepositoryPolicy) newDelegate));
            return true;
        }
        return false;
    }

    public static List repositoryToApiV4(List list) {
        return list != null ? new WrapperList<>(list, Repository::getDelegate, Repository::new) : null;
    }

    public static List repositoryToApiV3(List list) {
        return list != null ? new WrapperList<>(list, Repository::new, Repository::getDelegate) : null;
    }

}