io.alauda.kubernetes.api.model.extensions.NetworkPolicySpecFluentImpl Maven / Gradle / Ivy
package io.alauda.kubernetes.api.model.extensions;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.alauda.kubernetes.api.model.LabelSelectorFluentImpl;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.alauda.kubernetes.api.builder.Nested;
import java.util.ArrayList;
import io.alauda.kubernetes.api.builder.Predicate;
import java.lang.Deprecated;
import io.alauda.kubernetes.api.builder.BaseFluent;
import java.util.List;
import java.lang.Boolean;
import io.alauda.kubernetes.api.model.LabelSelectorBuilder;
import io.alauda.kubernetes.api.model.LabelSelector;
import javax.validation.Valid;
import java.util.Collection;
import java.lang.Object;
public class NetworkPolicySpecFluentImpl> extends io.alauda.kubernetes.api.builder.BaseFluent implements NetworkPolicySpecFluent{
private List ingress = new ArrayList();
private LabelSelectorBuilder podSelector;
public NetworkPolicySpecFluentImpl(){
}
public NetworkPolicySpecFluentImpl(NetworkPolicySpec instance){
this.withIngress(instance.getIngress());
this.withPodSelector(instance.getPodSelector());
}
public A addToIngress(int index,NetworkPolicyIngressRule item){
NetworkPolicyIngressRuleBuilder builder = new NetworkPolicyIngressRuleBuilder(item);_visitables.add(index >= 0 ? index : _visitables.size(), builder);this.ingress.add(index >= 0 ? index : ingress.size(), builder); return (A)this;
}
public A setToIngress(int index,NetworkPolicyIngressRule item){
NetworkPolicyIngressRuleBuilder builder = new NetworkPolicyIngressRuleBuilder(item);
if (index < 0 || index >= _visitables.size()) { _visitables.add(builder); } else { _visitables.set(index, builder);}
if (index < 0 || index >= ingress.size()) { ingress.add(builder); } else { ingress.set(index, builder);}
return (A)this;
}
public A addToIngress(NetworkPolicyIngressRule... items){
for (NetworkPolicyIngressRule item : items) {NetworkPolicyIngressRuleBuilder builder = new NetworkPolicyIngressRuleBuilder(item);_visitables.add(builder);this.ingress.add(builder);} return (A)this;
}
public A addAllToIngress(Collection items){
for (NetworkPolicyIngressRule item : items) {NetworkPolicyIngressRuleBuilder builder = new NetworkPolicyIngressRuleBuilder(item);_visitables.add(builder);this.ingress.add(builder);} return (A)this;
}
public A removeFromIngress(NetworkPolicyIngressRule... items){
for (NetworkPolicyIngressRule item : items) {NetworkPolicyIngressRuleBuilder builder = new NetworkPolicyIngressRuleBuilder(item);_visitables.remove(builder);this.ingress.remove(builder);} return (A)this;
}
public A removeAllFromIngress(Collection items){
for (NetworkPolicyIngressRule item : items) {NetworkPolicyIngressRuleBuilder builder = new NetworkPolicyIngressRuleBuilder(item);_visitables.remove(builder);this.ingress.remove(builder);} return (A)this;
}
/**
* This method has been deprecated, please use method buildIngress instead.
*/
@Deprecated public List getIngress(){
return build(ingress);
}
public List buildIngress(){
return build(ingress);
}
public NetworkPolicyIngressRule buildIngress(int index){
return this.ingress.get(index).build();
}
public NetworkPolicyIngressRule buildFirstIngress(){
return this.ingress.get(0).build();
}
public NetworkPolicyIngressRule buildLastIngress(){
return this.ingress.get(ingress.size() - 1).build();
}
public NetworkPolicyIngressRule buildMatchingIngress(io.alauda.kubernetes.api.builder.Predicate predicate){
for (NetworkPolicyIngressRuleBuilder item: ingress) { if(predicate.apply(item)){return item.build();} } return null;
}
public A withIngress(List ingress){
_visitables.removeAll(this.ingress);
this.ingress.clear();
if (ingress != null) {for (NetworkPolicyIngressRule item : ingress){this.addToIngress(item);}} return (A) this;
}
public A withIngress(NetworkPolicyIngressRule... ingress){
this.ingress.clear(); if (ingress != null) {for (NetworkPolicyIngressRule item :ingress){ this.addToIngress(item);}} return (A) this;
}
public Boolean hasIngress(){
return ingress!= null && !ingress.isEmpty();
}
public NetworkPolicySpecFluent.IngressNested addNewIngress(){
return new IngressNestedImpl();
}
public NetworkPolicySpecFluent.IngressNested addNewIngressLike(NetworkPolicyIngressRule item){
return new IngressNestedImpl(-1, item);
}
public NetworkPolicySpecFluent.IngressNested setNewIngressLike(int index,NetworkPolicyIngressRule item){
return new IngressNestedImpl(index, item);
}
public NetworkPolicySpecFluent.IngressNested editIngress(int index){
if (ingress.size() <= index) throw new RuntimeException("Can't edit ingress. Index exceeds size.");
return setNewIngressLike(index, buildIngress(index));
}
public NetworkPolicySpecFluent.IngressNested editFirstIngress(){
if (ingress.size() == 0) throw new RuntimeException("Can't edit first ingress. The list is empty.");
return setNewIngressLike(0, buildIngress(0));
}
public NetworkPolicySpecFluent.IngressNested editLastIngress(){
int index = ingress.size() - 1;
if (index < 0) throw new RuntimeException("Can't edit last ingress. The list is empty.");
return setNewIngressLike(index, buildIngress(index));
}
public NetworkPolicySpecFluent.IngressNested editMatchingIngress(io.alauda.kubernetes.api.builder.Predicate predicate){
int index = -1;
for (int i=0;i withNewPodSelector(){
return new PodSelectorNestedImpl();
}
public NetworkPolicySpecFluent.PodSelectorNested withNewPodSelectorLike(LabelSelector item){
return new PodSelectorNestedImpl(item);
}
public NetworkPolicySpecFluent.PodSelectorNested editPodSelector(){
return withNewPodSelectorLike(getPodSelector());
}
public NetworkPolicySpecFluent.PodSelectorNested editOrNewPodSelector(){
return withNewPodSelectorLike(getPodSelector() != null ? getPodSelector(): new LabelSelectorBuilder().build());
}
public NetworkPolicySpecFluent.PodSelectorNested editOrNewPodSelectorLike(LabelSelector item){
return withNewPodSelectorLike(getPodSelector() != null ? getPodSelector(): item);
}
public boolean equals(Object o){
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
NetworkPolicySpecFluentImpl that = (NetworkPolicySpecFluentImpl) o;
if (ingress != null ? !ingress.equals(that.ingress) :that.ingress != null) return false;
if (podSelector != null ? !podSelector.equals(that.podSelector) :that.podSelector != null) return false;
return true;
}
public class IngressNestedImpl extends NetworkPolicyIngressRuleFluentImpl> implements NetworkPolicySpecFluent.IngressNested,io.alauda.kubernetes.api.builder.Nested{
private final NetworkPolicyIngressRuleBuilder builder;
private final int index;
IngressNestedImpl(int index,NetworkPolicyIngressRule item){
this.index = index;
this.builder = new NetworkPolicyIngressRuleBuilder(this, item);
}
IngressNestedImpl(){
this.index = -1;
this.builder = new NetworkPolicyIngressRuleBuilder(this);
}
public N and(){
return (N) NetworkPolicySpecFluentImpl.this.setToIngress(index, builder.build());
}
public N endIngress(){
return and();
}
}
public class PodSelectorNestedImpl extends LabelSelectorFluentImpl> implements NetworkPolicySpecFluent.PodSelectorNested,io.alauda.kubernetes.api.builder.Nested{
private final LabelSelectorBuilder builder;
PodSelectorNestedImpl(LabelSelector item){
this.builder = new LabelSelectorBuilder(this, item);
}
PodSelectorNestedImpl(){
this.builder = new LabelSelectorBuilder(this);
}
public N and(){
return (N) NetworkPolicySpecFluentImpl.this.withPodSelector(builder.build());
}
public N endPodSelector(){
return and();
}
}
}