001// Generated by delombok at Sat Feb 25 17:58:34 UTC 2023
002package io.cui.tools.net;
003
004import static java.util.Objects.requireNonNull;
005import java.io.Serializable;
006import java.util.List;
007import lombok.NonNull;
008
009/**
010 * Defines a filter identifying which parameters are not to be included within
011 * url parameter handling. Therefore, it filters parameter prefixed with
012 * "javax.faces", depending on <code>excludeFacesParameter</code> and
013 * additionally a given list of parameter names.
014 * <p>
015 *
016 * @author Oliver Wolff
017 */
018public class ParameterFilter implements Serializable {
019    private static final long serialVersionUID = -4780294784318006024L;
020    private static final String JAVAX_FACES = "javax.faces";
021    /**
022     * The list of string to be excluded from the parameter-list. Because the
023     * test utilizes toLowerCase() the members of the list must all be
024     * lowercase. Otherwise, they are not considered.
025     */
026    @NonNull
027    private final List<String> excludes;
028    /**
029     * Flag indicating whether to exclude technical jsf parameters.
030     */
031    private final boolean excludeFacesParameter;
032
033    /**
034     * @param value
035     *            as key of view parameter. Must not be null
036     * @return true if value belongs to excluded values
037     */
038    public boolean isExcluded(final String value) {
039        requireNonNull(value);
040        var excluded = false;
041        if (excludeFacesParameter) {
042            excluded = value.startsWith(JAVAX_FACES);
043        }
044        if (!excluded) {
045            excluded = excludes.contains(value.toLowerCase());
046        }
047        return excluded;
048    }
049
050    @java.lang.SuppressWarnings("all")
051    @lombok.Generated
052    public ParameterFilter(@NonNull final List<String> excludes, final boolean excludeFacesParameter) {
053        if (excludes == null) {
054            throw new java.lang.NullPointerException("excludes is marked non-null but is null");
055        }
056        this.excludes = excludes;
057        this.excludeFacesParameter = excludeFacesParameter;
058    }
059
060    @java.lang.Override
061    @java.lang.SuppressWarnings("all")
062    @lombok.Generated
063    public boolean equals(final java.lang.Object o) {
064        if (o == this) return true;
065        if (!(o instanceof ParameterFilter)) return false;
066        final ParameterFilter other = (ParameterFilter) o;
067        if (!other.canEqual((java.lang.Object) this)) return false;
068        if (this.excludeFacesParameter != other.excludeFacesParameter) return false;
069        final java.lang.Object this$excludes = this.getExcludes();
070        final java.lang.Object other$excludes = other.getExcludes();
071        if (this$excludes == null ? other$excludes != null : !this$excludes.equals(other$excludes)) return false;
072        return true;
073    }
074
075    @java.lang.SuppressWarnings("all")
076    @lombok.Generated
077    protected boolean canEqual(final java.lang.Object other) {
078        return other instanceof ParameterFilter;
079    }
080
081    @java.lang.Override
082    @java.lang.SuppressWarnings("all")
083    @lombok.Generated
084    public int hashCode() {
085        final int PRIME = 59;
086        int result = 1;
087        result = result * PRIME + (this.excludeFacesParameter ? 79 : 97);
088        final java.lang.Object $excludes = this.getExcludes();
089        result = result * PRIME + ($excludes == null ? 43 : $excludes.hashCode());
090        return result;
091    }
092
093    @java.lang.Override
094    @java.lang.SuppressWarnings("all")
095    @lombok.Generated
096    public java.lang.String toString() {
097        return "ParameterFilter(excludes=" + this.getExcludes() + ", excludeFacesParameter=" + this.excludeFacesParameter + ")";
098    }
099
100    /**
101     * The list of string to be excluded from the parameter-list. Because the
102     * test utilizes toLowerCase() the members of the list must all be
103     * lowercase. Otherwise, they are not considered.
104     */
105    @NonNull
106    @java.lang.SuppressWarnings("all")
107    @lombok.Generated
108    public List<String> getExcludes() {
109        return this.excludes;
110    }
111}