2
* Copyright 2013 Goldman Sachs.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package com.gs.collections.api.list;
19
import java.util.Comparator;
20
import java.util.List;
22
import com.gs.collections.api.block.function.Function;
23
import com.gs.collections.api.block.function.Function2;
24
import com.gs.collections.api.block.function.primitive.BooleanFunction;
25
import com.gs.collections.api.block.function.primitive.ByteFunction;
26
import com.gs.collections.api.block.function.primitive.CharFunction;
27
import com.gs.collections.api.block.function.primitive.DoubleFunction;
28
import com.gs.collections.api.block.function.primitive.FloatFunction;
29
import com.gs.collections.api.block.function.primitive.IntFunction;
30
import com.gs.collections.api.block.function.primitive.LongFunction;
31
import com.gs.collections.api.block.function.primitive.ShortFunction;
32
import com.gs.collections.api.block.predicate.Predicate;
33
import com.gs.collections.api.block.predicate.Predicate2;
34
import com.gs.collections.api.collection.MutableCollection;
35
import com.gs.collections.api.list.primitive.MutableBooleanList;
36
import com.gs.collections.api.list.primitive.MutableByteList;
37
import com.gs.collections.api.list.primitive.MutableCharList;
38
import com.gs.collections.api.list.primitive.MutableDoubleList;
39
import com.gs.collections.api.list.primitive.MutableFloatList;
40
import com.gs.collections.api.list.primitive.MutableIntList;
41
import com.gs.collections.api.list.primitive.MutableLongList;
42
import com.gs.collections.api.list.primitive.MutableShortList;
43
import com.gs.collections.api.multimap.list.MutableListMultimap;
44
import com.gs.collections.api.partition.list.PartitionMutableList;
45
import com.gs.collections.api.tuple.Pair;
48
* A MutableList is an implementation of a JCF List which provides methods matching the Smalltalk Collection protocol.
50
public interface MutableList<T>
51
extends MutableCollection<T>, List<T>, Cloneable, ListIterable<T>
53
MutableList<T> with(T element);
55
MutableList<T> without(T element);
57
MutableList<T> withAll(Iterable<? extends T> elements);
59
MutableList<T> withoutAll(Iterable<? extends T> elements);
61
MutableList<T> newEmpty();
63
MutableList<T> clone();
65
MutableList<T> select(Predicate<? super T> predicate);
67
<P> MutableList<T> selectWith(Predicate2<? super T, ? super P> predicate, P parameter);
69
MutableList<T> reject(Predicate<? super T> predicate);
71
<P> MutableList<T> rejectWith(Predicate2<? super T, ? super P> predicate, P parameter);
73
PartitionMutableList<T> partition(Predicate<? super T> predicate);
75
<P> PartitionMutableList<T> partitionWith(Predicate2<? super T, ? super P> predicate, P parameter);
77
<S> MutableList<S> selectInstancesOf(Class<S> clazz);
79
<V> MutableList<V> collect(Function<? super T, ? extends V> function);
81
MutableBooleanList collectBoolean(BooleanFunction<? super T> booleanFunction);
83
MutableByteList collectByte(ByteFunction<? super T> byteFunction);
85
MutableCharList collectChar(CharFunction<? super T> charFunction);
87
MutableDoubleList collectDouble(DoubleFunction<? super T> doubleFunction);
89
MutableFloatList collectFloat(FloatFunction<? super T> floatFunction);
91
MutableIntList collectInt(IntFunction<? super T> intFunction);
93
MutableLongList collectLong(LongFunction<? super T> longFunction);
95
MutableShortList collectShort(ShortFunction<? super T> shortFunction);
97
<P, V> MutableList<V> collectWith(Function2<? super T, ? super P, ? extends V> function, P parameter);
99
<V> MutableList<V> collectIf(Predicate<? super T> predicate, Function<? super T, ? extends V> function);
101
<V> MutableList<V> flatCollect(Function<? super T, ? extends Iterable<V>> function);
103
MutableList<T> distinct();
106
* Sorts the internal data structure of this list and returns the list itself as a convenience.
108
MutableList<T> sortThis(Comparator<? super T> comparator);
111
* Sorts the internal data structure of this list and returns the list itself as a convenience.
113
MutableList<T> sortThis();
116
* Sorts the internal data structure of this list based on the natural order of the attribute returned by {@code
119
<V extends Comparable<? super V>> MutableList<T> sortThisBy(Function<? super T, ? extends V> function);
121
MutableList<T> subList(int fromIndex, int toIndex);
124
* Returns an unmodifable view of the list.
125
* The returned list will be <tt>Serializable</tt> if this list is <tt>Serializable</tt>.
127
* @return an unmodifiable view of this list
129
MutableList<T> asUnmodifiable();
131
MutableList<T> asSynchronized();
134
* Returns an immutable copy of this list. If the list is immutable, it returns itself.
135
* The returned list will be <tt>Serializable</tt> if this list is <tt>Serializable</tt>.
137
ImmutableList<T> toImmutable();
139
<V> MutableListMultimap<V, T> groupBy(Function<? super T, ? extends V> function);
141
<V> MutableListMultimap<V, T> groupByEach(Function<? super T, ? extends Iterable<V>> function);
143
<S> MutableList<Pair<T, S>> zip(Iterable<S> that);
145
MutableList<Pair<T, Integer>> zipWithIndex();
147
MutableList<T> takeWhile(Predicate<? super T> predicate);
149
MutableList<T> dropWhile(Predicate<? super T> predicate);
151
PartitionMutableList<T> partitionWhile(Predicate<? super T> predicate);
154
* Returns a new MutableList in reverse order
156
MutableList<T> toReversed();
159
* Mutates the current list by reversing its order and returns the current list as a result
161
MutableList<T> reverseThis();