CacheBuilder<K, V> setValueStrength(Strength strength) { checkState(valueStrength == null, "Value strength was already set to %s", valueStrength); valueStrength = checkNotNull(strength); return this; }
@Override protected void parseLong(CacheBuilderSpec spec, long value) { checkArgument(spec.maximumSize == null, "maximum size was already set to ", spec.maximumSize); checkArgument(spec.maximumWeight == null, "maximum weight was already set to ", spec.maximumWeight); spec.maximumSize = value; } }
private static String badPositionIndexes(int start, int end, int size) { if (start < 0 || start > size) { return badPositionIndex(start, size, "start index"); } if (end < 0 || end > size) { return badPositionIndex(end, size, "end index"); } // end < start return format("end index (%s) must not be less than start index (%s)", end, start); }
@Override public boolean addAll(int index, Collection<? extends V> elements) { checkNotNull(elements); checkPositionIndex(index, 0); throw new IllegalArgumentException("Key does not satisfy predicate: " + key); }
/** * @since 12.0 */ @GwtIncompatible("NavigableSet") @Override public ImmutableSortedSet<E> subSet( E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) { checkNotNull(fromElement); checkNotNull(toElement); checkArgument(comparator.compare(fromElement, toElement) <= 0); return subSetImpl(fromElement, fromInclusive, toElement, toInclusive); }
@Override public E get(int index) { Preconditions.checkElementIndex(index, 1); return element; }
@Override public void setSecurityContext(final SecurityContext context) { Preconditions.checkState(!inResponseProcessingPhase, ERROR_REQUEST_SET_SECURITY_CONTEXT_IN_RESPONSE_PHASE); this.securityContext = context; }
@Override public ImmutableList<Character> subList( int fromIndex, int toIndex) { checkPositionIndexes(fromIndex, toIndex, size()); // for GWT return charactersOf(string.substring(fromIndex, toIndex)); }
@Override public void add(int index, V element) { checkPositionIndex(index, 0); throw new IllegalArgumentException("Key does not satisfy predicate: " + key); }
/** * Creates a new instance of {@link DefaultBlockMaster}. * * @param metricsMaster the metrics master * @param masterContext the context for Alluxio master * @param clock the clock to use for determining the time * @param executorServiceFactory a factory for creating the executor service to use for running * maintenance threads */ DefaultBlockMaster(MetricsMaster metricsMaster, CoreMasterContext masterContext, Clock clock, ExecutorServiceFactory executorServiceFactory) { super(masterContext, clock, executorServiceFactory); Preconditions.checkNotNull(metricsMaster, "metricsMaster"); mBlockStore = masterContext.getBlockStoreFactory() .apply(new BlockStoreArgs(ServerConfiguration.global())); mGlobalStorageTierAssoc = new MasterStorageTierAssoc(); mMetricsMaster = metricsMaster; Metrics.registerGauges(this); }
private static String badPositionIndex(int index, int size, String desc) { if (index < 0) { return format("%s (%s) must not be negative", desc, index); } else if (size < 0) { throw new IllegalArgumentException("negative size: " + size); } else { // index > size return format("%s (%s) must not be greater than size (%s)", desc, index, size); } }
/** * Ensures that {@code index} specifies a valid <i>position</i> in an array, list or string of * size {@code size}. A position index may range from zero to {@code size}, inclusive. * * @param index a user-supplied index identifying a position in an array, list or string * @param size the size of that array, list or string * @param desc the text to use to describe this index in an error message * @return the value of {@code index} * @throws IndexOutOfBoundsException if {@code index} is negative or is greater than {@code size} * @throws IllegalArgumentException if {@code size} is negative */ public static int checkPositionIndex(int index, int size, @Nullable String desc) { // Carefully optimized for execution by hotspot (explanatory comment above) if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size, desc)); } return index; }
/** * Ensures that {@code start} and {@code end} specify a valid <i>positions</i> in an array, list * or string of size {@code size}, and are in order. A position index may range from zero to * {@code size}, inclusive. * * @param start a user-supplied index identifying a starting position in an array, list or string * @param end a user-supplied index identifying a ending position in an array, list or string * @param size the size of that array, list or string * @throws IndexOutOfBoundsException if either index is negative or is greater than {@code size}, * or if {@code end} is less than {@code start} * @throws IllegalArgumentException if {@code size} is negative */ public static void checkPositionIndexes(int start, int end, int size) { // Carefully optimized for execution by hotspot (explanatory comment above) if (start < 0 || end < start || end > size) { throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size)); } }
/** * Ensures that {@code index} specifies a valid <i>element</i> in an array, list or string of size * {@code size}. An element index may range from zero, inclusive, to {@code size}, exclusive. * * @param index a user-supplied index identifying an element of an array, list or string * @param size the size of that array, list or string * @param desc the text to use to describe this index in an error message * @return the value of {@code index} * @throws IndexOutOfBoundsException if {@code index} is negative or is not less than {@code size} * @throws IllegalArgumentException if {@code size} is negative */ public static int checkElementIndex( int index, int size, @Nullable String desc) { // Carefully optimized for execution by hotspot (explanatory comment above) if (index < 0 || index >= size) { throw new IndexOutOfBoundsException(badElementIndex(index, size, desc)); } return index; }
/** * @since 12.0 */ @GwtIncompatible("NavigableSet") @Override public ImmutableSortedSet<E> subSet( E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) { checkNotNull(fromElement); checkNotNull(toElement); checkArgument(comparator.compare(fromElement, toElement) <= 0); return subSetImpl(fromElement, fromInclusive, toElement, toInclusive); }
@Override public boolean addAll(int index, Collection<? extends V> elements) { checkNotNull(elements); checkPositionIndex(index, 0); throw new IllegalArgumentException("Key does not satisfy predicate: " + key); }
@Override public E get(int index) { Preconditions.checkElementIndex(index, 1); return element; }
@Override public void abortWith(final Response response) { Preconditions.checkState(!inResponseProcessingPhase, ERROR_REQUEST_ABORT_IN_RESPONSE_PHASE); this.abortResponse = response; }
@Override public ImmutableList<Character> subList( int fromIndex, int toIndex) { checkPositionIndexes(fromIndex, toIndex, size()); // for GWT return charactersOf(string.substring(fromIndex, toIndex)); }
@Override public void add(int index, V element) { checkPositionIndex(index, 0); throw new IllegalArgumentException("Key does not satisfy predicate: " + key); }