OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 177
Line 15... Line 15...
15
 
15
 
16
import org.openconcerto.utils.CollectionUtils;
16
import org.openconcerto.utils.CollectionUtils;
17
import org.openconcerto.utils.CompareUtils;
17
import org.openconcerto.utils.CompareUtils;
18
import org.openconcerto.utils.Tuple2;
18
import org.openconcerto.utils.Tuple2;
19
 
19
 
-
 
20
import java.util.Arrays;
20
import java.util.Collection;
21
import java.util.Collection;
21
import java.util.Collections;
22
import java.util.Collections;
22
import java.util.HashSet;
23
import java.util.HashSet;
23
import java.util.Set;
24
import java.util.Set;
24
 
25
 
Line 45... Line 46...
45
    @SuppressWarnings("unchecked")
46
    @SuppressWarnings("unchecked")
46
    public static <T> IncludeExclude<T> getFull() {
47
    public static <T> IncludeExclude<T> getFull() {
47
        return (IncludeExclude<T>) FULL;
48
        return (IncludeExclude<T>) FULL;
48
    }
49
    }
49
 
50
 
-
 
51
    @SafeVarargs
-
 
52
    public static <T> IncludeExclude<T> getNormalized(final T... includes) {
-
 
53
        return getNormalized(Arrays.asList(includes));
-
 
54
    }
-
 
55
 
50
    public static <T> IncludeExclude<T> getNormalized(final Collection<? extends T> includes) {
56
    public static <T> IncludeExclude<T> getNormalized(final Collection<? extends T> includes) {
51
        return getNormalized(includes, Collections.<T> emptySet());
57
        return getNormalized(includes, Collections.<T> emptySet());
52
    }
58
    }
53
 
59
 
54
    public static <T> IncludeExclude<T> getNormalized(final Collection<? extends T> includes, final Collection<? extends T> excludes) {
60
    public static <T> IncludeExclude<T> getNormalized(final Collection<? extends T> includes, final Collection<? extends T> excludes) {
Line 107... Line 113...
107
     *
113
     *
108
     * @param s an object to test.
114
     * @param s an object to test.
109
     * @return <code>true</code> if is in include and not in exclude.
115
     * @return <code>true</code> if is in include and not in exclude.
110
     */
116
     */
111
    public final boolean isIncluded(final T s) {
117
    public final boolean isIncluded(final T s) {
-
 
118
        // "if" order is irrelevant since those methods use getNormal() and it can't be both "all"
-
 
119
        // and "none".
112
        if (this.isAllIncluded())
120
        if (this.isAllIncluded())
113
            return true;
121
            return true;
114
        else if (this.isNoneIncluded())
122
        else if (this.isNoneIncluded())
115
            return false;
123
            return false;
116
        else
124
        else
Line 168... Line 176...
168
     * Whether this includes all objects.
176
     * Whether this includes all objects.
169
     *
177
     *
170
     * @return <code>true</code> if {@link #isIncluded(Object)} always return <code>true</code>
178
     * @return <code>true</code> if {@link #isIncluded(Object)} always return <code>true</code>
171
     */
179
     */
172
    public final boolean isAllIncluded() {
180
    public final boolean isAllIncluded() {
-
 
181
        // use normalized value to avoid ambiguous "include all" and "exclude all"
173
        return this.normal == FULL;
182
        return this.normal == FULL;
174
    }
183
    }
175
 
184
 
176
    /**
185
    /**
177
     * Whether this includes no objects.
186
     * Whether this includes no objects.
178
     *
187
     *
179
     * @return <code>true</code> if {@link #isIncluded(Object)} always return <code>false</code>
188
     * @return <code>true</code> if {@link #isIncluded(Object)} always return <code>false</code>
180
     */
189
     */
181
    public final boolean isNoneIncluded() {
190
    public final boolean isNoneIncluded() {
-
 
191
        // use normalized value to avoid ambiguous "include all" and "exclude all"
182
        return this.normal == EMPTY;
192
        return this.normal == EMPTY;
183
    }
193
    }
184
 
194
 
185
    /**
195
    /**
186
     * The one and only object included by this.
196
     * The one and only object included by this.
Line 210... Line 220...
210
            return sole.get1();
220
            return sole.get1();
211
        else
221
        else
212
            return ifNoSole;
222
            return ifNoSole;
213
    }
223
    }
214
 
224
 
-
 
225
    @SafeVarargs
-
 
226
    public final IncludeExclude<T> include(final T... items) {
-
 
227
        return this.include(Arrays.asList(items));
-
 
228
    }
-
 
229
 
215
    public final IncludeExclude<T> include(final Collection<? extends T> items) {
230
    public final IncludeExclude<T> include(final Collection<? extends T> items) {
216
        if (this.areAllIncluded(items))
231
        if (this.areAllIncluded(items))
217
            return this;
232
            return this;
218
        else if (this.excludes == null)
233
        else if (this.excludes == null)
219
            throw new IllegalStateException("Cannot include an item when excluding all");
234
            throw new IllegalStateException("Cannot include an item when excluding all");
Line 236... Line 251...
236
        }
251
        }
237
 
252
 
238
        return new IncludeExclude<T>(newIncludes, newExcludes, false, false);
253
        return new IncludeExclude<T>(newIncludes, newExcludes, false, false);
239
    }
254
    }
240
 
255
 
-
 
256
    @SafeVarargs
-
 
257
    public final IncludeExclude<T> exclude(final T... items) {
-
 
258
        return this.exclude(Arrays.asList(items));
-
 
259
    }
-
 
260
 
241
    public final IncludeExclude<T> exclude(final Collection<? extends T> items) {
261
    public final IncludeExclude<T> exclude(final Collection<? extends T> items) {
242
        if (this.areNoneIncluded(items))
262
        if (this.areNoneIncluded(items))
243
            return this;
263
            return this;
244
 
264
 
245
        assert this.excludes != null : "!areNoneIncluded() but this.excludes == null";
265
        assert this.excludes != null : "!areNoneIncluded() but this.excludes == null";