本文整理了Java中io.vavr.collection.Vector.length()
方法的一些代码示例,展示了Vector.length()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.length()
方法的具体详情如下:
包路径:io.vavr.collection.Vector
类名称:Vector
方法名:length
暂无
代码示例来源:origin: vavr-io/vavr
@Override
public int lastIndexOf(T element, int end) {
for (int i = Math.min(end, length() - 1); i >= 0; i--) {
if (Objects.equals(get(i), element)) {
return i;
}
}
return -1;
}
代码示例来源:origin: vavr-io/vavr
@Override
public Vector<T> subSequence(int beginIndex) {
if ((beginIndex >= 0) && (beginIndex <= length())) {
return drop(beginIndex);
} else {
throw new IndexOutOfBoundsException("subSequence(" + beginIndex + ")");
}
}
代码示例来源:origin: vavr-io/vavr
@Override
public <U> Vector<T> distinctBy(Function<? super T, ? extends U> keyExtractor) {
Objects.requireNonNull(keyExtractor, "keyExtractor is null");
final java.util.Set<U> seen = new java.util.HashSet<>(length());
return filter(t -> seen.add(keyExtractor.apply(t)));
}
代码示例来源:origin: vavr-io/vavr
@Override
public int indexOf(T element, int from) {
for (int i = from; i < length(); i++) {
if (Objects.equals(get(i), element)) {
return i;
}
}
return -1;
}
代码示例来源:origin: vavr-io/vavr
@Override
public Vector<T> takeRight(int n) {
return drop(length() - n);
}
代码示例来源:origin: vavr-io/vavr
@Override
public Vector<T> dropRight(int n) {
return take(length() - n);
}
代码示例来源:origin: vavr-io/vavr
@Override
public Vector<T> removeFirst(Predicate<T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
for (int i = 0; i < length(); i++) {
if (predicate.test(get(i))) {
return removeAt(i);
}
}
return this;
}
代码示例来源:origin: vavr-io/vavr
@Override
public Vector<T> leftPadTo(int length, T element) {
if (length <= length()) {
return this;
} else {
final Iterator<T> prefix = Iterator.continually(element).take(length - length());
return prependAll(prefix);
}
}
代码示例来源:origin: vavr-io/vavr
@Override
public Vector<T> removeLast(Predicate<T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
for (int i = length() - 1; i >= 0; i--) {
if (predicate.test(get(i))) {
return removeAt(i);
}
}
return this;
}
代码示例来源:origin: vavr-io/vavr
@Override
public Vector<T> remove(T element) {
for (int i = 0; i < length(); i++) {
if (Objects.equals(get(i), element)) {
return removeAt(i);
}
}
return this;
}
代码示例来源:origin: vavr-io/vavr
@Override
public Tuple2<Vector<T>, Vector<T>> partition(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
final ArrayList<T> left = new ArrayList<>(), right = new ArrayList<>();
for (int i = 0; i < length(); i++) {
final T t = get(i);
(predicate.test(t) ? left : right).add(t);
}
return Tuple.of(ofAll(left), ofAll(right));
}
代码示例来源:origin: vavr-io/vavr
@Override
public Vector<T> reverse() {
return (length() <= 1) ? this : ofAll(reverseIterator());
}
代码示例来源:origin: vavr-io/vavr
@Override
public Vector<T> subSequence(int beginIndex, int endIndex) {
Collections.subSequenceRangeCheck(beginIndex, endIndex, length());
return slice(beginIndex, endIndex);
}
代码示例来源:origin: vavr-io/vavr
@Override
public Vector<Vector<T>> combinations() { return rangeClosed(0, length()).map(this::combinations).flatMap(Function.identity()); }
代码示例来源:origin: vavr-io/vavr
@Override
public Vector<T> insertAll(int index, Iterable<? extends T> elements) {
Objects.requireNonNull(elements, "elements is null");
if ((index >= 0) && (index <= length())) {
final Vector<T> begin = take(index).appendAll(elements);
final Vector<T> end = drop(index);
return (begin.size() > end.size())
? begin.appendAll(end)
: end.prependAll(begin);
} else {
throw new IndexOutOfBoundsException("insert(" + index + ", e) on Vector of length " + length());
}
}
代码示例来源:origin: vavr-io/vavr
@Override
public Vector<T> padTo(int length, T element) {
final int actualLength = length();
return (length <= actualLength)
? this
: appendAll(Iterator.continually(element)
.take(length - actualLength));
}
代码示例来源:origin: vavr-io/vavr
@Override
public Tuple2<Vector<T>, Vector<T>> splitAtInclusive(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
for (int i = 0; i < length(); i++) {
final T value = get(i);
if (predicate.test(value)) {
return (i == (length() - 1)) ? Tuple.of(this, empty())
: Tuple.of(take(i + 1), drop(i + 1));
}
}
return Tuple.of(this, empty());
}
代码示例来源:origin: vavr-io/vavr
@Override
public <T1, T2> Tuple2<Vector<T1>, Vector<T2>> unzip(Function<? super T, Tuple2<? extends T1, ? extends T2>> unzipper) {
Objects.requireNonNull(unzipper, "unzipper is null");
Vector<T1> xs = empty();
Vector<T2> ys = empty();
for (int i = 0; i < length(); i++) {
final Tuple2<? extends T1, ? extends T2> t = unzipper.apply(get(i));
xs = xs.append(t._1);
ys = ys.append(t._2);
}
return Tuple.of(xs, ys);
}
代码示例来源:origin: vavr-io/vavr
@Override
public <T1, T2, T3> Tuple3<Vector<T1>, Vector<T2>, Vector<T3>> unzip3(Function<? super T, Tuple3<? extends T1, ? extends T2, ? extends T3>> unzipper) {
Objects.requireNonNull(unzipper, "unzipper is null");
Vector<T1> xs = empty();
Vector<T2> ys = empty();
Vector<T3> zs = empty();
for (int i = 0; i < length(); i++) {
final Tuple3<? extends T1, ? extends T2, ? extends T3> t = unzipper.apply(get(i));
xs = xs.append(t._1);
ys = ys.append(t._2);
zs = zs.append(t._3);
}
return Tuple.of(xs, ys, zs);
}
代码示例来源:origin: vavr-io/vavr
@Override
public Vector<T> slice(int beginIndex, int endIndex) {
if ((beginIndex >= endIndex) || (beginIndex >= size()) || isEmpty()) {
return empty();
} else if ((beginIndex <= 0) && (endIndex >= length())) {
return this;
} else {
return take(endIndex).drop(beginIndex);
}
}
内容来源于网络,如有侵权,请联系作者删除!