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

io.fabric8.openshift.api.model.ScopeRestrictionBuilder Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package io.fabric8.openshift.api.model;

import io.fabric8.kubernetes.api.builder.VisitableBuilder;
import java.lang.Boolean;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import javax.validation.ValidationException;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.util.Set;
import java.lang.Object;

public class ScopeRestrictionBuilder extends ScopeRestrictionFluentImpl implements VisitableBuilder{

    ScopeRestrictionFluent fluent;
    Boolean validationEnabled;

    public ScopeRestrictionBuilder(){
            this(true);
    }
    public ScopeRestrictionBuilder(Boolean validationEnabled){
            this(new ScopeRestriction(), validationEnabled);
    }
    public ScopeRestrictionBuilder(ScopeRestrictionFluent fluent){
            this(fluent, true);
    }
    public ScopeRestrictionBuilder(ScopeRestrictionFluent fluent,Boolean validationEnabled){
            this(fluent, new ScopeRestriction(), validationEnabled);
    }
    public ScopeRestrictionBuilder(ScopeRestrictionFluent fluent,ScopeRestriction instance){
            this(fluent, instance, true);
    }
    public ScopeRestrictionBuilder(ScopeRestrictionFluent fluent,ScopeRestriction instance,Boolean validationEnabled){
            this.fluent = fluent; 
            fluent.withClusterRole(instance.getClusterRole()); 
            fluent.withLiterals(instance.getLiterals()); 
            this.validationEnabled = validationEnabled; 
    }
    public ScopeRestrictionBuilder(ScopeRestriction instance){
            this(instance,true);
    }
    public ScopeRestrictionBuilder(ScopeRestriction instance,Boolean validationEnabled){
            this.fluent = this; 
            this.withClusterRole(instance.getClusterRole()); 
            this.withLiterals(instance.getLiterals()); 
            this.validationEnabled = validationEnabled; 
    }

    public ScopeRestriction build(){
            ScopeRestriction buildable = new ScopeRestriction(fluent.getClusterRole(),fluent.getLiterals());
            validate(buildable);
            return buildable;
    }

    private void validate(T item){
            if (!validationEnabled) { return; }
            Validator validator = null;
            try {
                ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
                validator = factory.getValidator();
            } catch(ValidationException e) {return;}
            Set> violations = validator.validate(item);
            if (!violations.isEmpty()) {
            throw new ConstraintViolationException(violations);
             }
    }

    public boolean equals(Object o){
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            if (!super.equals(o)) return false;
            ScopeRestrictionBuilder that = (ScopeRestrictionBuilder) o;
            if (fluent != null &&fluent != this ? !fluent.equals(that.fluent) :that.fluent != null &&fluent != this ) return false;

            if (validationEnabled != null ? !validationEnabled.equals(that.validationEnabled) :that.validationEnabled != null) return false;
            return true;
    }




}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy