OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 144 Rev 174
Line 17... Line 17...
17
 
17
 
18
import java.util.ArrayList;
18
import java.util.ArrayList;
19
import java.util.Collection;
19
import java.util.Collection;
20
import java.util.LinkedHashSet;
20
import java.util.LinkedHashSet;
21
import java.util.List;
21
import java.util.List;
-
 
22
import java.util.ListIterator;
-
 
23
import java.util.RandomAccess;
22
import java.util.Set;
24
import java.util.Set;
-
 
25
import java.util.function.BiPredicate;
23
 
26
 
24
/**
27
/**
25
 * Allow to create a proxy object which uses a {@link HashingStrategy}.
28
 * Allow to create a proxy object which uses a {@link HashingStrategy}.
26
 * 
29
 * 
27
 * @author Sylvain
30
 * @author Sylvain
Line 101... Line 104...
101
        }
104
        }
102
        assert clazz.isInstance(sA) && clazz.isInstance(sB);
105
        assert clazz.isInstance(sA) && clazz.isInstance(sB);
103
        return CompareUtils.equals(sA, sB);
106
        return CompareUtils.equals(sA, sB);
104
    }
107
    }
105
 
108
 
-
 
109
    static public final <S, T1 extends S> int indexOf(final List<T1> s1, final S o, final HashingStrategy<S> s) {
-
 
110
        return indexOf(s1, o, s::equals);
-
 
111
    }
-
 
112
 
-
 
113
    static public final <S, T1 extends S> int indexOf(final List<T1> s1, final S o, final BiPredicate<S, S> s) {
-
 
114
        if (s1 instanceof RandomAccess) {
-
 
115
            final int stop = s1.size();
-
 
116
            for (int i = 0; i < stop; i++) {
-
 
117
                if (s.test(s1.get(i), o))
-
 
118
                    return i;
-
 
119
            }
-
 
120
        } else {
-
 
121
            final ListIterator<T1> listIter = s1.listIterator();
-
 
122
            while (listIter.hasNext()) {
-
 
123
                final T1 item = listIter.next();
-
 
124
                if (s.test(item, o))
-
 
125
                    return listIter.previousIndex();
-
 
126
            }
-
 
127
        }
-
 
128
        return -1;
-
 
129
    }
-
 
130
 
106
    static public class ProxyFull<S, E extends S> implements ProxyItf<E> {
131
    static public class ProxyFull<S, E extends S> implements ProxyItf<E> {
107
 
132
 
108
        static public final <S, E extends S> Set<ProxyFull<S, E>> createSet(final HashingStrategy<S> strategy, final Collection<E> coll) {
133
        static public final <S, E extends S> Set<ProxyFull<S, E>> createSet(final HashingStrategy<S> strategy, final Collection<E> coll) {
109
            return wrap(strategy, coll, new LinkedHashSet<ProxyFull<S, E>>());
134
            return wrap(strategy, coll, new LinkedHashSet<ProxyFull<S, E>>());
110
        }
135
        }
Line 190... Line 215...
190
            if (this.strategy == null)
215
            if (this.strategy == null)
191
                return DEFAULT.equals(this.getDelegate(), delegate2);
216
                return DEFAULT.equals(this.getDelegate(), delegate2);
192
            else
217
            else
193
                return this.strategy.equals(this.getDelegate(), delegate2);
218
                return this.strategy.equals(this.getDelegate(), delegate2);
194
        }
219
        }
-
 
220
 
-
 
221
        @Override
-
 
222
        public String toString() {
-
 
223
            return this.getClass().getSimpleName() + " using strategy " + this.getStrategy() + " for " + this.getDelegate();
-
 
224
        }
195
    }
225
    }
196
 
226
 
197
    /**
227
    /**
198
     * A proxy object which uses a {@link HashingStrategy}.
228
     * A proxy object which uses a {@link HashingStrategy}.
199
     * 
229
     *