-
- Type Parameters:
T- the entity type of the sequence
- All Superinterfaces:
Collection<T>,Foldable<T>,java.lang.Iterable<T>,java.io.Serializable,Streamable<T>,Traversable<T>,Value<T>
public interface List<T> extends Collection<T>
- Since:
- 0.0.5
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description List<T>append(T value)Create a new list containing all elements in this instance and appending the providedvalueto the end of the new list.List<T>distinctBy(java.util.Comparator<T> comparator)Creates a distinct list based upon the provided comparator.List<T>filter(java.util.function.Predicate<T> predicate)Filter out an element if it does not match the suppliedpredicate.intfirstIndexWhere(java.util.function.Predicate<T> predicate)Search the collections for the first element matching the providedPredicateand return the index position of that element.Tget(int index)Get the element at the location ofindex<K> Map<K,? extends List<T>>groupBy(java.util.function.Function<? super T,? extends K> keyGenerator)Generate a new sequence using thekeyGenerator.default intindexOf(java.lang.Object lookFor)Find the index for the provided element, will return-1if the element is not present in the list.<U> List<U>map(java.util.function.Function<T,U> mapper)Perform a mapping operation on the elements in the stream.List<T>orElse(java.lang.Iterable<? extends T> other)Returns eitherthisif it is non empty, otherwise will return the providedother.List<T>orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)Returns eitherthisif it is non empty, otherwise the provided supplier is evaluated and returned.Pipeline<T>pipeline()Create a pipeline for the current list.List<T>reject(java.util.function.Predicate<T> predicate)Return a list that removes all elements that match thepredicateprovided.List<T>remove(int index)Removes an element from the list and returns a new instance of the list.List<T>tail()Build a new collection with all elements except for the head.List<T>union(java.lang.Iterable<T> iterable)Create a new sequence with all elements of this sequence combined with the elements of the provided iterable.-
Methods inherited from interface com.jongsoft.lang.collection.Collection
containsAll, count, first, foldLeft, foldRight, get, head, isEmpty, isSingleValued, last, reduceLeft, size, split, summing
-
Methods inherited from interface com.jongsoft.lang.collection.Traversable
average, iterator, sum
-
-
-
-
Method Detail
-
append
List<T> append(T value)
Create a new list containing all elements in this instance and appending the providedvalueto the end of the new list.Example:
// will result in a list with 2, 3, 4, 1 List(2, 3, 4).append(1)- Parameters:
value- the value to append to the list- Returns:
- the new list with the value appended
-
distinctBy
List<T> distinctBy(java.util.Comparator<T> comparator)
Creates a distinct list based upon the provided comparator. If a duplicate is found only the first match will be included in the returned list.- Parameters:
comparator- the comparator to use for distinct check- Returns:
- the distinct list
-
firstIndexWhere
int firstIndexWhere(java.util.function.Predicate<T> predicate)
Search the collections for the first element matching the providedPredicateand return the index position of that element.- Parameters:
predicate- the predicate to match- Returns:
- index of the found element, -1 if none found
-
filter
List<T> filter(java.util.function.Predicate<T> predicate)
Description copied from interface:StreamableFilter out an element if it does not match the suppliedpredicate. This operation will iterate over all elements and return a new set containing only the elements where the predicate returnstruefor.- Specified by:
filterin interfaceCollection<T>- Specified by:
filterin interfaceStreamable<T>- Specified by:
filterin interfaceTraversable<T>- Parameters:
predicate- the predicate to apply to the contents of this- Returns:
- the filtered value
-
get
T get(int index)
Get the element at the location ofindex- Parameters:
index- the index of the element in the list to get- Returns:
- the element at the provided index
- Throws:
java.lang.IndexOutOfBoundsException- ifindexis greater then theCollection.size()- 1
-
groupBy
<K> Map<K,? extends List<T>> groupBy(java.util.function.Function<? super T,? extends K> keyGenerator)
Generate a new sequence using thekeyGenerator. Calling this operation will create a new map grouping the elements by the generator provided.Example:
// This will result in Map(1 -> List(1, 11, 21), 2 -> List(2, 12, 22)) Sequence(1, 2, 11, 12, 21, 22) .groupBy(x -> x % 10);- Type Parameters:
K- the type of the key- Parameters:
keyGenerator- the generator to use for creating keys- Returns:
- the new map created using the generator
- Throws:
java.lang.NullPointerException- ifkeyGeneratoris null
-
indexOf
default int indexOf(java.lang.Object lookFor)
Find the index for the provided element, will return-1if the element is not present in the list.- Parameters:
lookFor- the element to look for- Returns:
- the index of the element, or
-1if none found
-
map
<U> List<U> map(java.util.function.Function<T,U> mapper)
Description copied from interface:StreamablePerform a mapping operation on the elements in the stream.This operation will loop over all elements in the stream and apply the
mappermethod. The mapped values will be returned in as a new stream of elements.- Specified by:
mapin interfaceCollection<T>- Specified by:
mapin interfaceStreamable<T>- Specified by:
mapin interfaceTraversable<T>- Type Parameters:
U- the type of object expected as a result- Parameters:
mapper- the mapping functionality- Returns:
- the mapped object
-
orElse
List<T> orElse(java.lang.Iterable<? extends T> other)
Description copied from interface:TraversableReturns eitherthisif it is non empty, otherwise will return the providedother.- Specified by:
orElsein interfaceCollection<T>- Specified by:
orElsein interfaceTraversable<T>- Parameters:
other- the alternative- Returns:
- this
Traversableif non empty, orother
-
orElse
List<T> orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
Description copied from interface:TraversableReturns eitherthisif it is non empty, otherwise the provided supplier is evaluated and returned.- Specified by:
orElsein interfaceCollection<T>- Specified by:
orElsein interfaceTraversable<T>- Parameters:
supplier- the supplier to generate the other- Returns:
- this (@code Traversable} if non empty, otherwise other
-
pipeline
Pipeline<T> pipeline()
Create a pipeline for the current list. A pipeline can be used to create a set of lazy operations on the list that will only get executed once the pipe is terminated.- Returns:
- the pipeline for this list
-
reject
List<T> reject(java.util.function.Predicate<T> predicate)
Description copied from interface:TraversableReturn a list that removes all elements that match thepredicateprovided.- Specified by:
rejectin interfaceCollection<T>- Specified by:
rejectin interfaceTraversable<T>- Parameters:
predicate- the predicate to use- Returns:
- the elements that do not match the
predicate
-
remove
List<T> remove(int index)
Removes an element from the list and returns a new instance of the list.- Parameters:
index- the index of the element to be removed- Returns:
- the new instance of the list without the element at the provided index
- Throws:
java.lang.IndexOutOfBoundsException- ifindexis not between the 0 and Collection.size()
-
tail
List<T> tail()
Description copied from interface:CollectionBuild a new collection with all elements except for the head. If there is only one element present then an empty collection will be returned. If the operation is called on an empty collection anNoSuchElementExceptionwill be thrown.- Specified by:
tailin interfaceCollection<T>- Returns:
- a collection containing the tail
-
union
List<T> union(java.lang.Iterable<T> iterable)
Create a new sequence with all elements of this sequence combined with the elements of the provided iterable. The elements in this sequence will be added before the providediterablein the returned sequence.Example:
// the example would be a List(1, 2, 3, 4) List<Integer> result = List(1, 2).union(List(3, 4));- Parameters:
iterable- the elements to be added- Returns:
- the new list containing a union between this and the iterable
-
-