本文整理了Java中io.vavr.collection.List.isEmpty()
方法的一些代码示例,展示了List.isEmpty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。List.isEmpty()
方法的具体详情如下:
包路径:io.vavr.collection.List
类名称:List
方法名:isEmpty
暂无
代码示例来源:origin: vavr-io/vavr
/**
* Returns the head element without modifying the List.
*
* @return the first element
* @throws java.util.NoSuchElementException if this List is empty
*/
default T peek() {
if (isEmpty()) {
throw new NoSuchElementException("peek of empty list");
}
return head();
}
代码示例来源:origin: vavr-io/vavr
@Override
default List<T> init() {
if (isEmpty()) {
throw new UnsupportedOperationException("init of empty list");
} else {
return dropRight(1);
}
}
代码示例来源:origin: vavr-io/vavr
/**
* Removes the head element from this List.
*
* @return the elements of this List without the head element
* @throws java.util.NoSuchElementException if this List is empty
*/
default List<T> pop() {
if (isEmpty()) {
throw new NoSuchElementException("pop of empty list");
}
return tail();
}
代码示例来源:origin: vavr-io/vavr
@Override
default List<T> orElse(Iterable<? extends T> other) {
return isEmpty() ? ofAll(other) : this;
}
代码示例来源:origin: vavr-io/vavr
@Override
default List<T> sorted(Comparator<? super T> comparator) {
Objects.requireNonNull(comparator, "comparator is null");
return isEmpty() ? this : toJavaStream().sorted(comparator).collect(collector());
}
代码示例来源:origin: vavr-io/vavr
private void drawAux(String indent, StringBuilder builder) {
builder.append(value);
for (io.vavr.collection.List<Node<T>> it = children; !it.isEmpty(); it = it.tail()) {
final boolean isLast = it.tail().isEmpty();
builder.append('\n')
.append(indent)
.append(isLast ? "└──" : "├──");
it.head().drawAux(indent + (isLast ? " " : "│ "), builder);
}
}
代码示例来源:origin: vavr-io/vavr
@Override
default List<T> dropWhile(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
List<T> list = this;
while (!list.isEmpty() && predicate.test(list.head())) {
list = list.tail();
}
return list;
}
代码示例来源:origin: vavr-io/vavr
@Override
default int lastIndexOf(T element, int end) {
int result = -1, index = 0;
for (List<T> list = this; index <= end && !list.isEmpty(); list = list.tail(), index++) {
if (Objects.equals(list.head(), element)) {
result = index;
}
}
return result;
}
代码示例来源:origin: vavr-io/vavr
@Override
default int indexOf(T element, int from) {
int index = 0;
for (List<T> list = this; !list.isEmpty(); list = list.tail(), index++) {
if (index >= from && Objects.equals(list.head(), element)) {
return index;
}
}
return -1;
}
代码示例来源:origin: vavr-io/vavr
/**
* Removes the head element from this List.
*
* @return a tuple containing the head element and the remaining elements of this List
* @throws java.util.NoSuchElementException if this List is empty
*/
default Tuple2<T, List<T>> pop2() {
if (isEmpty()) {
throw new NoSuchElementException("pop2 of empty list");
}
return Tuple.of(head(), tail());
}
代码示例来源:origin: vavr-io/vavr
/**
* Removes the head element from this List.
*
* @return {@code None} if this List is empty, otherwise a {@code Some} containing the elements of this List without the head element
*/
default Option<List<T>> popOption() {
return isEmpty() ? Option.none() : Option.some(pop());
}
代码示例来源:origin: vavr-io/vavr
@Override
default List<T> prependAll(Iterable<? extends T> elements) {
Objects.requireNonNull(elements, "elements is null");
return isEmpty() ? ofAll(elements) : ofAll(elements).reverse().foldLeft(this, List::prepend);
}
代码示例来源:origin: vavr-io/vavr
/**
* Returns the head element without modifying the List.
*
* @return {@code None} if this List is empty, otherwise a {@code Some} containing the head element
*/
default Option<T> peekOption() {
return isEmpty() ? Option.none() : Option.some(head());
}
代码示例来源:origin: vavr-io/vavr
static <T> Tuple2<List<T>, List<T>> splitByPredicateReversed(List<T> source, Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
List<T> init = Nil.instance();
List<T> tail = source;
while (!tail.isEmpty() && !predicate.test(tail.head())) {
init = init.prepend(tail.head());
tail = tail.tail();
}
return Tuple.of(init, tail);
}
}
代码示例来源:origin: vavr-io/vavr
@Override
public Queue<T> filter(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
final io.vavr.collection.List<T> filtered = toList().filter(predicate);
if (filtered.isEmpty()) {
return empty();
} else if (filtered.length() == length()) {
return this;
} else {
return ofAll(filtered);
}
}
代码示例来源:origin: vavr-io/vavr
@Override
public Queue<T> init() {
if (isEmpty()) {
throw new UnsupportedOperationException("init of empty " + stringPrefix());
} else if (rear.isEmpty()) {
return new Queue<>(front.init(), rear);
} else {
return new Queue<>(front, rear.tail());
}
}
代码示例来源:origin: vavr-io/vavr
@Override
default List<T> takeWhile(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
List<T> result = Nil.instance();
for (List<T> list = this; !list.isEmpty() && predicate.test(list.head()); list = list.tail()) {
result = result.prepend(list.head());
}
return result.length() == length() ? this : result.reverse();
}
代码示例来源:origin: vavr-io/vavr
/**
* Removes the head element from this List.
*
* @return {@code None} if this List is empty, otherwise {@code Some} {@code Tuple} containing the head element and the remaining elements of this List
*/
default Option<Tuple2<T, List<T>>> pop2Option() {
return isEmpty() ? Option.none() : Option.some(Tuple.of(head(), pop()));
}
代码示例来源:origin: vavr-io/vavr
@Override
public Queue<T> intersperse(T element) {
if (isEmpty()) {
return this;
} else if (rear.isEmpty()) {
return new Queue<>(front.intersperse(element), rear);
} else {
return new Queue<>(front.intersperse(element), rear.intersperse(element).append(element));
}
}
代码示例来源:origin: vavr-io/vavr
static <T> Stream<T> apply(io.vavr.collection.List<T> front, io.vavr.collection.List<T> rear, Stream<T> remaining) {
if (remaining.isEmpty()) {
return remaining;
} else if (front.isEmpty()) {
return apply(rear.reverse(), io.vavr.collection.List.empty(), remaining);
} else {
return Stream.cons(front.head(),
() -> apply(front.tail(), rear.prepend(remaining.head()), remaining.tail()));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!