io.alauda.devops.api.model.GroupRestrictionFluentImpl Maven / Gradle / Ivy
package io.alauda.devops.api.model;
import io.alauda.kubernetes.api.model.LabelSelectorBuilder;
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.model.LabelSelector;
import java.lang.String;
import io.alauda.kubernetes.api.builder.Predicate;
import java.lang.Deprecated;
import javax.validation.Valid;
import io.alauda.kubernetes.api.builder.BaseFluent;
import java.util.Collection;
import java.lang.Object;
import java.util.List;
import java.lang.Boolean;
public class GroupRestrictionFluentImpl> extends io.alauda.kubernetes.api.builder.BaseFluent implements GroupRestrictionFluent{
private List groups = new ArrayList();
private List labels = new ArrayList();
public GroupRestrictionFluentImpl(){
}
public GroupRestrictionFluentImpl(GroupRestriction instance){
this.withGroups(instance.getGroups());
this.withLabels(instance.getLabels());
}
public A addToGroups(int index,String item){
this.groups.add(index, item); return (A)this;
}
public A setToGroups(int index,String item){
this.groups.set(index, item); return (A)this;
}
public A addToGroups(String... items){
for (String item : items) {this.groups.add(item);} return (A)this;
}
public A addAllToGroups(Collection items){
for (String item : items) {this.groups.add(item);} return (A)this;
}
public A removeFromGroups(String... items){
for (String item : items) {this.groups.remove(item);} return (A)this;
}
public A removeAllFromGroups(Collection items){
for (String item : items) {this.groups.remove(item);} return (A)this;
}
public List getGroups(){
return this.groups;
}
public String getGroup(int index){
return this.groups.get(index);
}
public String getFirstGroup(){
return this.groups.get(0);
}
public String getLastGroup(){
return this.groups.get(groups.size() - 1);
}
public String getMatchingGroup(io.alauda.kubernetes.api.builder.Predicate predicate){
for (String item: groups) { if(predicate.apply(item)){return item;} } return null;
}
public A withGroups(List groups){
this.groups.clear();
if (groups != null) {for (String item : groups){this.addToGroups(item);}} return (A) this;
}
public A withGroups(String... groups){
this.groups.clear(); if (groups != null) {for (String item :groups){ this.addToGroups(item);}} return (A) this;
}
public Boolean hasGroups(){
return groups!= null && !groups.isEmpty();
}
public A addToLabels(int index,LabelSelector item){
LabelSelectorBuilder builder = new LabelSelectorBuilder(item);_visitables.add(index >= 0 ? index : _visitables.size(), builder);this.labels.add(index >= 0 ? index : labels.size(), builder); return (A)this;
}
public A setToLabels(int index,LabelSelector item){
LabelSelectorBuilder builder = new LabelSelectorBuilder(item);
if (index < 0 || index >= _visitables.size()) { _visitables.add(builder); } else { _visitables.set(index, builder);}
if (index < 0 || index >= labels.size()) { labels.add(builder); } else { labels.set(index, builder);}
return (A)this;
}
public A addToLabels(LabelSelector... items){
for (LabelSelector item : items) {LabelSelectorBuilder builder = new LabelSelectorBuilder(item);_visitables.add(builder);this.labels.add(builder);} return (A)this;
}
public A addAllToLabels(Collection items){
for (LabelSelector item : items) {LabelSelectorBuilder builder = new LabelSelectorBuilder(item);_visitables.add(builder);this.labels.add(builder);} return (A)this;
}
public A removeFromLabels(LabelSelector... items){
for (LabelSelector item : items) {LabelSelectorBuilder builder = new LabelSelectorBuilder(item);_visitables.remove(builder);this.labels.remove(builder);} return (A)this;
}
public A removeAllFromLabels(Collection items){
for (LabelSelector item : items) {LabelSelectorBuilder builder = new LabelSelectorBuilder(item);_visitables.remove(builder);this.labels.remove(builder);} return (A)this;
}
/**
* This method has been deprecated, please use method buildLabels instead.
*/
@Deprecated public List getLabels(){
return build(labels);
}
public List buildLabels(){
return build(labels);
}
public LabelSelector buildLabel(int index){
return this.labels.get(index).build();
}
public LabelSelector buildFirstLabel(){
return this.labels.get(0).build();
}
public LabelSelector buildLastLabel(){
return this.labels.get(labels.size() - 1).build();
}
public LabelSelector buildMatchingLabel(io.alauda.kubernetes.api.builder.Predicate predicate){
for (LabelSelectorBuilder item: labels) { if(predicate.apply(item)){return item.build();} } return null;
}
public A withLabels(List labels){
_visitables.removeAll(this.labels);
this.labels.clear();
if (labels != null) {for (LabelSelector item : labels){this.addToLabels(item);}} return (A) this;
}
public A withLabels(LabelSelector... labels){
this.labels.clear(); if (labels != null) {for (LabelSelector item :labels){ this.addToLabels(item);}} return (A) this;
}
public Boolean hasLabels(){
return labels!= null && !labels.isEmpty();
}
public GroupRestrictionFluent.LabelsNested addNewLabel(){
return new LabelsNestedImpl();
}
public GroupRestrictionFluent.LabelsNested addNewLabelLike(LabelSelector item){
return new LabelsNestedImpl(-1, item);
}
public GroupRestrictionFluent.LabelsNested setNewLabelLike(int index,LabelSelector item){
return new LabelsNestedImpl(index, item);
}
public GroupRestrictionFluent.LabelsNested editLabel(int index){
if (labels.size() <= index) throw new RuntimeException("Can't edit labels. Index exceeds size.");
return setNewLabelLike(index, buildLabel(index));
}
public GroupRestrictionFluent.LabelsNested editFirstLabel(){
if (labels.size() == 0) throw new RuntimeException("Can't edit first labels. The list is empty.");
return setNewLabelLike(0, buildLabel(0));
}
public GroupRestrictionFluent.LabelsNested editLastLabel(){
int index = labels.size() - 1;
if (index < 0) throw new RuntimeException("Can't edit last labels. The list is empty.");
return setNewLabelLike(index, buildLabel(index));
}
public GroupRestrictionFluent.LabelsNested editMatchingLabel(io.alauda.kubernetes.api.builder.Predicate predicate){
int index = -1;
for (int i=0;i extends LabelSelectorFluentImpl> implements GroupRestrictionFluent.LabelsNested,io.alauda.kubernetes.api.builder.Nested{
private final LabelSelectorBuilder builder;
private final int index;
LabelsNestedImpl(int index,LabelSelector item){
this.index = index;
this.builder = new LabelSelectorBuilder(this, item);
}
LabelsNestedImpl(){
this.index = -1;
this.builder = new LabelSelectorBuilder(this);
}
public N and(){
return (N) GroupRestrictionFluentImpl.this.setToLabels(index, builder.build());
}
public N endLabel(){
return and();
}
}
}