OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 174
Line 16... Line 16...
16
import org.openconcerto.utils.cc.IClosure;
16
import org.openconcerto.utils.cc.IClosure;
17
import org.openconcerto.utils.cc.IPredicate;
17
import org.openconcerto.utils.cc.IPredicate;
18
import org.openconcerto.utils.cc.ITransformer;
18
import org.openconcerto.utils.cc.ITransformer;
19
import org.openconcerto.utils.cc.IdentityHashSet;
19
import org.openconcerto.utils.cc.IdentityHashSet;
20
import org.openconcerto.utils.cc.IdentitySet;
20
import org.openconcerto.utils.cc.IdentitySet;
-
 
21
import org.openconcerto.utils.cc.LinkedIdentitySet;
21
import org.openconcerto.utils.cc.Transformer;
22
import org.openconcerto.utils.cc.Transformer;
22
 
23
 
23
import java.io.Serializable;
24
import java.io.Serializable;
24
import java.util.AbstractSet;
25
import java.util.AbstractSet;
25
import java.util.ArrayList;
26
import java.util.ArrayList;
Line 641... Line 642...
641
            collector.addAll(transf.transformChecked(coll));
642
            collector.addAll(transf.transformChecked(coll));
642
        }
643
        }
643
        return collector;
644
        return collector;
644
    }
645
    }
645
 
646
 
646
    @SuppressWarnings("unchecked")
-
 
647
    public static <T> Collection<T> subtract(final Collection<T> a, final Collection<? extends T> b) {
647
    public static <T> Collection<T> subtract(final Collection<T> a, final Collection<? extends T> b) {
-
 
648
        final Collection<T> res = a instanceof IdentitySet ? new LinkedIdentitySet<>(a) : new ArrayList<>(a);
648
        return org.apache.commons.collections.CollectionUtils.subtract(a, b);
649
        for (Iterator<? extends T> it = b.iterator(); it.hasNext();) {
-
 
650
            res.remove(it.next());
-
 
651
        }
-
 
652
        return res;
649
    }
653
    }
650
 
654
 
651
    @SuppressWarnings("unchecked")
-
 
652
    public static <T> Collection<T> substract(final Collection<T> a, final Collection<? extends T> b) {
655
    public static <T> Collection<T> substract(final Collection<T> a, final Collection<? extends T> b) {
653
        return org.apache.commons.collections.CollectionUtils.subtract(a, b);
656
        return subtract(a, b);
654
    }
657
    }
655
 
658
 
656
    public static final <T> T coalesce(T o1, T o2) {
659
    public static final <T> T coalesce(T o1, T o2) {
657
        return o1 != null ? o1 : o2;
660
        return o1 != null ? o1 : o2;
658
    }
661
    }
Line 933... Line 936...
933
     * Creates a map with null values.
936
     * Creates a map with null values.
934
     * 
937
     * 
935
     * @param <K> type of key.
938
     * @param <K> type of key.
936
     * @param <V> type of value.
939
     * @param <V> type of value.
937
     * @param keys the keys of the map.
940
     * @param keys the keys of the map.
938
     * @return a new map, if <code>keys</code> is a {@link List} it will be ordered.
941
     * @return a new ordered map.
939
     */
942
     */
940
    public static <K, V> Map<K, V> createMap(Collection<? extends K> keys) {
943
    public static <K, V> Map<K, V> createMap(Collection<? extends K> keys) {
-
 
944
        // there's no way to tell if a Collection is ordered, so always use ordered map.
941
        return fillMap(keys instanceof List ? new LinkedHashMap<K, V>(keys.size()) : new HashMap<K, V>(keys.size()), keys);
945
        return fillMap(new LinkedHashMap<K, V>(keys.size()), keys);
942
    }
946
    }
943
 
947
 
944
    /**
948
    /**
945
     * Fills a map with null values.
949
     * Fills a map with null values.
946
     * 
950
     *