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

io.dekorate.prometheus.model.ServiceMonitorSpecFluent Maven / Gradle / Ivy

package io.dekorate.prometheus.model;

import io.fabric8.kubernetes.api.model.LabelSelectorBuilder;
import io.fabric8.kubernetes.api.builder.VisitableBuilder;
import java.lang.SuppressWarnings;
import io.fabric8.kubernetes.api.builder.Nested;
import java.util.ArrayList;
import io.fabric8.kubernetes.api.model.LabelSelector;
import java.lang.String;
import java.util.function.Predicate;
import io.fabric8.kubernetes.api.builder.BaseFluent;
import java.util.Iterator;
import java.util.Collection;
import java.lang.Object;
import java.util.List;
import io.fabric8.kubernetes.api.model.LabelSelectorFluent;

/**
 * Generated
 */
@SuppressWarnings("unchecked")
public class ServiceMonitorSpecFluent> extends BaseFluent{
  public ServiceMonitorSpecFluent() {
  }
  
  public ServiceMonitorSpecFluent(ServiceMonitorSpec instance) {
    this.copyInstance(instance);
  }
  private LabelSelectorBuilder selector;
  private ArrayList endpoints;
  
  protected void copyInstance(ServiceMonitorSpec instance) {
    instance = (instance != null ? instance : new ServiceMonitorSpec());
    if (instance != null) {
          this.withSelector(instance.getSelector());
          this.withEndpoints(instance.getEndpoints());
        }
  }
  
  public LabelSelector buildSelector() {
    return this.selector != null ? this.selector.build() : null;
  }
  
  public A withSelector(LabelSelector selector) {
    this._visitables.remove("selector");
    if (selector != null) {
        this.selector = new LabelSelectorBuilder(selector);
        this._visitables.get("selector").add(this.selector);
    } else {
        this.selector = null;
        this._visitables.get("selector").remove(this.selector);
    }
    return (A) this;
  }
  
  public boolean hasSelector() {
    return this.selector != null;
  }
  
  public SelectorNested withNewSelector() {
    return new SelectorNested(null);
  }
  
  public SelectorNested withNewSelectorLike(LabelSelector item) {
    return new SelectorNested(item);
  }
  
  public SelectorNested editSelector() {
    return withNewSelectorLike(java.util.Optional.ofNullable(buildSelector()).orElse(null));
  }
  
  public SelectorNested editOrNewSelector() {
    return withNewSelectorLike(java.util.Optional.ofNullable(buildSelector()).orElse(new LabelSelectorBuilder().build()));
  }
  
  public SelectorNested editOrNewSelectorLike(LabelSelector item) {
    return withNewSelectorLike(java.util.Optional.ofNullable(buildSelector()).orElse(item));
  }
  
  public A addToEndpoints(int index,Endpoint item) {
    if (this.endpoints == null) {this.endpoints = new ArrayList();}
    EndpointBuilder builder = new EndpointBuilder(item);
    if (index < 0 || index >= endpoints.size()) { _visitables.get("endpoints").add(builder); endpoints.add(builder); } else { _visitables.get("endpoints").add(index, builder); endpoints.add(index, builder);}
    return (A)this;
  }
  
  public A setToEndpoints(int index,Endpoint item) {
    if (this.endpoints == null) {this.endpoints = new ArrayList();}
    EndpointBuilder builder = new EndpointBuilder(item);
    if (index < 0 || index >= endpoints.size()) { _visitables.get("endpoints").add(builder); endpoints.add(builder); } else { _visitables.get("endpoints").set(index, builder); endpoints.set(index, builder);}
    return (A)this;
  }
  
  public A addToEndpoints(io.dekorate.prometheus.model.Endpoint... items) {
    if (this.endpoints == null) {this.endpoints = new ArrayList();}
    for (Endpoint item : items) {EndpointBuilder builder = new EndpointBuilder(item);_visitables.get("endpoints").add(builder);this.endpoints.add(builder);} return (A)this;
  }
  
  public A addAllToEndpoints(Collection items) {
    if (this.endpoints == null) {this.endpoints = new ArrayList();}
    for (Endpoint item : items) {EndpointBuilder builder = new EndpointBuilder(item);_visitables.get("endpoints").add(builder);this.endpoints.add(builder);} return (A)this;
  }
  
  public A removeFromEndpoints(io.dekorate.prometheus.model.Endpoint... items) {
    if (this.endpoints == null) return (A)this;
    for (Endpoint item : items) {EndpointBuilder builder = new EndpointBuilder(item);_visitables.get("endpoints").remove(builder); this.endpoints.remove(builder);} return (A)this;
  }
  
  public A removeAllFromEndpoints(Collection items) {
    if (this.endpoints == null) return (A)this;
    for (Endpoint item : items) {EndpointBuilder builder = new EndpointBuilder(item);_visitables.get("endpoints").remove(builder); this.endpoints.remove(builder);} return (A)this;
  }
  
  public A removeMatchingFromEndpoints(Predicate predicate) {
    if (endpoints == null) return (A) this;
    final Iterator each = endpoints.iterator();
    final List visitables = _visitables.get("endpoints");
    while (each.hasNext()) {
      EndpointBuilder builder = each.next();
      if (predicate.test(builder)) {
        visitables.remove(builder);
        each.remove();
      }
    }
    return (A)this;
  }
  
  public List buildEndpoints() {
    return this.endpoints != null ? build(endpoints) : null;
  }
  
  public Endpoint buildEndpoint(int index) {
    return this.endpoints.get(index).build();
  }
  
  public Endpoint buildFirstEndpoint() {
    return this.endpoints.get(0).build();
  }
  
  public Endpoint buildLastEndpoint() {
    return this.endpoints.get(endpoints.size() - 1).build();
  }
  
  public Endpoint buildMatchingEndpoint(Predicate predicate) {
      for (EndpointBuilder item : endpoints) {
        if (predicate.test(item)) {
          return item.build();
        }
      }
      return null;
  }
  
  public boolean hasMatchingEndpoint(Predicate predicate) {
      for (EndpointBuilder item : endpoints) {
        if (predicate.test(item)) {
          return true;
        }
      }
      return false;
  }
  
  public A withEndpoints(List endpoints) {
    if (this.endpoints != null) {
      this._visitables.get("endpoints").clear();
    }
    if (endpoints != null) {
        this.endpoints = new ArrayList();
        for (Endpoint item : endpoints) {
          this.addToEndpoints(item);
        }
    } else {
      this.endpoints = null;
    }
    return (A) this;
  }
  
  public A withEndpoints(io.dekorate.prometheus.model.Endpoint... endpoints) {
    if (this.endpoints != null) {
        this.endpoints.clear();
        _visitables.remove("endpoints");
    }
    if (endpoints != null) {
      for (Endpoint item : endpoints) {
        this.addToEndpoints(item);
      }
    }
    return (A) this;
  }
  
  public boolean hasEndpoints() {
    return this.endpoints != null && !this.endpoints.isEmpty();
  }
  
  public EndpointsNested addNewEndpoint() {
    return new EndpointsNested(-1, null);
  }
  
  public EndpointsNested addNewEndpointLike(Endpoint item) {
    return new EndpointsNested(-1, item);
  }
  
  public EndpointsNested setNewEndpointLike(int index,Endpoint item) {
    return new EndpointsNested(index, item);
  }
  
  public EndpointsNested editEndpoint(int index) {
    if (endpoints.size() <= index) throw new RuntimeException("Can't edit endpoints. Index exceeds size.");
    return setNewEndpointLike(index, buildEndpoint(index));
  }
  
  public EndpointsNested editFirstEndpoint() {
    if (endpoints.size() == 0) throw new RuntimeException("Can't edit first endpoints. The list is empty.");
    return setNewEndpointLike(0, buildEndpoint(0));
  }
  
  public EndpointsNested editLastEndpoint() {
    int index = endpoints.size() - 1;
    if (index < 0) throw new RuntimeException("Can't edit last endpoints. The list is empty.");
    return setNewEndpointLike(index, buildEndpoint(index));
  }
  
  public EndpointsNested editMatchingEndpoint(Predicate predicate) {
    int index = -1;
    for (int i=0;i extends LabelSelectorFluent> implements Nested{
    SelectorNested(LabelSelector item) {
      this.builder = new LabelSelectorBuilder(this, item);
    }
    LabelSelectorBuilder builder;
    
    public N and() {
      return (N) ServiceMonitorSpecFluent.this.withSelector(builder.build());
    }
    
    public N endSelector() {
      return and();
    }
    
  
  }
  public class EndpointsNested extends EndpointFluent> implements Nested{
    EndpointsNested(int index,Endpoint item) {
      this.index = index;
      this.builder = new EndpointBuilder(this, item);
    }
    EndpointBuilder builder;
    int index;
    
    public N and() {
      return (N) ServiceMonitorSpecFluent.this.setToEndpoints(index,builder.build());
    }
    
    public N endEndpoint() {
      return and();
    }
    
  
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy