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

org.apache.maven.toolchain.model.PersistedToolchains 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.toolchain.model;

import java.io.Serializable;
import java.util.AbstractList;
import java.util.ArrayList;
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 PersistedToolchains
    extends TrackableBase
    implements Serializable, Cloneable
{

    public PersistedToolchains() {
        this(org.apache.maven.api.toolchain.PersistedToolchains.newInstance());
    }

    public PersistedToolchains(org.apache.maven.api.toolchain.PersistedToolchains delegate) {
        this(delegate, null);
    }

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

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

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

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

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

    public String getModelEncoding() {
        return getDelegate().getModelEncoding();
    }

    @Nonnull
    public List getToolchains() {
        return new WrapperList(
                    () -> getDelegate().getToolchains(), l -> update(getDelegate().withToolchains(l)),
                    d -> new ToolchainModel(d, this), ToolchainModel::getDelegate);
    }

    public void setToolchains(List toolchains) {
        if (toolchains == null) {
            toolchains = Collections.emptyList();
        }
        if (!Objects.equals(toolchains, getToolchains())) {
            update(getDelegate().withToolchains(
                toolchains.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
            toolchains.forEach(e -> e.childrenTracking = this::replace);
        }
    }

    public void addToolchain(ToolchainModel toolchain) {
        update(getDelegate().withToolchains(
               Stream.concat(getDelegate().getToolchains().stream(), Stream.of(toolchain.getDelegate()))
                        .collect(Collectors.toList())));
        toolchain.childrenTracking = this::replace;
    }

    public void removeToolchain(ToolchainModel toolchain) {
        update(getDelegate().withToolchains(
               getDelegate().getToolchains().stream()
                        .filter(e -> !Objects.equals(e, toolchain))
                        .collect(Collectors.toList())));
        toolchain.childrenTracking = null;
    }

    protected boolean replace(Object oldDelegate, Object newDelegate) {
        if (super.replace(oldDelegate, newDelegate)) {
            return true;
        }
        if (getDelegate().getToolchains().contains(oldDelegate)) {
            List list = new ArrayList<>(getDelegate().getToolchains());
            list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.toolchain.ToolchainModel) newDelegate : d);
            update(getDelegate().withToolchains(list));
            return true;
        }
        return false;
    }

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

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy