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

io.dekorate.halkyon.model.CapabilitiesFluentImpl Maven / Gradle / Ivy

There is a newer version: 2.0.0.beta2
Show newest version
package io.dekorate.halkyon.model;

import io.dekorate.deps.kubernetes.api.builder.VisitableBuilder;
import io.dekorate.deps.kubernetes.api.builder.Nested;
import java.util.ArrayList;
import io.dekorate.deps.kubernetes.api.builder.Predicate;
import java.lang.Deprecated;
import io.dekorate.deps.kubernetes.api.builder.BaseFluent;
import java.util.Iterator;
import java.util.Collection;
import java.lang.Object;
import java.util.List;
import java.lang.Boolean;

public class CapabilitiesFluentImpl> extends BaseFluent implements CapabilitiesFluent {

    private List requires;
    private List provides;

    public CapabilitiesFluentImpl() { 
    }


    public CapabilitiesFluentImpl(Capabilities instance) { 
        this.withRequires(instance.getRequires()); 
        this.withProvides(instance.getProvides()); 
    }


    public A withRequires(RequiredComponentCapability... requires) {
        if (this.requires != null) {this.requires.clear();}
        if (requires != null) {for (RequiredComponentCapability item :requires){ this.addToRequires(item);}} return (A) this;
    }

    
/**
 * This method has been deprecated, please use method buildRequires instead.
 */
@Deprecated public RequiredComponentCapability[] getRequires() {
        int size = requires != null ? requires.size() : 0;
RequiredComponentCapability[] result = new RequiredComponentCapability[size];
if (size == 0) {
   return result;
}
int index = 0;
for (VisitableBuilder builder : requires) {
    result[index++]=builder.build();
}
return result;

    }

    public RequiredComponentCapability[] buildRequires() {
        int size = requires != null ? requires.size() : 0;
RequiredComponentCapability[] result = new RequiredComponentCapability[size];
if (size == 0) {
   return result;
}
int index = 0;
for (VisitableBuilder builder : requires) {
    result[index++]=builder.build();
}
return result;

    }

    public RequiredComponentCapability buildRequire(int index) {
        return this.requires.get(index).build();
    }

    public RequiredComponentCapability buildFirstRequire() {
        return this.requires.get(0).build();
    }

    public RequiredComponentCapability buildLastRequire() {
        return this.requires.get(requires.size() - 1).build();
    }

    public RequiredComponentCapability buildMatchingRequire(io.dekorate.deps.kubernetes.api.builder.Predicate predicate) {
        for (RequiredComponentCapabilityBuilder item: requires) { if(predicate.apply(item)){ return item.build();} } return null;
    }

    public Boolean hasMatchingRequire(io.dekorate.deps.kubernetes.api.builder.Predicate predicate) {
        for (RequiredComponentCapabilityBuilder item: requires) { if(predicate.apply(item)){ return true;} } return false;
    }

    public A addToRequires(int index,RequiredComponentCapability item) {
        if (this.requires == null) {this.requires = new ArrayList();}
        RequiredComponentCapabilityBuilder builder = new RequiredComponentCapabilityBuilder(item);_visitables.get("requires").add(index >= 0 ? index : _visitables.get("requires").size(), builder);this.requires.add(index >= 0 ? index : requires.size(), builder); return (A)this;
    }

    public A setToRequires(int index,RequiredComponentCapability item) {
        if (this.requires == null) {this.requires = new ArrayList();}
        RequiredComponentCapabilityBuilder builder = new RequiredComponentCapabilityBuilder(item);
        if (index < 0 || index >= _visitables.get("requires").size()) { _visitables.get("requires").add(builder); } else { _visitables.get("requires").set(index, builder);}
        if (index < 0 || index >= requires.size()) { requires.add(builder); } else { requires.set(index, builder);}
         return (A)this;
    }

    public A addToRequires(RequiredComponentCapability... items) {
        if (this.requires == null) {this.requires = new ArrayList();}
        for (RequiredComponentCapability item : items) {RequiredComponentCapabilityBuilder builder = new RequiredComponentCapabilityBuilder(item);_visitables.get("requires").add(builder);this.requires.add(builder);} return (A)this;
    }

    public A addAllToRequires(Collection items) {
        if (this.requires == null) {this.requires = new ArrayList();}
        for (RequiredComponentCapability item : items) {RequiredComponentCapabilityBuilder builder = new RequiredComponentCapabilityBuilder(item);_visitables.get("requires").add(builder);this.requires.add(builder);} return (A)this;
    }

    public A removeFromRequires(RequiredComponentCapability... items) {
        for (RequiredComponentCapability item : items) {RequiredComponentCapabilityBuilder builder = new RequiredComponentCapabilityBuilder(item);_visitables.get("requires").remove(builder);if (this.requires != null) {this.requires.remove(builder);}} return (A)this;
    }

    public A removeAllFromRequires(Collection items) {
        for (RequiredComponentCapability item : items) {RequiredComponentCapabilityBuilder builder = new RequiredComponentCapabilityBuilder(item);_visitables.get("requires").remove(builder);if (this.requires != null) {this.requires.remove(builder);}} return (A)this;
    }

    public A removeMatchingFromRequires(io.dekorate.deps.kubernetes.api.builder.Predicate predicate) {
        if (requires == null) return (A) this;
        final Iterator each = requires.iterator();
        final List visitables = _visitables.get("requires");
        while (each.hasNext()) {
          RequiredComponentCapabilityBuilder builder = each.next();
          if (predicate.apply(builder)) {
            visitables.remove(builder);
            each.remove();
          }
        }
        return (A)this;
    }

    public Boolean hasRequires() {
        return requires != null && !requires.isEmpty();
    }

    public CapabilitiesFluent.RequiresNested addNewRequire() {
        return new RequiresNestedImpl();
    }

    public CapabilitiesFluent.RequiresNested addNewRequireLike(RequiredComponentCapability item) {
        return new RequiresNestedImpl(-1, item);
    }

    public CapabilitiesFluent.RequiresNested setNewRequireLike(int index,RequiredComponentCapability item) {
        return new RequiresNestedImpl(index, item);
    }

    public CapabilitiesFluent.RequiresNested editRequire(int index) {
        if (requires.size() <= index) throw new RuntimeException("Can't edit requires. Index exceeds size.");
        return setNewRequireLike(index, buildRequire(index));
    }

    public CapabilitiesFluent.RequiresNested editFirstRequire() {
        if (requires.size() == 0) throw new RuntimeException("Can't edit first requires. The list is empty.");
        return setNewRequireLike(0, buildRequire(0));
    }

    public CapabilitiesFluent.RequiresNested editLastRequire() {
        int index = requires.size() - 1;
        if (index < 0) throw new RuntimeException("Can't edit last requires. The list is empty.");
        return setNewRequireLike(index, buildRequire(index));
    }

    public CapabilitiesFluent.RequiresNested editMatchingRequire(io.dekorate.deps.kubernetes.api.builder.Predicate predicate) {
        int index = -1;
        for (int i=0;i builder : provides) {
    result[index++]=builder.build();
}
return result;

    }

    public ComponentCapability[] buildProvides() {
        int size = provides != null ? provides.size() : 0;
ComponentCapability[] result = new ComponentCapability[size];
if (size == 0) {
   return result;
}
int index = 0;
for (VisitableBuilder builder : provides) {
    result[index++]=builder.build();
}
return result;

    }

    public ComponentCapability buildProvide(int index) {
        return this.provides.get(index).build();
    }

    public ComponentCapability buildFirstProvide() {
        return this.provides.get(0).build();
    }

    public ComponentCapability buildLastProvide() {
        return this.provides.get(provides.size() - 1).build();
    }

    public ComponentCapability buildMatchingProvide(io.dekorate.deps.kubernetes.api.builder.Predicate predicate) {
        for (ComponentCapabilityBuilder item: provides) { if(predicate.apply(item)){ return item.build();} } return null;
    }

    public Boolean hasMatchingProvide(io.dekorate.deps.kubernetes.api.builder.Predicate predicate) {
        for (ComponentCapabilityBuilder item: provides) { if(predicate.apply(item)){ return true;} } return false;
    }

    public A addToProvides(int index,ComponentCapability item) {
        if (this.provides == null) {this.provides = new ArrayList();}
        ComponentCapabilityBuilder builder = new ComponentCapabilityBuilder(item);_visitables.get("provides").add(index >= 0 ? index : _visitables.get("provides").size(), builder);this.provides.add(index >= 0 ? index : provides.size(), builder); return (A)this;
    }

    public A setToProvides(int index,ComponentCapability item) {
        if (this.provides == null) {this.provides = new ArrayList();}
        ComponentCapabilityBuilder builder = new ComponentCapabilityBuilder(item);
        if (index < 0 || index >= _visitables.get("provides").size()) { _visitables.get("provides").add(builder); } else { _visitables.get("provides").set(index, builder);}
        if (index < 0 || index >= provides.size()) { provides.add(builder); } else { provides.set(index, builder);}
         return (A)this;
    }

