OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 82 → Rev 83

/trunk/OpenConcerto/src/org/openconcerto/utils/SetMap.java
13,13 → 13,76
package org.openconcerto.utils;
 
import org.openconcerto.utils.CollectionMap2Itf.SetMapItf;
 
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
 
public class SetMap<K, V> extends CollectionMap2<K, Set<V>, V> {
public class SetMap<K, V> extends CollectionMap2<K, Set<V>, V> implements SetMapItf<K, V> {
 
static private class Unmodifiable<K, V> extends UnmodifiableCollectionMap<K, Set<V>, V> implements SetMapItf<K, V> {
Unmodifiable(CollectionMap2Itf<K, Set<V>, V> delegate) {
super(delegate, new UnmodifiableCollectionMap.UnmodifiableMap<K, Set<V>>(delegate) {
@Override
protected Set<V> toUnmodifiable(Set<V> coll) {
return Collections.unmodifiableSet(coll);
}
});
}
}
 
static public <K, V> SetMapItf<K, V> unmodifiableMap(SetMapItf<K, V> map) {
return new Unmodifiable<K, V>(map);
}
 
@SuppressWarnings({ "unchecked", "rawtypes" })
private static SetMap EMPTY = new SetMap(Collections.emptyMap(), Mode.NULL_FORBIDDEN) {
@Override
public SetMap clone() {
// this instance is immutable and Collections classes might be cloneable
return this;
}
};
 
@SuppressWarnings("unchecked")
public static <K, V> SetMap<K, V> empty() {
return EMPTY;
}
 
public static <K, V> SetMap<K, V> singleton(K key, V... values) {
return singleton(key, Arrays.asList(values));
}
 
public static <K, V> SetMap<K, V> singleton(K key, Collection<? extends V> values) {
return singleton(key, new HashSet<V>(values), false);
}
 
private static <K, V> SetMap<K, V> singleton(K key, Set<V> values, final boolean immutable) {
final Set<V> coll = immutable ? values : Collections.unmodifiableSet(values);
return new SetMap<K, V>(Collections.singletonMap(key, coll), DEFAULT_MODE) {
@Override
public SetMap<K, V> clone() {
// this instance is immutable and Collections classes might be cloneable
return this;
}
};
}
 
// to avoid
// "Type safety : A generic array of Tuple2<String,Boolean> is created for a varargs parameter"
public static <K, V> SetMap<K, V> singleton(K key, V value) {
return singleton(key, Collections.singleton(value), true);
}
 
// static method since one-argument is for copying (see CopyUtils)
static public <K, V> SetMap<K, V> decorate(final Map<K, Set<V>> m) {
return new SetMap<K, V>(m, DEFAULT_MODE);
}
 
public SetMap() {
super();
}
32,10 → 95,6
super(initialCapacity);
}
 
public SetMap(Map<? extends K, ? extends Collection<? extends V>> m) {
super(m);
}
 
public SetMap(Mode mode, boolean emptyCollSameAsNoColl) {
super(mode, emptyCollSameAsNoColl);
}
44,8 → 103,31
super(mode);
}
 
public SetMap(Map<K, Set<V>> delegate, Mode mode) {
super(delegate, mode);
}
 
public SetMap(final Map<K, Set<V>> delegate, final Mode mode, final Boolean emptyCollSameAsNoColl) {
super(delegate, mode, emptyCollSameAsNoColl);
}
 
// ** copy constructors
 
public SetMap(CollectionMap2<K, Set<V>, ? extends V> m) {
super(m);
}
 
public SetMap(Map<? extends K, ? extends Collection<? extends V>> m) {
super(m);
}
 
@Override
public Set<V> createCollection(Collection<? extends V> v) {
return new HashSet<V>(v);
}
 
@Override
public SetMap<K, V> clone() throws CloneNotSupportedException {
return (SetMap<K, V>) super.clone();
}
}