io.alauda.kubernetes.api.model.LimitRangeSpecFluentImpl Maven / Gradle / Ivy
package io.alauda.kubernetes.api.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.alauda.kubernetes.api.builder.Nested;
import java.util.ArrayList;
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 LimitRangeSpecFluentImpl> extends io.alauda.kubernetes.api.builder.BaseFluent implements LimitRangeSpecFluent{
private List limits = new ArrayList();
public LimitRangeSpecFluentImpl(){
}
public LimitRangeSpecFluentImpl(LimitRangeSpec instance){
this.withLimits(instance.getLimits());
}
public A addToLimits(int index,LimitRangeItem item){
LimitRangeItemBuilder builder = new LimitRangeItemBuilder(item);_visitables.add(index >= 0 ? index : _visitables.size(), builder);this.limits.add(index >= 0 ? index : limits.size(), builder); return (A)this;
}
public A setToLimits(int index,LimitRangeItem item){
LimitRangeItemBuilder builder = new LimitRangeItemBuilder(item);
if (index < 0 || index >= _visitables.size()) { _visitables.add(builder); } else { _visitables.set(index, builder);}
if (index < 0 || index >= limits.size()) { limits.add(builder); } else { limits.set(index, builder);}
return (A)this;
}
public A addToLimits(LimitRangeItem... items){
for (LimitRangeItem item : items) {LimitRangeItemBuilder builder = new LimitRangeItemBuilder(item);_visitables.add(builder);this.limits.add(builder);} return (A)this;
}
public A addAllToLimits(Collection items){
for (LimitRangeItem item : items) {LimitRangeItemBuilder builder = new LimitRangeItemBuilder(item);_visitables.add(builder);this.limits.add(builder);} return (A)this;
}
public A removeFromLimits(LimitRangeItem... items){
for (LimitRangeItem item : items) {LimitRangeItemBuilder builder = new LimitRangeItemBuilder(item);_visitables.remove(builder);this.limits.remove(builder);} return (A)this;
}
public A removeAllFromLimits(Collection items){
for (LimitRangeItem item : items) {LimitRangeItemBuilder builder = new LimitRangeItemBuilder(item);_visitables.remove(builder);this.limits.remove(builder);} return (A)this;
}
/**
* This method has been deprecated, please use method buildLimits instead.
*/
@Deprecated public List getLimits(){
return build(limits);
}
public List buildLimits(){
return build(limits);
}
public LimitRangeItem buildLimit(int index){
return this.limits.get(index).build();
}
public LimitRangeItem buildFirstLimit(){
return this.limits.get(0).build();
}
public LimitRangeItem buildLastLimit(){
return this.limits.get(limits.size() - 1).build();
}
public LimitRangeItem buildMatchingLimit(io.alauda.kubernetes.api.builder.Predicate predicate){
for (LimitRangeItemBuilder item: limits) { if(predicate.apply(item)){return item.build();} } return null;
}
public A withLimits(List limits){
_visitables.removeAll(this.limits);
this.limits.clear();
if (limits != null) {for (LimitRangeItem item : limits){this.addToLimits(item);}} return (A) this;
}
public A withLimits(LimitRangeItem... limits){
this.limits.clear(); if (limits != null) {for (LimitRangeItem item :limits){ this.addToLimits(item);}} return (A) this;
}
public Boolean hasLimits(){
return limits!= null && !limits.isEmpty();
}
public LimitRangeSpecFluent.LimitsNested addNewLimit(){
return new LimitsNestedImpl();
}
public LimitRangeSpecFluent.LimitsNested addNewLimitLike(LimitRangeItem item){
return new LimitsNestedImpl(-1, item);
}
public LimitRangeSpecFluent.LimitsNested setNewLimitLike(int index,LimitRangeItem item){
return new LimitsNestedImpl(index, item);
}
public LimitRangeSpecFluent.LimitsNested editLimit(int index){
if (limits.size() <= index) throw new RuntimeException("Can't edit limits. Index exceeds size.");
return setNewLimitLike(index, buildLimit(index));
}
public LimitRangeSpecFluent.LimitsNested editFirstLimit(){
if (limits.size() == 0) throw new RuntimeException("Can't edit first limits. The list is empty.");
return setNewLimitLike(0, buildLimit(0));
}
public LimitRangeSpecFluent.LimitsNested editLastLimit(){
int index = limits.size() - 1;
if (index < 0) throw new RuntimeException("Can't edit last limits. The list is empty.");
return setNewLimitLike(index, buildLimit(index));
}
public LimitRangeSpecFluent.LimitsNested editMatchingLimit(io.alauda.kubernetes.api.builder.Predicate predicate){
int index = -1;
for (int i=0;i extends LimitRangeItemFluentImpl> implements LimitRangeSpecFluent.LimitsNested,io.alauda.kubernetes.api.builder.Nested{
private final LimitRangeItemBuilder builder;
private final int index;
LimitsNestedImpl(int index,LimitRangeItem item){
this.index = index;
this.builder = new LimitRangeItemBuilder(this, item);
}
LimitsNestedImpl(){
this.index = -1;
this.builder = new LimitRangeItemBuilder(this);
}
public N and(){
return (N) LimitRangeSpecFluentImpl.this.setToLimits(index, builder.build());
}
public N endLimit(){
return and();
}
}
}