    public A addToProvides(ComponentCapability... items) {
        if (this.provides == null) {this.provides = new ArrayList();}
        for (ComponentCapability item : items) {ComponentCapabilityBuilder builder = new ComponentCapabilityBuilder(item);_visitables.get("provides").add(builder);this.provides.add(builder);} return (A)this;
    }

    public A addAllToProvides(Collection items) {
        if (this.provides == null) {this.provides = new ArrayList();}
        for (ComponentCapability item : items) {ComponentCapabilityBuilder builder = new ComponentCapabilityBuilder(item);_visitables.get("provides").add(builder);this.provides.add(builder);} return (A)this;
    }

    public A removeFromProvides(ComponentCapability... items) {
        for (ComponentCapability item : items) {ComponentCapabilityBuilder builder = new ComponentCapabilityBuilder(item);_visitables.get("provides").remove(builder);if (this.provides != null) {this.provides.remove(builder);}} return (A)this;
    }

    public A removeAllFromProvides(Collection items) {
        for (ComponentCapability item : items) {ComponentCapabilityBuilder builder = new ComponentCapabilityBuilder(item);_visitables.get("provides").remove(builder);if (this.provides != null) {this.provides.remove(builder);}} return (A)this;
    }

    public A removeMatchingFromProvides(io.dekorate.deps.kubernetes.api.builder.Predicate predicate) {
        if (provides == null) return (A) this;
        final Iterator each = provides.iterator();
        final List visitables = _visitables.get("provides");
        while (each.hasNext()) {
          ComponentCapabilityBuilder builder = each.next();
          if (predicate.apply(builder)) {
            visitables.remove(builder);
            each.remove();
          }
        }
        return (A)this;
    }

    public Boolean hasProvides() {
        return provides != null && !provides.isEmpty();
    }

    public CapabilitiesFluent.ProvidesNested addNewProvide() {
        return new ProvidesNestedImpl();
    }

    public CapabilitiesFluent.ProvidesNested addNewProvideLike(ComponentCapability item) {
        return new ProvidesNestedImpl(-1, item);
    }

    public CapabilitiesFluent.ProvidesNested setNewProvideLike(int index,ComponentCapability item) {
        return new ProvidesNestedImpl(index, item);
    }

    public CapabilitiesFluent.ProvidesNested editProvide(int index) {
        if (provides.size() <= index) throw new RuntimeException("Can't edit provides. Index exceeds size.");
        return setNewProvideLike(index, buildProvide(index));
    }

    public CapabilitiesFluent.ProvidesNested editFirstProvide() {
        if (provides.size() == 0) throw new RuntimeException("Can't edit first provides. The list is empty.");
        return setNewProvideLike(0, buildProvide(0));
    }

    public CapabilitiesFluent.ProvidesNested editLastProvide() {
        int index = provides.size() - 1;
        if (index < 0) throw new RuntimeException("Can't edit last provides. The list is empty.");
        return setNewProvideLike(index, buildProvide(index));
    }

    public CapabilitiesFluent.ProvidesNested editMatchingProvide(io.dekorate.deps.kubernetes.api.builder.Predicate predicate) {
        int index = -1;
        for (int i=0;i extends RequiredComponentCapabilityFluentImpl> implements CapabilitiesFluent.RequiresNested,io.dekorate.deps.kubernetes.api.builder.Nested {
        private final RequiredComponentCapabilityBuilder builder;
        private final int index;

        RequiresNestedImpl(int index,RequiredComponentCapability item) {
            this.index = index;
            this.builder = new RequiredComponentCapabilityBuilder(this, item);
        }

        RequiresNestedImpl() {
            this.index = -1;
            this.builder = new RequiredComponentCapabilityBuilder(this);
        }

        public N and() {
             return (N) CapabilitiesFluentImpl.this.setToRequires(index,builder.build());
        }

        public N endRequire() {
             return and();
        }
    }


    public class ProvidesNestedImpl extends ComponentCapabilityFluentImpl> implements CapabilitiesFluent.ProvidesNested,io.dekorate.deps.kubernetes.api.builder.Nested {
        private final ComponentCapabilityBuilder builder;
        private final int index;

        ProvidesNestedImpl(int index,ComponentCapability item) {
            this.index = index;
            this.builder = new ComponentCapabilityBuilder(this, item);
        }

        ProvidesNestedImpl() {
            this.index = -1;
            this.builder = new ComponentCapabilityBuilder(this);
        }

        public N and() {
             return (N) CapabilitiesFluentImpl.this.setToProvides(index,builder.build());
        }

        public N endProvide() {
             return and();
        }
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy