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 void setReadTimeout(int timeout) { XApi.require(timeout >= 0, "Timeout cannot be negative"); this.readTimeout = timeout; }
@Nonnull public static <E> E requireNonNull(@Nonnull E object, @Nonnull String objectName) throws IllegalArgumentException { require(object != null, objectName + " cannot be null"); return object; }
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; }
@Override public synchronized void reset() throws IOException { XApi.require(markedChar >= 0, markedChar == INVALIDATED ? "Invalid mark" : "Reader not marked"); ensureOpen(); this.nextChar = markedChar; this.skipLF = markedSkipLF; }
public synchronized void directWrite(@Nonnull char[] array, int offset, int length) throws IOException { XApi.require(offset >= 0 && offset < array.length && length >= 0 && offset + length <= array.length, "Invalid offset/length: " + offset + '/' + length); ensureOpen(); handle.write(array, offset, length); }
public double nextDouble(double minValue, double maxValue) { XApi.require(minValue <= maxValue, "maxValue must be greater than minValue"); if (minValue == maxValue) { return minValue; } double bound = maxValue - minValue + 1.0D; double result = nextDouble(bound); return minValue + result; }
public long nextLong(long minValue, long maxValue) { XApi.require(minValue <= maxValue, "maxValue must be greater than minValue"); if (minValue == maxValue) { return minValue; } long bound = maxValue - minValue + 1; long result = nextLong(bound); return minValue + result; }
public EventMethod(@Nonnull Method method) { XApi.require(validate(method), "Method not acceptable (see EventMethod#validate)"); this.method = method; this.parameterType = method.getParameterTypes()[0]; }
public TextWriter(@Nonnull Writer writer, @Nullable Encoding encoding, int bufferSize) { super(writer); XApi.require(bufferSize > 0, "bufferSize must be greater than zero"); this.buffer = new char[bufferSize]; this.encoding = encoding != null ? encoding : Encoding.defaultEncoding(); this.handle = writer; this.nextIndex = 0; }
public void write(long data, int bitCount) throws IOException { XApi.require(bitCount <= 64, "bitCount must be equal or less than 64"); for (int i = 0; i < bitCount; i++) { write1(((data >> i) & 0x1) == 0x1); } }
public Password(@Nonnull SafeInt... data) throws IllegalArgumentException { this.data = data.clone(); for (SafeInt safeValue : this.data) { int value = safeValue.get(); XApi.require(value >= Character.MIN_VALUE && value <= Character.MAX_VALUE, "Out of range value \"" + value + "\""); } }
public synchronized void writeln(@Nonnull char[] array, int offset, int length) throws IOException { XApi.require(offset >= 0 && offset < array.length && length >= 0 && offset + length <= array.length, "Invalid offset/length: " + offset + '/' + length); write(array, offset, length); newLine(); }
@Nullable @Override public E get(int index) { XApi.require(index >= 0 && index < size(), "Invalid index " + index + "; outside of limits 0~" + (size() - 1)); return doGet(index); }
@Override public void set(int index, @Nullable E object) { XApi.require(index >= 0 && index < size(), "Invalid index " + index + "; outside of limits 0~" + (size() - 1)); doSet(index, object); }
@Nonnull default XList<E> subList(int offset, int length) { XApi.require(offset >= 0 && length >= 0 && offset + length <= size(), "Invalid offset/length: " + offset + '/' + length + " for list with size " + size()); XList<E> list = newInstance(); XListIterator<E> iterator = iterator(); iterator.skip(offset); while (length-- > 0 && iterator.hasNext()) { list.add(iterator.next()); } return list; }