Package com.github.underscore
Class Underscore<T>
java.lang.Object
com.github.underscore.Underscore<T>
- Direct Known Subclasses:
U
Underscore-java17 is a java port of Underscore.js.
- Author:
- Valentyn Kolesnikov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static interface
static class
private static final class
static interface
static interface
private static final class
private static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private static final long
private static final long
private static final long
private static final String
private static final String
private static final String
private static final Pattern
private static final String
private static final int
private static final String
private static final AtomicInteger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> Supplier<E>
static <E> boolean
boolean
static <T> Predicate<T>
static <E> boolean
boolean
static <K,
E> Map<K, E> associateBy
(Iterable<E> iterable, Function<E, K> func) <K,
E> Map<K, E> associateBy
(Function<E, K> func) static <E> Supplier<E>
static <E extends Comparable<E>>
intbinarySearch
(E[] array, E key) static <E extends Comparable<E>>
intbinarySearch
(Iterable<E> iterable, E key) static <T,
F> Function<F, T> chain()
static Underscore.Chain<Integer>
chain
(int[] array) static <T> Underscore.Chain<T>
static <T> Underscore.Chain<T>
static <T> Underscore.Chain<T>
static Underscore.Chain<Map<String,
Object>> static <T> Underscore.Chain<T>
chain
(T... array) static <T> T
checkNotNull
(T reference) static <T> T
checkNotNull
(T reference, Object errorMessage) static <T> List<T>
checkNotNullElements
(List<T> references) chunk
(int size) chunk
(int size, int step) static void
clearInterval
(ScheduledFuture scheduledFuture) static void
clearTimeout
(ScheduledFuture<?> scheduledFuture) static <E> E[]
clone
(E... iterable) static Object
static <T,
E> List<T> static <T,
E> Set<T> compact()
static <E> E[]
compact
(E... array) static <E> E[]
compact
(E[] array, E falsyValue) static <E> List<E>
static <E> List<E>
compactList
(List<E> list, E falsyValue) static <T> Function<T,
T> static <T> List<T>
static <T> T[]
concat
(T[] first, T[]... other) concatWith
(Iterable<T>... other) static <E> Supplier<E>
constant
(E value) static <E> boolean
static <E> boolean
boolean
static <E> boolean
containsAtLeast
(Iterable<E> iterable, E value, int count) boolean
containsAtLeast
(T value, int count) static <E> boolean
containsAtMost
(Iterable<E> iterable, E value, int count) boolean
containsAtMost
(T value, int count) static <E> boolean
containsWith
(Iterable<E> iterable, E elem) boolean
containsWith
(T elem) copyOf()
static <T> List<T>
copyOfRange
(int start, int end) static <T> List<T>
copyOfRange
(Iterable<T> iterable, int start, int end) static <E> int
int
countBy()
cycle
(int times) static <T> List<T>
static <T> Supplier<T>
static <K,
V> Map<K, V> static <T> T
defaultTo
(T value, T defaultValue) static ScheduledFuture<Void>
static <T> ScheduledFuture<T>
static <T> ScheduledFuture<T>
static <E> Optional<E>
static <E> E[]
difference
(E[]... arrays) static <E> List<E>
difference
(List<E> list1, List<E> list2) static <E> List<E>
difference
(List<E> list, List<E>... lists) differenceWith
(List<T>... lists) static <E> E[]
distinct
(E... array) static <E> List<E>
static <K,
E> E[] distinctBy
(E[] array, Function<E, K> func) static <K,
E> Collection<E> distinctBy
(Iterable<E> iterable, Function<E, K> func) private static <E> void
static <E> E[]
drop
(E... array) static <E> E[]
drop
(E[] array, int n) static <E> List<E>
static <E> List<E>
static <T> void
void
static <T> void
eachIndexed
(Iterable<T> iterable, BiConsumer<Integer, ? super T> func) static <T> void
void
elementAt
(int index) static <T> T
elementAtOrElse
(int index, T defaultValue) static <T> T
elementAtOrElse
(List<T> list, int index, T defaultValue) elementAtOrNull
(int index) static <T> T
elementAtOrNull
(List<T> list, int index) static String
static <E> boolean
boolean
static <K,
V> Map<K, V> static <E> List<E>
static <E> List<E>
static <E> Set<E>
filterFalse
(Predicate<T> pred) static <E> List<E>
filterFalse
(List<E> list, Predicate<E> pred) static <E> Set<E>
filterFalse
(Set<E> set, Predicate<E> pred) static <E> List<E>
filterIndexed
(List<E> list, Underscore.PredicateIndexed<E> pred) static <E> Optional<E>
static <E> int
static <E> int
static <E> E
static <E> E
static <E> Optional<E>
static <E> int
findLastIndex
(E[] array, Predicate<E> pred) static <E> int
findLastIndex
(List<E> list, Predicate<E> pred) static <E> E
findLastKey
(E[] array, Predicate<E> pred) static <E> E
findLastKey
(List<E> list, Predicate<E> pred) static <T,
E> Optional<E> first()
first
(int n) static <E> E
first
(E... array) static <E> E
static <E> E
static <E> List<E>
static <E> List<E>
static <E> E
firstOrNull
(Iterable<E> iterable) static <E> E
firstOrNull
(Iterable<E> iterable, Predicate<E> pred) firstOrNull
(Predicate<T> pred) flatten()
flatten
(boolean shallow) static <E> List<E>
static <E> List<E>
private static <E> void
static <T,
E> E foldl
(Iterable<T> iterable, BiFunction<E, T, E> func, E zeroElem) static <T,
E> E foldr
(Iterable<T> iterable, BiFunction<E, T, E> func, E zeroElem) static <T> void
void
static <T> void
forEachIndexed
(Iterable<T> iterable, BiConsumer<Integer, ? super T> func) void
forEachIndexed
(BiConsumer<Integer, ? super T> func) static <T> void
forEachRight
(Iterable<T> iterable, Consumer<? super T> func) void
forEachRight
(Consumer<? super T> func) static String
get
(int index) static <T> T
groupBy
(Iterable<E> iterable, Function<E, K> func, BinaryOperator<E> binaryOperator) groupBy
(Function<E, K> func, BinaryOperator<E> binaryOperator) static <K,
V> boolean head()
head
(int n) static <E> E
head
(E... array) static <E> E
static <E> List<E>
static <E> E
identity
(E value) static <E> boolean
static <E> int
indexOf
(E[] array, E value) static <E> int
initial()
initial
(int n) static <E> E[]
initial
(E... array) static <E> E[]
initial
(E[] array, int n) static <E> List<E>
static <E> List<E>
static <T,
E> E inject
(Iterable<T> iterable, BiFunction<E, T, E> func, E zeroElem) static <T> List<T>
interposeByList
(Iterable<T> interIter) static <T> List<T>
interposeByList
(Iterable<T> iterable, Iterable<T> interIter) static <E> E[]
intersection
(E[]... arrays) static <E> List<E>
intersection
(List<E> list1, List<E> list2) static <E> List<E>
intersection
(List<E> list, List<E>... lists) intersectionWith
(List<T>... lists) static <E> List<E>
static <E> List<E>
static boolean
static boolean
static boolean
boolean
isEmpty()
static <T> boolean
static <K,
V> boolean static boolean
static boolean
static boolean
isFunction
(Object object) static <K,
V> boolean boolean
static <T> boolean
isNotEmpty
(Iterable<T> iterable) static <K,
V> boolean isNotEmpty
(Map<K, V> object) static boolean
static boolean
static boolean
static boolean
static boolean
static <T> Iterable<T>
iterate
(T seed, UnaryOperator<T> unaryOperator) iteratee
(K key) join()
static <T> String
static <T> String
static <T> String
join
(T[] array) static <T> String
static <T> String
joinToString
(Iterable<T> iterable, String separator, String prefix, String postfix, int limit, String truncated, Function<T, String> transform) private static void
joinToStringPostfix
(String postfix, int limit, String truncated, int index, StringBuilder sb) static <K,
V> Set<K> last()
last
(int n) static <E> E
last
(E... array) static <E> E
static <E> List<E>
static <E> E
static int
lastIndex
(int[] array) static <T> int
static <T> int
lastIndex
(T[] array) static <E> int
lastIndexOf
(E[] array, E value) static <E> int
lastIndexOf
(List<E> list, E value) lastOrNull
(Predicate<T> pred) static <E> E
lastOrNull
(List<E> list) static <E> E
lastOrNull
(List<E> list, Predicate<E> pred) static void
static <T> List<T>
<F> List<F>
static <T,
E> List<T> static <T,
E> Set<T> <F> List<F>
mapIndexed
(BiFunction<Integer, ? super T, F> func) static <T,
E> List<T> mapIndexed
(List<E> list, BiFunction<Integer, ? super E, T> func) static <T,
E> List<T> mapMulti
(List<E> list, BiConsumer<? super E, ? super Consumer<T>> mapper) max()
static <E extends Comparable<? super E>>
Emax
(Collection<E> collection) static <E,
F extends Comparable>
Emax
(Collection<E> collection, Function<E, F> func) <F extends Comparable<? super F>>
Tstatic <T,
F> Function<F, T> min()
static <E extends Comparable<? super E>>
Emin
(Collection<E> collection) static <E,
F extends Comparable>
Emin
(Collection<E> collection, Function<E, F> func) <F extends Comparable<? super F>>
Tstatic void
mixin
(String funcName, UnaryOperator<String> func) static <E> Predicate<E>
protected static <T> List<T>
newArrayList
(Iterable<T> iterable) protected static <T> List<T>
newArrayList
(Iterable<T> iterable, int size) protected static <T> List<T>
newArrayList
(T object) protected static <T> List<T>
newArrayListWithExpectedSize
(int size) newIntegerList
(int... array) protected static <T> Set<T>
newLinkedHashSet
(Iterable<T> iterable) protected static <T> Set<T>
newLinkedHashSetWithExpectedSize
(int size) static boolean
static long
now()
of()
static Underscore.Chain<Integer>
of
(int[] array) static <T> Underscore.Chain<T>
static <T> Underscore.Chain<T>
static <T> Underscore.Chain<T>
static <T> Underscore.Chain<T>
of
(T... array) static <T> Supplier<T>
static <T> Predicate<T>
static <E> List<E>[]
pop()
property
(K key) static <K,
V> Function<K, V> propertyOf
(Map<K, V> object) static <T> List<T>
static int
random
(int max) static int
random
(int min, int max) range
(char stop) range
(char start, char stop) range
(char start, char stop, int step) range
(int stop) range
(int start, int stop) range
(int start, int stop, int step) static <E> E
reduce
(int[] array, BiFunction<E, ? super Integer, E> func, E zeroElem) static <T,
E> E reduce
(Iterable<T> iterable, BiFunction<E, T, E> func, E zeroElem) static <T> Optional<T>
reduce
(Iterable<T> iterable, BinaryOperator<T> func) static <T,
E> E reduce
(T[] array, BiFunction<E, T, E> func, E zeroElem) static <E> E
reduceRight
(int[] array, BiFunction<E, ? super Integer, E> func, E zeroElem) static <T,
E> E reduceRight
(Iterable<T> iterable, BiFunction<E, T, E> func, E zeroElem) static <T> Optional<T>
reduceRight
(Iterable<T> iterable, BinaryOperator<T> func) static <T,
E> E reduceRight
(T[] array, BiFunction<E, T, E> func, E zeroElem) static <E> List<E>
static <E> Set<E>
static <E> List<E>
rejectIndexed
(List<E> list, Underscore.PredicateIndexed<E> pred) static <T> List<T>
repeat
(T element, int times) static <T> List<T>
replaceIndexed
(Underscore.PredicateIndexed<T> pred, T value) static <T> List<T>
replaceIndexed
(Iterable<T> iter, Underscore.PredicateIndexed<T> pred, T value) rest()
rest
(int n) static <E> E[]
rest
(E... array) static <E> E[]
rest
(E[] array, int n) static <E> List<E>
static <E> List<E>
static <E> Object
reverse()
reverse
(int[] array) static <T> List<T>
static <T> T[]
reverse
(T... array) sample()
static <E> E
static <E> Set<E>
static <E> List<E>
static <E> Set<E>
static <T> ScheduledFuture
setInterval
(Supplier<T> function, int delayMilliseconds) private static void
setTemplateKey
(Map<String, String> templateSettings, String key) static <T> ScheduledFuture<T>
setTimeout
(Supplier<T> function, int delayMilliseconds) shift()
shuffle()
static <E> List<E>
static <E> E
singleOrNull
(Iterable<E> iterable) static <E> E
singleOrNull
(Iterable<E> iterable, Predicate<E> pred) singleOrNull
(Predicate<T> pred) int
size()
static <E> int
size
(E... array) static int
slice
(int start) slice
(int start, int end) static <T> List<T>
static <T> List<T>
static <T> T[]
slice
(T[] array, int start) static <T> T[]
slice
(T[] array, int start, int end) static <E> boolean
boolean
sort()
static <T extends Comparable<T>>
List<T>static <T extends Comparable<T>>
T[]sort
(T... array) static <E,
T extends Comparable<? super T>>
List<E>static <K,
V extends Comparable<? super V>>
List<Map<K,V>> <E,
V extends Comparable<? super V>>
List<E>static <E extends Comparable<E>>
intsortedIndex
(E[] array, E value) static <E extends Comparable<E>>
intsortedIndex
(E[] array, E value, String propertyName) static <E extends Comparable<E>>
intsortedIndex
(List<E> list, E value) static <E extends Comparable<E>>
intsortedIndex
(List<E> list, E value, String propertyName) static <T extends Comparable<? super T>>
List<T>sortWith
(Iterable<T> iterable, Comparator<T> comparator) <E extends Comparable<? super E>>
List<E>sortWith
(Comparator<E> comparator) splitAt
(int position) splitAt
(T[] array, int position) tail()
tail
(int n) static <E> E[]
tail
(E... array) static <E> E[]
tail
(E[] array, int n) static <E> List<E>
static <E> List<E>
takeSkipping
(int stepSize) static <T> List<T>
takeSkipping
(Iterable<T> iterable, int stepSize) static <T> List<T>
takeSkipping
(T[] array, int stepSize) static <T> void
static <K,
V> Underscore.Template<Map<K, V>> static void
templateSettings
(Map<String, String> templateSettings) static <T> Supplier<T>
static void
<E> E[]
toArray()
static <E> E[]
toCardinalityMap
(Iterable<K> iterable) <K,
V> Map<K, V> toMap()
static <K,
V> Map<K, V> static <K,
V> Map<K, V> static String
static <E> E[]
union
(E[]... arrays) static <E> List<E>
static <E> E[]
uniq
(E... array) static <K,
E> E[] static <K,
E> Collection<E> static <E> List<E>
static String
static String
static <T> List<T>
value()
static <K,
V> Collection<V> static <T,
E> List<E> static <T,
E> Set<E> static <E> E[]
without
(E[] array, E... values) static <E> List<E>
wrap
(UnaryOperator<T> function, Function<UnaryOperator<T>, T> wrapper)
-
Field Details
-
FUNCTIONS
-
TEMPLATE_SETTINGS
-
MIN_PASSWORD_LENGTH_8
private static final int MIN_PASSWORD_LENGTH_8- See Also:
-
CAPACITY_SIZE_5
private static final long CAPACITY_SIZE_5- See Also:
-
CAPACITY_COEFF_2
private static final long CAPACITY_COEFF_2- See Also:
-
CAPACITY_SIZE_16
private static final long CAPACITY_SIZE_16- See Also:
-
UNIQUE_ID
-
ALL_SYMBOLS
- See Also:
-
EVALUATE
- See Also:
-
INTERPOLATE
- See Also:
-
ESCAPE
- See Also:
-
S_Q
- See Also:
-
E_S
- See Also:
-
FORMAT_PATTERN
-
ESCAPES
-
iterable
-
string
-
-
Constructor Details
-
Underscore
-
Underscore
-
-
Method Details
-
setTemplateKey
-
templateSettings
-
iteratee
-
each
-
eachIndexed
-
each
-
eachRight
-
eachRight
-
forEach
-
forEachIndexed
-
forEach
-
forEachIndexed
-
forEachRight
-
forEachRight
-
map
-
mapMulti
public static <T,E> List<T> mapMulti(List<E> list, BiConsumer<? super E, ? super Consumer<T>> mapper) -
map
-
map
-
map
-
mapIndexed
-
replace
-
replace
-
replaceIndexed
public static <T> List<T> replaceIndexed(Iterable<T> iter, Underscore.PredicateIndexed<T> pred, T value) -
replaceIndexed
-
mapIndexed
-
collect
-
collect
-
reduce
-
reduce
-
reduce
-
reduce
-
foldl
-
inject
-
reduceRight
-
reduceRight
-
reduceRight
-
reduceRight
-
foldr
-
find
-
detect
-
findLast
-
filter
-
filter
-
filter
-
filterIndexed
-
filter
-
select
-
select
-
reject
-
reject
-
rejectIndexed
-
reject
-
filterFalse
-
filterFalse
-
filterFalse
-
every
-
every
-
all
-
all
-
some
-
some
-
any
-
any
-
count
-
count
-
contains
-
contains
-
containsWith
-
containsWith
-
contains
-
containsAtLeast
-
containsAtMost
-
containsAtLeast
-
containsAtMost
-
include
-
invoke
-
doInvoke
-
invoke
-
invoke
-
invoke
-
pluck
-
pluck
-
pluck
-
where
-
where
-
where
-
findWhere
-
findWhere
-
max
-
max
-
max
-
max
-
min
-
min
-
min
-
min
-
shuffle
-
shuffle
-
sample
-
sample
-
sample
-
sortWith
public static <T extends Comparable<? super T>> List<T> sortWith(Iterable<T> iterable, Comparator<T> comparator) -
sortWith
-
sortBy
public static <E,T extends Comparable<? super T>> List<E> sortBy(Iterable<E> iterable, Function<E, T> func) -
sortBy
-
sortBy
public static <K,V extends Comparable<? super V>> List<Map<K,V>> sortBy(Iterable<Map<K, V>> iterable, K key) -
groupBy
-
groupBy
-
groupBy
public static <K,E> Map<K,Optional<E>> groupBy(Iterable<E> iterable, Function<E, K> func, BinaryOperator<E> binaryOperator) -
groupBy
-
associateBy
-
associateBy
-
indexBy
-
indexBy
-
countBy
-
countBy
-
countBy
-
countBy
-
toArray
-
toArray
public <E> E[] toArray() -
toMap
-
toMap
-
toMap
-
toCardinalityMap
-
toCardinalityMap
-
size
-
size
public int size() -
size
public static <E> int size(E... array) -
partition
-
partition
-
singleOrNull
-
singleOrNull
-
singleOrNull
-
singleOrNull
-
first
-
first
public static <E> E first(E... array) -
first
-
first
-
first
-
first
-
first
-
first
-
first
-
firstOrNull
-
firstOrNull
-
firstOrNull
-
firstOrNull
-
head
-
head
public static <E> E head(E... array) -
head
-
head
-
head
-
initial
-
initial
-
initial
public static <E> E[] initial(E... array) -
initial
public static <E> E[] initial(E[] array, int n) -
initial
-
initial
-
last
public static <E> E last(E... array) -
last
-
last
-
last
-
last
-
last
-
last
-
lastOrNull
-
lastOrNull
-
lastOrNull
-
lastOrNull
-
rest
-
rest
-
rest
public static <E> E[] rest(E... array) -
rest
public static <E> E[] rest(E[] array, int n) -
rest
-
rest
-
tail
-
tail
-
tail
public static <E> E[] tail(E... array) -
tail
public static <E> E[] tail(E[] array, int n) -
tail
-
tail
-
drop
-
drop
-
drop
public static <E> E[] drop(E... array) -
drop
public static <E> E[] drop(E[] array, int n) -
compact
-
compact
public static <E> E[] compact(E... array) -
compactList
-
compact
public static <E> E[] compact(E[] array, E falsyValue) -
compact
-
compact
-
flatten
-
flatten
-
flatten
-
flatten
-
flatten
-
without
-
without
public static <E> E[] without(E[] array, E... values) -
uniq
-
uniq
public static <E> E[] uniq(E... array) -
uniq
-
uniq
-
distinct
-
distinct
public static <E> E[] distinct(E... array) -
distinctBy
-
distinctBy
-
union
-
unionWith
-
union
public static <E> E[] union(E[]... arrays) -
intersection
-
intersection
-
intersectionWith
-
intersection
public static <E> E[] intersection(E[]... arrays) -
difference
-
difference
-
differenceWith
-
difference
public static <E> E[] difference(E[]... arrays) -
zip
-
unzip
-
object
-
findIndex
-
findIndex
-
findLastIndex
-
findLastIndex
-
binarySearch
-
binarySearch
-
sortedIndex
-
sortedIndex
-
sortedIndex
-
sortedIndex
-
indexOf
-
indexOf
public static <E> int indexOf(E[] array, E value) -
lastIndexOf
-
lastIndexOf
public static <E> int lastIndexOf(E[] array, E value) -
range
-
range
-
range
-
range
-
range
-
range
-
chunk
-
chunk
-
chunkFill
-
chunkFill
-
chunk
-
chunk
-
chunkFill
-
chunkFill
-
cycle
-
cycle
-
repeat
-
interpose
-
interposeByList
-
interpose
-
interposeByList
-
bind
-
memoize
-
delay
-
defer
-
defer
-
throttle
-
debounce
-
wrap
public static <T> Function<Void,T> wrap(UnaryOperator<T> function, Function<UnaryOperator<T>, T> wrapper) -
negate
-
compose
-
after
-
before
-
once
-
keys
-
values
-
mapObject
-
pairs
-
invert
-
functions
-
methods
-
extend
-
findKey
-
findKey
-
findLastKey
-
findLastKey
-
pick
-
pick
-
omit
-
omit
-
defaults
-
clone
-
clone
public static <E> E[] clone(E... iterable) -
tap
-
isMatch
-
isEqual
-
isEmpty
-
isEmpty
-
isEmpty
public boolean isEmpty() -
isNotEmpty
-
isNotEmpty
-
isNotEmpty
public boolean isNotEmpty() -
isArray
-
isObject
-
isFunction
-
isString
-
isNumber
-
isDate
-
isRegExp
-
isError
-
isBoolean
-
isNull
-
has
-
identity
public static <E> E identity(E value) -
constant
-
property
-
propertyOf
-
matcher
-
times
-
random
public static int random(int min, int max) -
random
public static int random(int max) -
now
public static long now() -
escape
-
unescape
-
result
-
uniqueId
-
uniquePassword
-
template
-
format
-
iterate
-
chain
-
chain
-
chain
-
chain
-
chain
-
chain
-
chain
-
of
-
of
-
of
-
of
-
of
-
of
-
mixin
-
call
-
sort
-
sort
-
sort
-
join
-
joinToString
-
joinToStringPostfix
private static void joinToStringPostfix(String postfix, int limit, String truncated, int index, StringBuilder sb) -
join
-
join
-
join
-
join
-
join
-
push
-
push
-
pop
-
pop
-
unshift
-
unshift
-
shift
-
shift
-
concat
public static <T> T[] concat(T[] first, T[]... other) -
concat
-
concatWith
-
slice
-
slice
public static <T> T[] slice(T[] array, int start) -
slice
-
slice
-
slice
public static <T> T[] slice(T[] array, int start, int end) -
slice
-
splitAt
-
splitAt
-
splitAt
-
takeSkipping
-
takeSkipping
-
takeSkipping
-
reverse
-
reverse
public static <T> T[] reverse(T... array) -
reverse
-
reverse
-
getIterable
-
value
-
getString
-
setTimeout
-
clearTimeout
-
setInterval
-
clearInterval
-
copyOf
-
copyOf
-
copyOfRange
-
copyOfRange
-
elementAt
-
elementAt
-
get
-
get
-
set
-
set
-
elementAtOrElse
-
elementAtOrElse
-
elementAtOrNull
-
elementAtOrNull
-
lastIndex
-
lastIndex
public static <T> int lastIndex(T[] array) -
lastIndex
public static int lastIndex(int[] array) -
checkNotNull
public static <T> T checkNotNull(T reference) -
checkNotNullElements
-
checkNotNull
-
nonNull
-
defaultTo
public static <T> T defaultTo(T value, T defaultValue) -
newArrayList
-
newArrayList
-
newArrayList
-
newIntegerList
-
newArrayListWithExpectedSize
-
newLinkedHashSet
-
newLinkedHashSetWithExpectedSize
-
and
-
or
-
main
-