OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Rev 180 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
83 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.utils;
15
 
16
import org.openconcerto.utils.CollectionMap2.Mode;
17
 
18
import java.util.Collection;
19
import java.util.List;
20
import java.util.Map;
21
import java.util.Set;
22
 
23
public interface CollectionMap2Itf<K, C extends Collection<V>, V> extends Map<K, C> {
24
 
25
    public static interface ListMapItf<K, V> extends CollectionMap2Itf<K, List<V>, V> {
26
    }
27
 
28
    public static interface SetMapItf<K, V> extends CollectionMap2Itf<K, Set<V>, V> {
29
    }
30
 
31
    public Mode getMode();
32
 
33
    public boolean isEmptyCollSameAsNoColl();
34
 
35
    public C getNonNull(K key);
36
 
37
    /**
38
     * Get the collection mapped to the passed key. Note : <code>get(key, true, true)</code> is
39
     * equivalent to <code>get(key)</code>.
40
     *
41
     * @param key the key whose associated value is to be returned.
42
     * @param nullIfMissing only relevant if the key isn't contained : if <code>true</code>
43
     *        <code>null</code> will be returned, otherwise an empty collection.
44
     * @param nullIfPresent only relevant if the key is mapped to <code>null</code> : if
45
     *        <code>true</code> <code>null</code> will be returned, otherwise an empty collection.
46
     * @return the non {@code null} value to which the specified key is mapped, otherwise
47
     *         {@code null} or empty collection depending on the other parameters.
48
     */
49
    public C get(Object key, final boolean nullIfMissing, final boolean nullIfPresent);
50
 
51
    public C getCollection(Object key);
52
 
53
    /**
177 ilm 54
     * Returns <tt>true</tt> if the collection mapped to the passed key contains the specified
55
     * element.
56
     *
57
     * @param key the key.
58
     * @param element element whose presence in the collection is to be tested.
59
     * @return <tt>true</tt> if the collection mapped to the passed key contains the specified
60
     *         element or if the key exists, its collection is <code>null</code> and the
61
     *         {@link #getMode() mode} is {@link Mode#NULL_MEANS_ALL} <br>
62
     *         <code>false</code> if <code>!this.containsKey(key)</code>.
63
     * @throws NullPointerException if the key exists, its collection is <code>null</code> and the
64
     *         {@link #getMode() mode} is not {@link Mode#NULL_MEANS_ALL}.
65
     */
66
    public boolean containsInCollection(K key, V element) throws NullPointerException;
67
 
68
    /**
83 ilm 69
     * Returns a {@link Collection} view of all the values contained in this map. The collection is
70
     * backed by the map, so changes to the map are reflected in the collection, and vice-versa. If
71
     * the map is modified while an iteration over the collection is in progress (except through the
72
     * iterator's own <tt>remove</tt> operation), the results of the iteration are undefined. The
73
     * collection supports element removal, which removes the corresponding values from the map, via
74
     * the <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>, <tt>removeAll</tt>,
75
     * <tt>retainAll</tt> and <tt>clear</tt> operations. Note that it doesn't remove entries only
76
     * values : keySet() doesn't change, use {@link #removeAllEmptyCollections()} and
77
     * {@link #removeAllNullCollections()} afterwards. It does not support the <tt>add</tt> or
78
     * <tt>addAll</tt> operations.
79
     *
80
     * @return a view all values in all entries, <code>null</code> collections are ignored.
81
     */
82
    public Collection<V> allValues();
83
 
84
    // copy passed collection
85
    public C putCollection(final K key, final Collection<? extends V> value);
86
 
87
    public boolean add(final K k, final V v);
88
 
89
    public boolean addAll(final K k, final Collection<? extends V> v);
90
 
91
    /**
92
     * Call {@link #addAll(Object, Collection)} for each entry.
93
     *
94
     * @param mm the collection map to merge.
95
     */
96
    public void merge(final Map<? extends K, ? extends Collection<? extends V>> mm);
97
 
98
    /**
99
     * Call {@link #add(Object, Object)} for each entry.
100
     *
101
     * @param scalarMap the map to merge.
102
     */
103
    public void mergeScalarMap(final Map<? extends K, ? extends V> scalarMap);
104
 
144 ilm 105
    // cannot be called just "remove" since it conflicts with the new method in java 8
106
    public boolean removeOne(final K k, final V v);
83 ilm 107
 
144 ilm 108
    public boolean removeAllInstancesOfItem(final K k, final V v);
109
 
83 ilm 110
    public boolean removeAll(final K k, final Collection<? extends V> v);
111
 
112
    public boolean removeAll(final Map<? extends K, ? extends Collection<? extends V>> mm);
113
 
114
    public boolean removeAllScalar(final Map<? extends K, ? extends V> m);
115
 
116
    public Set<K> removeAllEmptyCollections();
117
 
118
    public Set<K> removeAllNullCollections();
119
}