com.github.andyshao.util.ByteArraySpliterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Gear Show documentation
Show all versions of Gear Show documentation
Enhance and formating the coding of JDK
The newest version!
package com.github.andyshao.util;
import java.util.Objects;
import java.util.Spliterator;
import java.util.function.Consumer;
import lombok.Builder;
/**
*
* Title:
* Descript:
* Copyright: Copryright(c) Nov 15, 2019
* Encoding: UNIX UTF-8
*
* @author Andy.Shao
*
*/
@Builder
public class ByteArraySpliterator implements Spliterator {
private final byte[] bs;
private int index;
private final int fence;
private final int characteristics;
@Override
public boolean tryAdvance(Consumer super Byte> action) {
Objects.requireNonNull(action);
if(this.index < this.fence) {
byte item = this.bs[this.index++];
action.accept(item);
return true;
}
return false;
}
@Override
public Spliterator trySplit() {
int mid = (this.index + this.fence) >>> 1, ol = this.index;
return (ol >= mid) ? null : new ByteArraySpliterator(bs, this.index = mid, ol, characteristics);
}
@Override
public long estimateSize() {
return this.fence - this.index;
}
@Override
public int characteristics() {
return this.characteristics;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy