public void setSaltRounds(int saltRounds) { XApi.require(saltRounds >= 4 && saltRounds <= 30, "Illegal salt rounds: " + saltRounds + "; expected to be between 4 and 30, inclusive"); this.saltRounds = saltRounds; } }
public static void require(boolean condition, @Nonnull String message) throws IllegalArgumentException { if (!condition) { raise(message); } }
public static void requireState(boolean condition, @Nonnull String message) throws IllegalStateException { if (!condition) { raiseState(message); } }
public final void load(@Nonnull Object... entries) throws IllegalArgumentException { XApi.require(entries.length % 2 == 0, "Values must consist of (key, value)..."); clear(); for (int i = 0; i < entries.length; i += 2) { XApi.requireNonNull(entries[i], "values[" + i + ']'); set(entries[i].toString(), entries[i + 1]); } }
@Nonnull public static <E> E requireStateNonNull(@Nonnull E object, @Nonnull String objectName) throws IllegalStateException { requireState(object != null, objectName + " cannot be null"); return object; } }
@Nonnull public byte[] getData() { XApi.requireState(lastOutput != null, "No OutputStream has been opened"); return lastOutput.toArray(); }
public void setReadTimeout(int timeout) { XApi.require(timeout >= 0, "Timeout cannot be negative"); this.readTimeout = timeout; }
@Override protected void write(@Nonnull OutputStream output) throws IOException { XApi.requireState(hasObject(), "No JSON object specified"); try (TextWriter writer = new TextWriter(output)) { writer.write(getObject()); } } }
public void setInitialBufferCapacity(int initialBufferCapacity) { XApi.require(initialBufferCapacity > 0, "initialBufferCapacity must be greater than zero"); this.initialBufferCapacity = initialBufferCapacity; } }
@Override public void seek(long position) throws IOException { XApi.require(position >= 0 && position < array.length, "Position out of array bounds"); this.position = (int) position; }
public Bytes(long bytes) { XApi.require(bytes >= 0L, "Byte amount cannot be negative"); this.bytes = bytes; }
public void setConnectTimeout(int timeout) { XApi.require(timeout >= 0, "Timeout cannot be negative"); this.connectTimeout = timeout; }
@SafeVarargs public ArrayIterator(int offset, int length, @Nonnull E... data) { XApi.require(offset >= 0 && length >= 0 && offset + length <= data.length, "Invalid offset/length"); this.data = data; this.length = length; this.offset = offset; }
@Nonnull public static <E> E requireNonNull(@Nonnull E object, @Nonnull String objectName) throws IllegalArgumentException { require(object != null, objectName + " cannot be null"); return object; }
@SafeVarargs public XArrayView(int offset, int length, @Nonnull E... data) { XApi.require(offset >= 0 && length >= 0 && offset + length <= data.length, "Invalid offset/length"); XApi.require(ArrayWorker.all(data, Objects::nonNull), "Array cannot have any null element"); this.data = data; this.length = length; this.offset = offset; }
public AssetFormat(@Nonnull String name, @Nonnull String... formats) { XApi.require(formats.length > 0, "At least one format is required"); this.formats = new XArrayView<>(formats); this.name = name; }
public float nextFloat(float minValue, float maxValue) { XApi.require(minValue <= maxValue, "maxValue must be greater than minValue"); if (minValue == maxValue) { return minValue; } float bound = maxValue - minValue + 1.0F; float result = nextFloat(bound); return minValue + result; }
public int nextInt(int minValue, int maxValue) { XApi.require(minValue <= maxValue, "maxValue must be greater than minValue"); if (minValue == maxValue) { return minValue; } int bound = maxValue - minValue + 1; int result = nextInt(bound); return minValue + result; }
@Override public synchronized void mark(int readAheadLimit) throws IOException { XApi.require(readAheadLimit >= 0, "readAheadLimit must be positive"); ensureOpen(); this.markedChar = nextChar; this.markedSkipLF = skipLF; this.readAheadLimit = readAheadLimit; }