genie-common-internal/src/main/java/com/netflix/genie/common/internal/dtos/Criterion.java [42:215]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@Getter
@EqualsAndHashCode(doNotUseGetters = true)
@ToString(doNotUseGetters = true)
@JsonDeserialize(builder = Criterion.Builder.class)
@SuppressWarnings("checkstyle:finalclass")
public class Criterion implements Serializable {

    private static final long serialVersionUID = -8382495858646428806L;

    private final String id;
    private final String name;
    private final String version;
    private final String status;
    private final ImmutableSet<
        @NotEmpty(message = "A tag can't be an empty string")
        @Size(max = 255, message = "A tag can't be longer than 255 characters") String> tags;

    /**
     * Copy the contents of the given {@link Criterion} but use the supplied status.
     *
     * @param criterion The {@link Criterion} to copy
     * @param status    The status to use
     */
    public Criterion(final Criterion criterion, final String status) {
        this.id = criterion.id;
        this.name = criterion.name;
        this.version = criterion.version;
        this.status = status;
        this.tags = ImmutableSet.copyOf(criterion.getTags());
    }

    private Criterion(final Builder builder) throws IllegalArgumentException {
        this.id = builder.bId;
        this.name = builder.bName;
        this.version = builder.bVersion;
        this.status = builder.bStatus;
        this.tags = builder.bTags == null ? ImmutableSet.of() : ImmutableSet.copyOf(builder.bTags);

        if (
            StringUtils.isBlank(this.id)
                && StringUtils.isBlank(this.name)
                && StringUtils.isBlank(this.version)
                && StringUtils.isBlank(this.status)
                && this.tags.isEmpty()
        ) {
            throw new IllegalArgumentException("Invalid criterion. One of the fields must have a valid value");
        }
    }

    /**
     * Get the id of the resource desired if it exists.
     *
     * @return {@link Optional} wrapping the id
     */
    public Optional<String> getId() {
        return Optional.ofNullable(this.id);
    }

    /**
     * Get the name of the resource desired if it exists.
     *
     * @return {@link Optional} wrapping the name
     */
    public Optional<String> getName() {
        return Optional.ofNullable(this.name);
    }

    /**
     * Get the version of the resource desired if it exists.
     *
     * @return {@link Optional} wrapping the version
     */
    public Optional<String> getVersion() {
        return Optional.ofNullable(this.version);
    }

    /**
     * Get the desired status of the resource if it has been set by the creator.
     *
     * @return {@link Optional} wrapping the status
     */
    public Optional<String> getStatus() {
        return Optional.ofNullable(this.status);
    }

    /**
     * Get the set of tags the creator desires the resource to have if any were set.
     *
     * @return An immutable set of strings. Any attempt at modification will throw an exception.
     */
    public Set<String> getTags() {
        return this.tags;
    }

    /**
     * Builder for creating a Criterion instance.
     *
     * @author tgianos
     * @since 4.0.0
     */
    public static class Builder {
        private String bId;
        private String bName;
        private String bVersion;
        private String bStatus;
        private ImmutableSet<String> bTags;

        /**
         * Set the id of the resource (cluster, command, etc) to use.
         *
         * @param id The id
         * @return The builder
         */
        public Builder withId(@Nullable final String id) {
            this.bId = StringUtils.isBlank(id) ? null : id;
            return this;
        }

        /**
         * Set the name of the resource (cluster, command, etc) to search for.
         *
         * @param name The name of the resource
         * @return The builder
         */
        public Builder withName(@Nullable final String name) {
            this.bName = StringUtils.isBlank(name) ? null : name;
            return this;
        }

        /**
         * Set the version of the resource (cluster, command, etc) to search for.
         *
         * @param version The version of the resource
         * @return The builder
         */
        public Builder withVersion(@Nullable final String version) {
            this.bVersion = StringUtils.isBlank(version) ? null : version;
            return this;
        }

        /**
         * Set the status to search for. Overrides default status of resource in search algorithm.
         *
         * @param status The status to override the default with
         * @return The builder
         */
        public Builder withStatus(@Nullable final String status) {
            this.bStatus = StringUtils.isBlank(status) ? null : status;
            return this;
        }

        /**
         * Set the tags to use in the search.
         *
         * @param tags The tags. Any blanks will be removed
         * @return The builder
         */
        public Builder withTags(@Nullable final Set<String> tags) {
            this.bTags = tags == null ? ImmutableSet.of() : ImmutableSet.copyOf(
                tags
                    .stream()
                    .filter(StringUtils::isNotBlank)
                    .collect(Collectors.toSet()));
            return this;
        }

