public enum C extends Enum<C>
| Modifier and Type | Class and Description |
|---|---|
static class |
C.Array<T> |
static class |
C.F
the namespace of function definitions relevant to Collection manipulation
|
static class |
C.Feature
The character enum for a data structure
|
static interface |
C.Featured
Define a type that holds a set of
C.Feature |
static interface |
C.List<T>
The osgl List interface is a mixture of
List and osgl C.Sequence |
static interface |
C.ListFactory
Defines a factory to create
java List instance
used by DelegatingList to create it's backing data structure |
static interface |
C.ListOrSet<T> |
static class |
C.Map<K,V> |
static interface |
C.Range<ELEMENT>
Define a Range data structure which contains a discrete sequence of elements start from
C.Range.from()
until C.Range.to(). |
static interface |
C.ReversibleSequence<T>
A bidirectional sequence which can be iterated from tail to head
|
static interface |
C.Sequence<T> |
static interface |
C.Set<T> |
static interface |
C.Traversable<T>
Define a traversable structure with functional programming support,
including map, reduce etc.
|
| Enum Constant and Description |
|---|
INSTANCE |
| Modifier and Type | Field and Description |
|---|---|
static String |
CONF_LINKED_LIST_FACTORY
"osgl.list.factory", the property key to configure user defined
list factory. |
static String |
CONF_RANDOM_ACCESS_LIST_FACTORY
"osgl.random_access_list.factory", the property key to configure user defined
random access list factory. |
static C.ListOrSet |
EMPTY |
static C.List |
EMPTY_LIST |
static Map |
EMPTY_MAP |
static C.Set |
EMPTY_SET |
| Modifier and Type | Method and Description |
|---|---|
static <T> Collection<T> |
asCollection(Iterable<T> iterable) |
static <T> C.List<T> |
concat(C.List<T> l1,
C.List<T> l2)
Concatenate two
List into one. |
static <T> C.ReversibleSequence<T> |
concat(C.ReversibleSequence<T> s1,
C.ReversibleSequence<T> s2)
Concatenate two
C.ReversibleSequence into one |
static <T> C.Sequence<T> |
concat(C.Sequence<T> s1,
C.Sequence<T> s2)
Concatenate two
C.Sequence into one |
static <T> C.ListOrSet<T> |
empty() |
static boolean |
empty(Collection<?> col) |
static boolean |
empty(Map map) |
static <T> C.List<T> |
emptyListOf(Class<T> c) |
static <T> Iterable<T> |
enumerable(Enumeration<T> e)
Convert a
Enumeration to an Iterable |
static C.Range<Integer> |
evenNumbers()
|
static <T> C.Sequence<T> |
filter(C.Sequence<T> seq,
Osgl.Function<? super T,Boolean> predicate) |
static <T> void |
forEach(Iterable<? extends T> iterable,
Osgl.Function<? super T,?> visitor)
Run visitor function on each element supplied by the iterable.
|
static <T> void |
forEach(Iterator<? extends T> iterator,
Osgl.Function<? super T,?> visitor)
Run visitor function on each element supplied by the iterator.
|
static <K,V> void |
forEach(Map<K,V> map,
Osgl.Func2<? super K,? super V,?> indexedVisitor)
Run indexedVisitor function on all key/value pair in a given map.
|
static boolean |
isEmpty(Collection<?> col) |
static boolean |
isEmpty(Map map) |
static boolean |
isImmutable(C.Traversable<?> t)
Check if a
C.Traversable structure is immutable. |
static boolean |
isReadOnly(C.Traversable<?> t)
Check if a
C.Traversable structure is read only. |
static <T> C.List<T> |
list()
Returns an empty immutable list
|
static C.List<Boolean> |
list(boolean[] elements)
Create an immutable Boolean list of a byte (primitive type) array.
|
static C.List<Byte> |
list(byte[] elements)
Create an immutable Byte list of a byte (primitive type) array.
|
static C.List<Character> |
list(char[] elements)
Create an immutable Character list of a char array.
|
static <T> C.List<T> |
list(Collection<? extends T> col) |
static C.List<Double> |
list(double[] elements)
Create an immutable Byte list of a double array.
|
static <T> C.List<T> |
list(Enumeration<? extends T> enumeration) |
static C.List<Float> |
list(float[] elements)
Create an immutable byte list of a float array.
|
static C.List<Integer> |
list(int[] elements)
Create an immutable integer list of a int array.
|
static <T> C.List<T> |
list(Iterable<? extends T> iterable) |
static <T> C.List<T> |
list(Iterator<? extends T> iterator) |
static <T> C.List<T> |
list(List<? extends T> javaList) |
static C.List<Long> |
list(long[] elements)
Create an immutable Long list of a long array.
|
static C.List<Short> |
list(short[] elements)
Create an immutable Short list of a short array.
|
static <T> C.List<T> |
list(T t) |
static <T> C.List<T> |
list(T t,
T... ta)
Creates an immutable list from an element plus an array of elements
|
static C.List<Boolean> |
listOf(boolean[] elements)
Create an immutable Boolean list from a boolean (primitive type) array.
|
static C.List<Byte> |
listOf(byte[] elements)
Create an immutable Byte list from a byte (primitive type) array.
|
static C.List<Character> |
listOf(char[] elements)
Create an immutable Short list from a char (primitive type) array.
|
static C.List<Double> |
listOf(double[] elements)
Create an immutable Double list from an double (primitive type) array.
|
static C.List<Float> |
listOf(float[] elements)
Create an immutable Float list from a float (primitive type) array.
|
static C.List<Integer> |
listOf(int[] elements)
Create an immutable Integer list from an int (primitive type) array.
|
static C.List<Long> |
listOf(long[] elements)
Create an immutable Long list from a long (primitive type) array.
|
static C.List<Short> |
listOf(short[] elements)
Create an immutable Short list from a short (primitive type) array.
|
static <T> C.List<T> |
listOf(T... ta)
Creates an immutable list of an array of elements.
|
static <K,V> Map<K,V> |
map(C.Map<? extends K,? extends V> map)
|
static <T,R> C.ReversibleSequence<R> |
map(C.ReversibleSequence<T> seq,
Osgl.Function<? super T,? extends R> mapper) |
static <T,R> C.Sequence<R> |
map(C.Sequence<T> seq,
Osgl.Function<? super T,? extends R> mapper) |
static <K,V> Map<K,V> |
map(Map<? extends K,? extends V> map)
|
static <K,V> Map<K,V> |
map(Object... args)
Create a immutable
Map from elements specified in an array. |
static C.Range<Integer> |
naturalNumbers()
|
static <T> C.List<T> |
newList() |
static <T> C.List<T> |
newList(Iterable<? extends T> iterable) |
static <T> C.List<T> |
newList(T t) |
static <T> C.List<T> |
newList(T t1,
T t2) |
static <T> C.List<T> |
newList(T t1,
T t2,
T t3) |
static <T> C.List<T> |
newList(T t1,
T t2,
T t3,
T... ta) |
static <T> C.List<T> |
newListOf(T[] ts) |
static <K,V> C.Map<K,V> |
newMap(Map<? extends K,? extends V> map)
|
static <K,V> C.Map<K,V> |
newMap(Object... args)
Create an new
Map from an array of elements. |
static <T> C.Set<T> |
newSet()
Create an new empty set
|
static <T> C.Set<T> |
newSet(Collection<? extends T> col)
Create an new set with all elements contained in the collection
specified
|
static <T> C.List<T> |
newSizedList(int size) |
static boolean |
notEmpty(Collection<?> col) |
static boolean |
notEmpty(Map map) |
static C.Range<Integer> |
oddNumbers()
|
static <T> C.Sequence<T> |
prepend(T t,
C.Sequence<T> sequence) |
static C.Range<Byte> |
range(byte from,
byte to)
|
static C.Range<Integer> |
range(int from,
int to)
|
static C.Range<Long> |
range(long from,
long to)
|
static C.Range<Short> |
range(short from,
short to)
|
static <T> C.Sequence<T> |
seq(Enumeration<? extends T> enumeration) |
static <T> C.Sequence<T> |
seq(Iterable<? extends T> iterable)
Return a
C.Sequence consists of all elements in the
iterable specified |
static <T> C.Sequence<T> |
seq(Iterator<? extends T> iterator) |
static <T> C.Set<T> |
set()
Create an empty immutable set
|
static <T> C.Set<T> |
set(Collection<? extends T> col)
Create an immutable set of all elements contained in the collection specified
|
static <T> C.Set<T> |
set(Iterable<? extends T> itr)
Create an immutable set of all elements supplied by the iterable specified
|
static <T> C.Set<T> |
set(T element)
Create an immutable set of a single element
|
static <T> C.Set<T> |
set(T t1,
T... ta)
Create an immutable set contains specified elements
|
static <T> C.Set<T> |
setOf(T... ta)
Create an immutable set of an array of elements
|
static <T> C.List<T> |
singletonList(T t) |
static C |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static C[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
static <T> C.List<T> |
wrap(List<T> list) |
public static final C INSTANCE
public static final String CONF_LINKED_LIST_FACTORY
list factory.
Upon loaded, osgl tried to get a class name string from system
properties use this configuration key. If osgl find the String
returned is not empty then it will initialize the list factory
use the class name configured. If any exception raised during the
initialization, then it might cause the JVM failed to boot uppublic static final String CONF_RANDOM_ACCESS_LIST_FACTORY
random access list factory. See CONF_LINKED_LIST_FACTORY for how osgl use this configurationpublic static final C.List EMPTY_LIST
public static final C.Set EMPTY_SET
public static final Map EMPTY_MAP
public static final C.ListOrSet EMPTY
public static C[] values()
for (C c : C.values()) System.out.println(c);
public static C valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic static boolean empty(Collection<?> col)
public static boolean notEmpty(Collection<?> col)
public static boolean isEmpty(Collection<?> col)
public static boolean empty(Map map)
public static boolean notEmpty(Map map)
public static boolean isEmpty(Map map)
public static <T> Collection<T> asCollection(Iterable<T> iterable)
public static C.Range<Integer> range(int from, int to)
from - specify the left side of the range (inclusive)to - specify the right hand side of the range (exclusive)public static C.Range<Byte> range(byte from, byte to)
from - specify the left side of the range (inclusive)to - specify the right hand side of the range (exclusive)public static C.Range<Short> range(short from, short to)
from - specify the left side of the range (inclusive)to - specify the right hand side of the range (exclusive)public static C.Range<Long> range(long from, long to)
from - specify the left side of the range (inclusive)to - specify the right hand side of the range (exclusive)public static C.Range<Integer> naturalNumbers()
C.Range of non-negative integers start from 0 to Integer.MAX_VALUE. Note
unlike traditional definition of natural number, zero is included in the range returnedpublic static C.Range<Integer> evenNumbers()
public static <T> C.ListOrSet<T> empty()
public static <T> C.List<T> list()
T - the type of the list elementpublic static <T> C.List<T> list(T t)
public static <T> C.List<T> listOf(T... ta)
Note the array will not be copied, instead it will
be used directly as the backing data for the list.
To create an list with a copy of the array specified.
Use the newListOf(Object[]) method
T - the element typeta - an array of elementspublic static <T> C.List<T> list(T t, T... ta)
T - the element typet - the first elementta - the arraypublic static C.List<Boolean> listOf(boolean[] elements)
At the moment the implementation will convert the boolean (primary) array to Boolean (wraper) array, thus a copy of the array will actually take place. However it should assume the array will directly be used as backing data in user application to cater to the future optimized implementation
elements - an array of primary booleanpublic static C.List<Boolean> list(boolean[] elements)
elements - an array of bytespublic static C.List<Byte> listOf(byte[] elements)
At the moment the implementation will convert the byte (primary) array to Byte (reference) array, thus a copy of the array will actually take place. However it should assume the array will directly be used as backing data in user application to cater to the future optimized implementation
elements - an array of primary bytepublic static C.List<Byte> list(byte[] elements)
elements - an array of bytespublic static C.List<Character> listOf(char[] elements)
At the moment the implementation will convert the char (primary) array to Character (reference) array, thus a copy of the array will actually take place. However it should assume the array will directly be used as backing data in user application to cater to the future optimized implementation
elements - an array of primary shortpublic static C.List<Character> list(char[] elements)
elements - an array of shortspublic static C.List<Short> listOf(short[] elements)
At the moment the implementation will convert the short (primary) array to Short (reference) array, thus a copy of the array will actually take place. However it should assume the array will directly be used as backing data in user application to cater to the future optimized implementation
elements - an array of primary shortpublic static C.List<Short> list(short[] elements)
elements - an array of shortspublic static C.List<Integer> listOf(int[] elements)
At the moment the implementation will convert the int (primary) array to Integer (reference) array, thus a copy of the array will actually take place. However it should assume the array will directly be used as backing data in user application to cater to the future optimized implementation
elements - an array of primary intpublic static C.List<Integer> list(int[] elements)
elements - an array of intpublic static C.List<Long> listOf(long[] elements)
At the moment the implementation will convert the long (primary) array to Long (reference) array, thus a copy of the array will actually take place. However it should assume the array will directly be used as backing data in user application to cater to the future optimized implementation
elements - an array of primary longpublic static C.List<Long> list(long[] elements)
elements - an array of longpublic static C.List<Float> listOf(float[] elements)
At the moment the implementation will convert the float (primary) array to Float (reference) array, thus a copy of the array will actually take place. However it should assume the array will directly be used as backing data in user application to cater to the future optimized implementation
elements - an array of primary floatpublic static C.List<Float> list(float[] elements)
elements - an array of floatspublic static C.List<Double> listOf(double[] elements)
At the moment the implementation will convert the double (primary) array to Double (reference) array, thus a copy of the array will actually take place. However it should assume the array will directly be used as backing data in user application to cater to the future optimized implementation
elements - an array of primary doublepublic static C.List<Double> list(double[] elements)
elements - an array of doublepublic static <T> C.List<T> list(Enumeration<? extends T> enumeration)
public static <T> C.List<T> list(Collection<? extends T> col)
public static <T> C.List<T> singletonList(T t)
public static <T> C.List<T> newSizedList(int size)
public static <T> C.List<T> newList()
public static <T> C.List<T> newList(T t)
public static <T> C.List<T> newList(T t1, T t2)
public static <T> C.List<T> newList(T t1, T t2, T t3)
public static <T> C.List<T> newList(T t1, T t2, T t3, T... ta)
public static <T> C.List<T> newListOf(T[] ts)
public static <T> C.Sequence<T> seq(Iterable<? extends T> iterable)
C.Sequence consists of all elements in the
iterable specifiedT - the element typeiterable - the iterable in which elements will be used to fill into the sequencepublic static <T> C.Sequence<T> seq(Iterator<? extends T> iterator)
public static <T> C.Sequence<T> seq(Enumeration<? extends T> enumeration)
public static <T,R> C.Sequence<R> map(C.Sequence<T> seq, Osgl.Function<? super T,? extends R> mapper)
public static <T,R> C.ReversibleSequence<R> map(C.ReversibleSequence<T> seq, Osgl.Function<? super T,? extends R> mapper)
public static <T> C.Sequence<T> filter(C.Sequence<T> seq, Osgl.Function<? super T,Boolean> predicate)
public static <T> C.Sequence<T> prepend(T t, C.Sequence<T> sequence)
public static <T> C.Sequence<T> concat(C.Sequence<T> s1, C.Sequence<T> s2)
C.Sequence into oneT - the element types1 - the first sequences2 - the second sequencepublic static <T> C.ReversibleSequence<T> concat(C.ReversibleSequence<T> s1, C.ReversibleSequence<T> s2)
C.ReversibleSequence into oneT - the element types1 - the first reversible sequences2 - the second reversible sequencepublic static <T> C.List<T> concat(C.List<T> l1, C.List<T> l2)
List into one.
Note if the first list is readonly or immutable an new list instance will be created with elements in both list 1 and list 2 filled in. Otherwise all elemnets from list 2 will be appended to list 1 and return list 1 instance
T - the element typel1 - list 1l2 - list 2public static <T> C.Set<T> set()
T - the generic typepublic static <T> C.Set<T> set(T element)
T - the element typeelement - the single elementpublic static <T> C.Set<T> set(T t1, T... ta)
T - the element typet1 - one element to be added into the result setta - an array from which all elements will be added into the result setpublic static <T> C.Set<T> setOf(T... ta)
T - the element typeta - the array from which all elements will be added into
the result setpublic static <T> C.Set<T> set(Collection<? extends T> col)
T - the element typecol - the collection from which elements will be added into the
result setnewSet(Collection)public static <T> C.Set<T> set(Iterable<? extends T> itr)
T - the element typeitr - the iterable from where elements will be added into the result setpublic static <T> C.Set<T> newSet()
T - the element typepublic static <T> C.Set<T> newSet(Collection<? extends T> col)
T - the element typecol - the collection from which all elements will be added into
the result setset(Collection)public static <K,V> Map<K,V> map(Object... args)
Map from elements specified in an array.
Example
Map<String, Integer> scores = C.map("Tom", 80, "Peter", 93, ...);
The above code will create an immutable Map with the following entries
Note the array size must be an even number, otherwise IndexOutOfBoundsException
will be thrown out
K - the key typeV - the value typeargs - the argument array specifies the entriesnewMap(Object...)public static <K,V> Map<K,V> map(Map<? extends K,? extends V> map)
K - the key typeV - the value typemap - the map from which entries will be put into the new immutable mappublic static <K,V> Map<K,V> map(C.Map<? extends K,? extends V> map)
K - the key typeV - the value typemap - the map from which entries will be put into the new immutable mappublic static <K,V> C.Map<K,V> newMap(Object... args)
Map from an array of elements.
Example
Map<String, Integer> scores = C.newMap("Tom", 80, "Peter", 93, ...);
The above code will create a Map with the following entries
Note the array size must be an even number, otherwise IndexOutOfBoundsException
will be thrown out
K - the key typeV - the value typeargs - the argument array specifies the entriesmap(Object...)public static <K,V> C.Map<K,V> newMap(Map<? extends K,? extends V> map)
K - the key typeV - the value typemap - the map that contains elements to be put into the new mappublic static <T> Iterable<T> enumerable(Enumeration<T> e)
Enumeration to an IterableT - the element typee - the enumerationpublic static boolean isReadOnly(C.Traversable<?> t)
C.Traversable structure is read only. A
Traversable is considered to be read only structure when
is(Feature.READONLY) || is(Feature.IMMUTABLE
evaluate to truet - the structure to be checkedtrue if the structure is read only
or immutablepublic static boolean isImmutable(C.Traversable<?> t)
C.Traversable structure is immutable.t - the traversable strucure to be checkedtrue if the traversable is immutablepublic static <T> void forEach(Iterable<? extends T> iterable, Osgl.Function<? super T,?> visitor) throws Osgl.Break
Osgl.Break if it need to break the loop.
Note if NotAppliedException thrown out by visitor function, it will be ignored
and keep looping through the Map entry set. It is kind of continue mechanism in a funcitonal
way
T - the generic type of the iterable elementsiterable - supply the element to be applied to the visitor functionvisitor - the function called on element provided by the iterable$.Break - break the loopOsgl.Breakpublic static <T> void forEach(Iterator<? extends T> iterator, Osgl.Function<? super T,?> visitor)
Osgl.Break if it need to break the loop.
Note if NotAppliedException thrown out by visitor function, it will be ignored
and keep looping through the Map entry set. It is kind of continue mechanism in a funcitonal
way
T - the generic type of the elementiterator - iterator provides elements to be applied to the visitor functionvisitor - the function applied on the elementpublic static <K,V> void forEach(Map<K,V> map, Osgl.Func2<? super K,? super V,?> indexedVisitor) throws Osgl.Break
Osgl.Break if it need to break the loop.
Note if NotAppliedException thrown out by indexedVisitor function, it will be ignored
and keep looping through the Map entry set. It is kind of continue mechanism in a funcitonal
way
K - the generic type of KeyV - the generic type of Valuemap - the map in which enties will be applied to the indexedVisitor functionindexedVisitor - the function that takes (key,value) pair$.Break - the Osgl.Break with payload throwed out by indexedVisitor function to break to loopOsgl.BreakCopyright © 2017. All Rights Reserved.