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

com.enonic.xp.content.ValidationErrors Maven / Gradle / Ivy

The newest version!
package com.enonic.xp.content;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

import com.google.common.collect.ImmutableList;

public final class ValidationErrors
{
    private final ImmutableList errors;

    private ValidationErrors( final Collection validationErrors )
    {
        errors = ImmutableList.copyOf( validationErrors );
    }

    public static Builder create()
    {
        return new Builder();
    }

    /**
     * Returns true if there were any errors.
     * @return true if there were any errors
     */
    public boolean hasErrors()
    {
        return !errors.isEmpty();
    }

    /**
     * Returns a stream of {@link ValidationError} instances.
     * @return a stream of {@link ValidationError} instances
     */
    public Stream stream()
    {
        return errors.stream();
    }

    @Override
    public boolean equals( final Object o )
    {
        if ( this == o )
        {
            return true;
        }
        if ( o == null || getClass() != o.getClass() )
        {
            return false;
        }
        final ValidationErrors that = (ValidationErrors) o;
        return errors.equals( that.errors );
    }

    @Override
    public int hashCode()
    {
        return Objects.hash( errors );
    }

    public static class Builder
    {
        private final List validationErrors = new ArrayList<>();

        public Builder add( final ValidationError dataValidationError )
        {
            this.validationErrors.add( dataValidationError );
            return this;
        }

        public Builder addAll( final Collection validationErrors )
        {
            this.validationErrors.addAll( validationErrors );
            return this;
        }

        public ValidationErrors build()
        {
            return new ValidationErrors( this.validationErrors );
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy