OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 177 Rev 180
Line 14... Line 14...
14
 package org.openconcerto.utils;
14
 package org.openconcerto.utils;
15
 
15
 
16
import org.openconcerto.utils.CollectionMap2.Mode;
16
import org.openconcerto.utils.CollectionMap2.Mode;
17
 
17
 
18
import java.util.Collection;
18
import java.util.Collection;
-
 
19
import java.util.Collections;
19
import java.util.List;
20
import java.util.List;
20
import java.util.Map;
21
import java.util.Map;
-
 
22
import java.util.Objects;
21
import java.util.Set;
23
import java.util.Set;
-
 
24
import java.util.function.Function;
22
 
25
 
23
public interface CollectionMap2Itf<K, C extends Collection<V>, V> extends Map<K, C> {
26
public interface CollectionMap2Itf<K, C extends Collection<V>, V> extends Map<K, C> {
24
 
27
 
25
    public static interface ListMapItf<K, V> extends CollectionMap2Itf<K, List<V>, V> {
28
    public static interface ListMapItf<K, V> extends CollectionMap2Itf<K, List<V>, V> {
-
 
29
        /**
-
 
30
         * Change this instance and return an unmodifiable Map view. After this method, this
-
 
31
         * instance shouldn't be modified, e.g. if a new entry (with a modifiable collection) is
-
 
32
         * added then the returned object will be able to modify it. Contrary to
-
 
33
         * {@link ListMap#unmodifiableMap(ListMapItf)}, the returned object doesn't allocate any
-
 
34
         * memory.
-
 
35
         * 
-
 
36
         * @return an unmodifiable Map view.
-
 
37
         * @see CollectionMap2Itf#convertToUnmodifiableMap(Function)
-
 
38
         */
-
 
39
        public default Map<K, List<V>> convertToUnmodifiableMap() {
-
 
40
            return convertToUnmodifiableMap(Collections::unmodifiableList);
-
 
41
        }
26
    }
42
    }
27
 
43
 
28
    public static interface SetMapItf<K, V> extends CollectionMap2Itf<K, Set<V>, V> {
44
    public static interface SetMapItf<K, V> extends CollectionMap2Itf<K, Set<V>, V> {
-
 
45
        /**
-
 
46
         * Change this instance and return an unmodifiable Map view. After this method, this
-
 
47
         * instance shouldn't be modified, e.g. if a new entry (with a modifiable collection) is
-
 
48
         * added then the returned object will be able to modify it. Contrary to
-
 
49
         * {@link SetMap#unmodifiableMap(ListMapItf)}, the returned object doesn't allocate any
-
 
50
         * memory.
-
 
51
         * 
-
 
52
         * @return an unmodifiable Map view.
-
 
53
         * @see CollectionMap2Itf#convertToUnmodifiableMap(Function)
-
 
54
         */
-
 
55
        public default Map<K, Set<V>> convertToUnmodifiableMap() {
-
 
56
            return convertToUnmodifiableMap(Collections::unmodifiableSet);
-
 
57
        }
29
    }
58
    }
30
 
59
 
31
    public Mode getMode();
60
    public Mode getMode();
32
 
61
 
33
    public boolean isEmptyCollSameAsNoColl();
62
    public boolean isEmptyCollSameAsNoColl();
Line 114... Line 143...
114
    public boolean removeAllScalar(final Map<? extends K, ? extends V> m);
143
    public boolean removeAllScalar(final Map<? extends K, ? extends V> m);
115
 
144
 
116
    public Set<K> removeAllEmptyCollections();
145
    public Set<K> removeAllEmptyCollections();
117
 
146
 
118
    public Set<K> removeAllNullCollections();
147
    public Set<K> removeAllNullCollections();
-
 
148
 
-
 
149
    public default void replaceAllNonNullValues(final Function<? super C, ? extends C> function) {
-
 
150
        this.replaceAll((k, v) -> v == null ? null : function.apply(v));
-
 
151
    }
-
 
152
 
-
 
153
    /**
-
 
154
     * Change this instance and return an unmodifiable Map view. After this method, this instance
-
 
155
     * shouldn't be modified, e.g. if a new entry (with a modifiable collection) is added then the
-
 
156
     * returned object will be able to modify it. The returned object doesn't allocate any memory.
-
 
157
     * 
-
 
158
     * @param toUnmodifiable how to replace collections with unmodifiable views, never passed
-
 
159
     *        <code>null</code>.
-
 
160
     * @return an unmodifiable Map view.
-
 
161
     * @see SetMapItf#convertToUnmodifiableMap()
-
 
162
     * @see ListMapItf#convertToUnmodifiableMap()
-
 
163
     */
-
 
164
    public default Map<K, C> convertToUnmodifiableMap(final Function<? super C, ? extends C> toUnmodifiable) {
-
 
165
        this.replaceAllNonNullValues(Objects.requireNonNull(toUnmodifiable));
-
 
166
        return Collections.unmodifiableMap(this);
-
 
167
    }
119
}
168
}