Annotate NotNull and Nullable
This commit is contained in:
parent
aa661c936c
commit
e4ba8dcd68
@ -3,6 +3,7 @@ package org.warp.commonutils.stream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Simple {@link InputStream} implementation that exposes currently
|
||||
@ -19,7 +20,7 @@ public class ByteBufferBackedInputStream extends InputStream {
|
||||
public int read() throws IOException { return _b.hasRemaining() ? (_b.get() & 0xFF) : -1; }
|
||||
|
||||
@Override
|
||||
public int read(byte[] bytes, int off, int len) throws IOException {
|
||||
public int read(byte @NotNull [] bytes, int off, int len) throws IOException {
|
||||
if (!_b.hasRemaining()) return -1;
|
||||
len = Math.min(len, _b.remaining());
|
||||
_b.get(bytes, off, len);
|
||||
|
@ -26,12 +26,12 @@ public class DataInputOutputImpl implements DataInputOutput {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFully(byte[] bytes) throws IOException {
|
||||
public void readFully(byte @NotNull [] bytes) throws IOException {
|
||||
in.readFully(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFully(byte[] bytes, int i, int i1) throws IOException {
|
||||
public void readFully(byte @NotNull [] bytes, int i, int i1) throws IOException {
|
||||
in.readFully(bytes, i, i1);
|
||||
}
|
||||
|
||||
@ -107,12 +107,12 @@ public class DataInputOutputImpl implements DataInputOutput {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] bytes) throws IOException {
|
||||
public void write(byte @NotNull [] bytes) throws IOException {
|
||||
out.write(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] bytes, int i, int i1) throws IOException {
|
||||
public void write(byte @NotNull [] bytes, int i, int i1) throws IOException {
|
||||
out.write(bytes, i, i1);
|
||||
}
|
||||
|
||||
|
@ -25,12 +25,12 @@ public class DataInputOutputStream extends DataOutputStream implements DataInput
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFully(byte[] bytes) throws IOException {
|
||||
public void readFully(byte @NotNull [] bytes) throws IOException {
|
||||
in.readFully(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFully(byte[] bytes, int i, int i1) throws IOException {
|
||||
public void readFully(byte @NotNull [] bytes, int i, int i1) throws IOException {
|
||||
in.readFully(bytes, i, i1);
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
package org.warp.commonutils.stream;
|
||||
|
||||
import java.io.DataInput;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A data input stream lets an application read primitive Java data
|
||||
@ -56,8 +57,8 @@ public class SafeDataInputStream extends SafeFilterInputStream implements DataIn
|
||||
/**
|
||||
* working arrays initialized on demand by readUTF
|
||||
*/
|
||||
private byte bytearr[] = new byte[80];
|
||||
private char chararr[] = new char[80];
|
||||
private byte[] bytearr = new byte[80];
|
||||
private char[] chararr = new char[80];
|
||||
|
||||
/**
|
||||
* Reads some number of bytes from the contained input stream and
|
||||
@ -93,7 +94,7 @@ public class SafeDataInputStream extends SafeFilterInputStream implements DataIn
|
||||
* @see SafeFilterInputStream#in
|
||||
* @see java.io.InputStream#read(byte[], int, int)
|
||||
*/
|
||||
public final int read(byte b[]) {
|
||||
public final int read(byte[] b) {
|
||||
return in.read(b, 0, b.length);
|
||||
}
|
||||
|
||||
@ -138,7 +139,7 @@ public class SafeDataInputStream extends SafeFilterInputStream implements DataIn
|
||||
* @see SafeFilterInputStream#in
|
||||
* @see java.io.InputStream#read(byte[], int, int)
|
||||
*/
|
||||
public final int read(byte b[], int off, int len) {
|
||||
public final int read(byte[] b, int off, int len) {
|
||||
return in.read(b, off, len);
|
||||
}
|
||||
|
||||
@ -154,7 +155,7 @@ public class SafeDataInputStream extends SafeFilterInputStream implements DataIn
|
||||
* @throws NullPointerException if {@code b} is {@code null}.
|
||||
* @see SafeFilterInputStream#in
|
||||
*/
|
||||
public final void readFully(byte b[]) {
|
||||
public final void readFully(byte @NotNull [] b) {
|
||||
readFully(b, 0, b.length);
|
||||
}
|
||||
|
||||
@ -175,7 +176,7 @@ public class SafeDataInputStream extends SafeFilterInputStream implements DataIn
|
||||
* {@code b.length - off}.
|
||||
* @see SafeFilterInputStream#in
|
||||
*/
|
||||
public final void readFully(byte b[], int off, int len) {
|
||||
public final void readFully(byte @NotNull [] b, int off, int len) {
|
||||
if (len < 0)
|
||||
throw new IndexOutOfBoundsException();
|
||||
int n = 0;
|
||||
@ -199,7 +200,7 @@ public class SafeDataInputStream extends SafeFilterInputStream implements DataIn
|
||||
*/
|
||||
public final int skipBytes(int n) {
|
||||
int total = 0;
|
||||
int cur = 0;
|
||||
int cur;
|
||||
|
||||
while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
|
||||
total += cur;
|
||||
@ -345,7 +346,7 @@ public class SafeDataInputStream extends SafeFilterInputStream implements DataIn
|
||||
return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
|
||||
}
|
||||
|
||||
private byte readBuffer[] = new byte[8];
|
||||
private final byte[] readBuffer = new byte[8];
|
||||
|
||||
/**
|
||||
* See the general contract of the {@code readLong}
|
||||
@ -405,7 +406,7 @@ public class SafeDataInputStream extends SafeFilterInputStream implements DataIn
|
||||
return Double.longBitsToDouble(readLong());
|
||||
}
|
||||
|
||||
private char lineBuffer[];
|
||||
private char[] lineBuffer;
|
||||
|
||||
/**
|
||||
* See the general contract of the {@code readLine}
|
||||
@ -435,7 +436,7 @@ public class SafeDataInputStream extends SafeFilterInputStream implements DataIn
|
||||
*/
|
||||
@Deprecated
|
||||
public final String readLine() {
|
||||
char buf[] = lineBuffer;
|
||||
char[] buf = lineBuffer;
|
||||
|
||||
if (buf == null) {
|
||||
buf = lineBuffer = new char[128];
|
||||
@ -489,7 +490,7 @@ public class SafeDataInputStream extends SafeFilterInputStream implements DataIn
|
||||
* @return a Unicode string.
|
||||
* @see SafeDataInputStream#readUTF(SafeDataInputStream)
|
||||
*/
|
||||
public final String readUTF() {
|
||||
public final @NotNull String readUTF() {
|
||||
return readUTF(this);
|
||||
}
|
||||
|
||||
@ -507,17 +508,16 @@ public class SafeDataInputStream extends SafeFilterInputStream implements DataIn
|
||||
* @return a Unicode string.
|
||||
* @see SafeDataInputStream#readUnsignedShort()
|
||||
*/
|
||||
public static final String readUTF(SafeDataInputStream in) {
|
||||
public static String readUTF(SafeDataInputStream in) {
|
||||
int utflen = in.readUnsignedShort();
|
||||
byte[] bytearr = null;
|
||||
char[] chararr = null;
|
||||
SafeDataInputStream dis = in;
|
||||
if (dis.bytearr.length < utflen){
|
||||
dis.bytearr = new byte[utflen*2];
|
||||
dis.chararr = new char[utflen*2];
|
||||
byte[] bytearr;
|
||||
char[] chararr;
|
||||
if (in.bytearr.length < utflen){
|
||||
in.bytearr = new byte[utflen*2];
|
||||
in.chararr = new char[utflen*2];
|
||||
}
|
||||
chararr = dis.chararr;
|
||||
bytearr = dis.bytearr;
|
||||
chararr = in.chararr;
|
||||
bytearr = in.bytearr;
|
||||
|
||||
int c, char2, char3;
|
||||
int count = 0;
|
||||
|
@ -4,6 +4,7 @@ import java.io.Closeable;
|
||||
import java.io.Flushable;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Objects;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This abstract class is the superclass of all classes representing
|
||||
@ -62,7 +63,7 @@ public abstract class SafeOutputStream extends OutputStream implements Closeable
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte b[], int off, int len) {
|
||||
public void write(byte @NotNull [] b, int off, int len) {
|
||||
Objects.checkFromIndexSize(off, len, b.length);
|
||||
ensureOpen();
|
||||
}
|
||||
@ -97,7 +98,7 @@ public abstract class SafeOutputStream extends OutputStream implements Closeable
|
||||
* @param b the data.
|
||||
* @see java.io.OutputStream#write(byte[], int, int)
|
||||
*/
|
||||
public void write(byte b[]) {
|
||||
public void write(byte @NotNull [] b) {
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
||||
@ -126,7 +127,7 @@ public abstract class SafeOutputStream extends OutputStream implements Closeable
|
||||
* @param off the start offset in the data.
|
||||
* @param len the number of bytes to write.
|
||||
*/
|
||||
public void write(byte b[], int off, int len) {
|
||||
public void write(byte[] b, int off, int len) {
|
||||
Objects.checkFromIndexSize(off, len, b.length);
|
||||
// len == 0 condition implicitly handled by loop bounds
|
||||
for (int i = 0 ; i < len ; i++) {
|
||||
|
@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class Bytes {
|
||||
public final byte[] data;
|
||||
|
||||
public Bytes(@NotNull byte[] data) {
|
||||
public Bytes(byte @NotNull[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
@ -48,13 +48,13 @@ public class FastUtilStackSetWrapper<T> implements StackSet<T>, Collection<T> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
public Object @NotNull [] toArray() {
|
||||
return linkedHashSet.toArray();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <T1> T1[] toArray(@NotNull T1[] a) {
|
||||
public <T1> T1 @NotNull [] toArray(@NotNull T1 @NotNull [] a) {
|
||||
//noinspection SuspiciousToArrayCall
|
||||
return linkedHashSet.toArray(a);
|
||||
}
|
||||
|
@ -49,13 +49,13 @@ public class FastUtilStackWrapper<T> implements Stack<T>, Collection<T> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
public Object @NotNull [] toArray() {
|
||||
return collection.toArray();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <T1> T1[] toArray(@NotNull T1[] a) {
|
||||
public <T1> T1 @NotNull [] toArray(@NotNull T1 @NotNull [] a) {
|
||||
//noinspection SuspiciousToArrayCall
|
||||
return collection.toArray(a);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public class FloatPriorityQueue<T> implements Queue<T> {
|
||||
private final Queue<ScoredValue<T>> internalQueue;
|
||||
|
||||
public static <T> FloatPriorityQueue<T> of() {
|
||||
return new FloatPriorityQueue<T>(0);
|
||||
return new FloatPriorityQueue<>(0);
|
||||
}
|
||||
|
||||
public static <T> FloatPriorityQueue<T> of(T value, float score) {
|
||||
@ -33,6 +33,7 @@ public class FloatPriorityQueue<T> implements Queue<T> {
|
||||
return pq;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> FloatPriorityQueue<T> of(ScoredValue<T>... values) {
|
||||
var pq = new FloatPriorityQueue<T>(values.length);
|
||||
for (ScoredValue<T> value : values) {
|
||||
@ -64,12 +65,12 @@ public class FloatPriorityQueue<T> implements Queue<T> {
|
||||
}
|
||||
|
||||
public static <T> FloatPriorityQueue<T> synchronize(FloatPriorityQueue<T> queue) {
|
||||
return new SynchronizedFloatPriorityQueue<T>(queue.contentValues, queue.internalQueue);
|
||||
return new SynchronizedFloatPriorityQueue<>(queue.contentValues, queue.internalQueue);
|
||||
}
|
||||
|
||||
public static <T> FloatPriorityQueue<T> synchronizedPq(int initialCapacity) {
|
||||
var pq = new FloatPriorityQueue<T>(initialCapacity);
|
||||
return new SynchronizedFloatPriorityQueue<T>(pq.contentValues, pq.internalQueue);
|
||||
return new SynchronizedFloatPriorityQueue<>(pq.contentValues, pq.internalQueue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -95,7 +96,7 @@ public class FloatPriorityQueue<T> implements Queue<T> {
|
||||
public Iterator<T> iterator() {
|
||||
assert contentValues.size() == internalQueue.size();
|
||||
var it = internalQueue.iterator();
|
||||
return new Iterator<T>() {
|
||||
return new Iterator<>() {
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
assert contentValues.size() == internalQueue.size();
|
||||
@ -120,14 +121,15 @@ public class FloatPriorityQueue<T> implements Queue<T> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
public Object @NotNull [] toArray() {
|
||||
assert contentValues.size() == internalQueue.size();
|
||||
return internalQueue.stream().map(FloatPriorityQueue::getValueOrNull).toArray(Object[]::new);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"SuspiciousToArrayCall", "unchecked"})
|
||||
@NotNull
|
||||
@Override
|
||||
public <T1> T1[] toArray(@NotNull T1[] a) {
|
||||
public <T1> T1 @NotNull [] toArray(@NotNull T1 @NotNull [] a) {
|
||||
assert contentValues.size() == internalQueue.size();
|
||||
return internalQueue
|
||||
.stream()
|
||||
@ -286,7 +288,7 @@ public class FloatPriorityQueue<T> implements Queue<T> {
|
||||
}
|
||||
|
||||
public <U extends T> FloatPriorityQueueView<U> view() {
|
||||
return new FloatPriorityQueueView<U>(this);
|
||||
return new FloatPriorityQueueView<>(this);
|
||||
}
|
||||
|
||||
private static class SynchronizedFloatPriorityQueue<T> extends FloatPriorityQueue<T> {
|
||||
@ -313,7 +315,7 @@ public class FloatPriorityQueue<T> implements Queue<T> {
|
||||
@Override
|
||||
public synchronized @NotNull Iterator<T> iterator() {
|
||||
var it = super.iterator();
|
||||
return new Iterator<T>() {
|
||||
return new Iterator<>() {
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
synchronized (SynchronizedFloatPriorityQueue.this) {
|
||||
@ -331,12 +333,13 @@ public class FloatPriorityQueue<T> implements Queue<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized @NotNull Object[] toArray() {
|
||||
public synchronized @NotNull Object @NotNull [] toArray() {
|
||||
return super.toArray();
|
||||
}
|
||||
|
||||
@SuppressWarnings("SuspiciousToArrayCall")
|
||||
@Override
|
||||
public synchronized <T1> @NotNull T1[] toArray(@NotNull T1[] a) {
|
||||
public synchronized <T1> @NotNull T1 @NotNull [] toArray(@NotNull T1 @NotNull [] a) {
|
||||
return super.toArray(a);
|
||||
}
|
||||
|
||||
@ -356,6 +359,7 @@ public class FloatPriorityQueue<T> implements Queue<T> {
|
||||
return super.addTop(t);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public synchronized boolean add(T t) {
|
||||
return super.add(t);
|
||||
|
@ -65,13 +65,13 @@ public class FloatPriorityQueueView<T> implements Queue<T> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
public Object @NotNull [] toArray() {
|
||||
return queue.toArray();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <T1> T1[] toArray(@NotNull T1[] a) {
|
||||
public <T1> T1 @NotNull [] toArray(@NotNull T1 @NotNull [] a) {
|
||||
//noinspection SuspiciousToArrayCall
|
||||
return queue.toArray(a);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class ImmutableLinkedSet<E> implements Set<E> {
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
var it = set.iterator();
|
||||
return new Iterator<E>() {
|
||||
return new Iterator<>() {
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return it.hasNext();
|
||||
@ -58,13 +58,13 @@ public class ImmutableLinkedSet<E> implements Set<E> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
public Object @NotNull [] toArray() {
|
||||
return set.toArray();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <T> T[] toArray(@NotNull T[] a) {
|
||||
public <T> T @NotNull [] toArray(@NotNull T @NotNull [] a) {
|
||||
//noinspection SuspiciousToArrayCall
|
||||
return set.toArray(a);
|
||||
}
|
||||
@ -118,7 +118,7 @@ public class ImmutableLinkedSet<E> implements Set<E> {
|
||||
@Override
|
||||
public Spliterator<E> spliterator() {
|
||||
var spl = set.spliterator();
|
||||
return new Spliterator<E>() {
|
||||
return new Spliterator<>() {
|
||||
@Override
|
||||
public boolean tryAdvance(Consumer<? super E> action) {
|
||||
return spl.tryAdvance(action);
|
||||
|
@ -21,6 +21,7 @@ import java.util.Locale;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A default {@link ThreadFactory} implementation that accepts the name prefix
|
||||
@ -65,7 +66,7 @@ public class ShortNamedThreadFactory implements ThreadFactory {
|
||||
* @see java.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
|
||||
*/
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
public Thread newThread(@NotNull Runnable r) {
|
||||
final Thread t = new Thread(group, r, String.format(Locale.ROOT, "%s-%d",
|
||||
this.threadNamePrefix, threadNumber.getAndIncrement()), 0);
|
||||
t.setDaemon(false);
|
||||
|
Loading…
Reference in New Issue
Block a user