OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 83 | 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.cc;
15
 
16
import org.openconcerto.utils.CopyUtils;
17
 
18
import java.util.Collection;
19
import java.util.Map;
20
import java.util.Set;
21
 
22
public abstract class AbstractMapDecorator<K, V> implements Map<K, V>, Cloneable {
23
 
24
    // not final because of clone()
25
    private Map<K, V> delegate;
26
 
27
    public AbstractMapDecorator(final Map<K, V> delegate) {
28
        super();
29
        this.delegate = delegate;
30
    }
31
 
32
    protected final Map<K, V> getDelegate() {
33
        return this.delegate;
34
    }
35
 
36
    @Override
37
    public int size() {
38
        return this.delegate.size();
39
    }
40
 
41
    @Override
42
    public boolean isEmpty() {
43
        return this.delegate.isEmpty();
44
    }
45
 
46
    @Override
47
    public boolean containsKey(final Object key) {
48
        return this.delegate.containsKey(key);
49
    }
50
 
51
    @Override
52
    public boolean containsValue(final Object value) {
53
        return this.delegate.containsValue(value);
54
    }
55
 
56
    @Override
57
    public V get(final Object key) {
58
        return this.delegate.get(key);
59
    }
60
 
61
    @Override
62
    public V put(final K key, final V value) {
63
        return this.delegate.put(key, value);
64
    }
65
 
66
    @Override
67
    public V remove(final Object key) {
68
        return this.delegate.remove(key);
69
    }
70
 
71
    @Override
72
    public void putAll(final Map<? extends K, ? extends V> m) {
73
        this.delegate.putAll(m);
74
    }
75
 
76
    @Override
77
    public void clear() {
78
        this.delegate.clear();
79
    }
80
 
81
    @Override
82
    public Set<K> keySet() {
83
        return this.delegate.keySet();
84
    }
85
 
86
    @Override
87
    public Collection<V> values() {
88
        return this.delegate.values();
89
    }
90
 
91
    @Override
92
    public Set<java.util.Map.Entry<K, V>> entrySet() {
93
        return this.delegate.entrySet();
94
    }
95
 
96
    @Override
97
    public boolean equals(final Object o) {
98
        return this.delegate.equals(o);
99
    }
100
 
101
    @Override
102
    public int hashCode() {
103
        return this.delegate.hashCode();
104
    }
105
 
106
    @Override
107
    public String toString() {
108
        return this.getClass().getSimpleName() + " " + this.delegate.toString();
109
    }
110
 
111
    @Override
177 ilm 112
    protected Object clone() {
83 ilm 113
        try {
114
            final Map<K, V> delegate = CopyUtils.copy(this.delegate);
115
            @SuppressWarnings("unchecked")
116
            final AbstractMapDecorator<K, V> res = (AbstractMapDecorator<K, V>) super.clone();
117
            res.delegate = delegate;
118
            return res;
119
        } catch (CloneNotSupportedException e) {
177 ilm 120
            // As done in java.util collections
121
            throw new InternalError(e);
83 ilm 122
        }
123
    }
124
}