        /**
         * Build an immutable Criterion. A precondition exception will be thrown if all of the fields are empty.
         *
         * @return A criterion which is completely immutable.
         * @throws IllegalArgumentException A valid Criterion must have at least one field populated
         */
        public Criterion build() throws IllegalArgumentException {
            return new Criterion(this);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



genie-common/src/main/java/com/netflix/genie/common/dto/Criterion.java [42:215]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@Getter
@EqualsAndHashCode(doNotUseGetters = true)
@ToString(doNotUseGetters = true)
@JsonDeserialize(builder = Criterion.Builder.class)
@SuppressWarnings("checkstyle:finalclass")
public class Criterion implements Serializable {

    private static final long serialVersionUID = -8382495858646428806L;

    private final String id;
    private final String name;
    private final String version;
    private final String status;
    private final ImmutableSet<
        @NotEmpty(message = "A tag can't be an empty string")
        @Size(max = 255, message = "A tag can't be longer than 255 characters") String> tags;

    /**
     * Copy the contents of the given {@link Criterion} but use the supplied status.
     *
     * @param criterion The {@link Criterion} to copy
     * @param status    The status to use
     */
    public Criterion(final Criterion criterion, final String status) {
        this.id = criterion.id;
        this.name = criterion.name;
        this.version = criterion.version;
        this.status = status;
        this.tags = ImmutableSet.copyOf(criterion.getTags());
    }

    private Criterion(final Builder builder) throws IllegalArgumentException {
        this.id = builder.bId;
        this.name = builder.bName;
        this.version = builder.bVersion;
        this.status = builder.bStatus;
        this.tags = builder.bTags == null ? ImmutableSet.of() : ImmutableSet.copyOf(builder.bTags);

        if (
            StringUtils.isBlank(this.id)
                && StringUtils.isBlank(this.name)
                && StringUtils.isBlank(this.version)
                && StringUtils.isBlank(this.status)
                && this.tags.isEmpty()
        ) {
            throw new IllegalArgumentException("Invalid criterion. One of the fields must have a valid value");
        }
    }

    /**
     * Get the id of the resource desired if it exists.
     *
     * @return {@link Optional} wrapping the id
     */
    public Optional<String> getId() {
        return Optional.ofNullable(this.id);
    }

    /**
     * Get the name of the resource desired if it exists.
     *
     * @return {@link Optional} wrapping the name
     */
    public Optional<String> getName() {
        return Optional.ofNullable(this.name);
    }

    /**
     * Get the version of the resource desired if it exists.
     *
     * @return {@link Optional} wrapping the version
     */
    public Optional<String> getVersion() {
        return Optional.ofNullable(this.version);
    }

    /**
     * Get the desired status of the resource if it has been set by the creator.
     *
     * @return {@link Optional} wrapping the status
     */
    public Optional<String> getStatus() {
        return Optional.ofNullable(this.status);
    }

    /**
     * Get the set of tags the creator desires the resource to have if any were set.
     *
     * @return An immutable set of strings. Any attempt at modification will throw an exception.
     */
    public Set<String> getTags() {
        return this.tags;
    }

    /**
     * Builder for creating a Criterion instance.
     *
     * @author tgianos
     * @since 4.0.0
     */
    public static class Builder {
        private String bId;
        private String bName;
        private String bVersion;
        private String bStatus;
        private ImmutableSet<String> bTags;

        /**
         * Set the id of the resource (cluster, command, etc) to use.
         *
         * @param id The id
         * @return The builder
         */
        public Builder withId(@Nullable final String id) {
            this.bId = StringUtils.isBlank(id) ? null : id;
            return this;
        }

        /**
         * Set the name of the resource (cluster, command, etc) to search for.
         *
         * @param name The name of the resource
         * @return The builder
         */
        public Builder withName(@Nullable final String name) {
            this.bName = StringUtils.isBlank(name) ? null : name;
            return this;
        }

        /**
         * Set the version of the resource (cluster, command, etc) to search for.
         *
         * @param version The version of the resource
         * @return The builder
         */
        public Builder withVersion(@Nullable final String version) {
            this.bVersion = StringUtils.isBlank(version) ? null : version;
            return this;
        }

        /**
         * Set the status to search for. Overrides default status of resource in search algorithm.
         *
         * @param status The status to override the default with
         * @return The builder
         */
        public Builder withStatus(@Nullable final String status) {
            this.bStatus = StringUtils.isBlank(status) ? null : status;
            return this;
        }

        /**
         * Set the tags to use in the search.
         *
         * @param tags The tags. Any blanks will be removed
         * @return The builder
         */
        public Builder withTags(@Nullable final Set<String> tags) {
            this.bTags = tags == null ? ImmutableSet.of() : ImmutableSet.copyOf(
                tags
                    .stream()
                    .filter(StringUtils::isNotBlank)
                    .collect(Collectors.toSet()));
            return this;
        }

        /**
         * Build an immutable Criterion. A precondition exception will be thrown if all of the fields are empty.
         *
         * @return A criterion which is completely immutable.
         * @throws IllegalArgumentException A valid Criterion must have at least one field populated
         */
        public Criterion build() throws IllegalArgumentException {
            return new Criterion(this);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



