/** * Default constructor. * @param url The URL */ UrlReadable(URL url) { ArgumentUtils.requireNonNull("url", url); this.url = url; }
/** * Adds a check that the given number is positive. * * @param name The name of the argument * @param value The value * @throws IllegalArgumentException if the argument is not positive * @return The value */ public static @Nonnull Number requirePositive(String name, Number value) { requireNonNull(name, value); requirePositive(name, value.intValue()); return value; }
/** * Constructs a new event for the given data. * * @param data The data * @param <ET> The data type * @return The event instance */ static <ET> Event<ET> of(ET data) { ArgumentUtils.check("data", data).notNull(); return new DefaultEvent<>(data); }
/** * Creates a new decoder that decodes the specified URI encoded in the * specified charset. * * @param uri The URI * @param charset The charset to use * @param maxParams The maximum number of params */ QueryStringDecoder(URI uri, Charset charset, int maxParams) { String rawPath = uri.getRawPath(); if (rawPath == null) { rawPath = EMPTY_STRING; } String rawQuery = uri.getRawQuery(); // Also take care of cut of things like "http://localhost" this.uri = rawQuery == null ? rawPath : rawPath + '?' + rawQuery; this.charset = Objects.requireNonNull(charset, "charset"); this.maxParams = ArgumentUtils.requirePositive("maxParams", maxParams); pathEndIdx = rawPath.length(); }
/** * Finds an available TCP port. * * @param minPortRange The minimum port range * @param maxPortRange The maximum port range * @return The available port */ public static int findAvailableTcpPort(int minPortRange, int maxPortRange) { ArgumentUtils.check(() -> minPortRange > MIN_PORT_RANGE) .orElseFail("Port minimum value must be greater than " + MIN_PORT_RANGE); ArgumentUtils.check(() -> maxPortRange >= minPortRange) .orElseFail("Max port range must be greater than minimum port range"); ArgumentUtils.check(() -> maxPortRange <= MAX_PORT_RANGE) .orElseFail("Port maximum value must be less than " + MAX_PORT_RANGE); int currentPort = nextPort(minPortRange, maxPortRange); while (!isTcpPortAvailable(currentPort)) { currentPort = nextPort(minPortRange, maxPortRange); } return currentPort; }
/** * Creates a new decoder that decodes the specified URI encoded in the * specified charset. * * @param uri The URI * @param charset The charset to use * @param maxParams The maximum number of params */ QueryStringDecoder(URI uri, Charset charset, int maxParams) { String rawPath = uri.getRawPath(); if (rawPath == null) { rawPath = EMPTY_STRING; } String rawQuery = uri.getRawQuery(); // Also take care of cut of things like "http://localhost" this.uri = rawQuery == null ? rawPath : rawPath + '?' + rawQuery; this.charset = Objects.requireNonNull(charset, "charset"); this.maxParams = ArgumentUtils.requirePositive("maxParams", maxParams); pathEndIdx = rawPath.length(); }
EntryWeigherView(Weigher<? super V> weigher) { ArgumentUtils.requireNonNull("weigher", weigher); this.weigher = weigher; }
/** * Constructs a new event for the given data. * * @param event The event * @param data The data * @param <ET> The data type * @return The event instance */ static <ET> Event<ET> of(Event event, ET data) { ArgumentUtils.check("data", data).notNull(); return new DefaultEvent<>(data) .id(event.getId()) .comment(event.getComment()) .name(event.getName()) .retry(event.getRetry()); } }
/** * Default constructor. * @param file The file */ FileReadable(@Nonnull File file) { ArgumentUtils.requireNonNull("file", file); this.file = file; }
@Override public ScheduledFuture<?> scheduleWithFixedDelay(Duration initialDelay, Duration delay, Runnable command) { check("delay", delay).notNull(); check("command", command).notNull(); long initialDelayMillis = initialDelay != null ? initialDelay.toMillis() : 0; return executorService.scheduleWithFixedDelay( command, initialDelayMillis, delay.toMillis(), TimeUnit.MILLISECONDS ); }
/** * Variation of {@link #isAnnotationPresent(Class)} for declared annotations. * * @param annotationClass The annotation class * @return True if it is */ default boolean isDeclaredAnnotationPresent(@Nonnull Class<? extends Annotation> annotationClass) { ArgumentUtils.requireNonNull("annotationClass", annotationClass); return false; } }
/** * Return whether an annotation is present. * * @param annotationClass The annotation class * @return True if it is */ default boolean isAnnotationPresent(@Nonnull Class<? extends Annotation> annotationClass) { ArgumentUtils.requireNonNull("annotationClass", annotationClass); return false; }
/** * @param resourceLoaders The resouce loaders */ public ResourceResolver(@Nonnull List<ResourceLoader> resourceLoaders) { ArgumentUtils.requireNonNull("resourceLoaders", resourceLoaders); this.resourceLoaders = resourceLoaders; }
@Override public ScheduledFuture<?> scheduleAtFixedRate(Duration initialDelay, Duration period, Runnable command) { check("period", period).notNull(); check("command", command).notNull(); long initialDelayMillis = initialDelay != null ? initialDelay.toMillis() : 0; return executorService.scheduleAtFixedRate( command, initialDelayMillis, period.toMillis(), TimeUnit.MILLISECONDS ); }
/** * Synthesizes a new annotation from the metadata for the given annotation type. This method works * by creating a runtime proxy of the annotation interface and should be avoided in favour of * direct use of the annotation metadata and only used for unique cases that require integrating third party libraries. * * @param annotationClass The annotation class * @param <T> The annotation generic type * @return The annotation or null if it doesn't exist */ default @Nullable <T extends Annotation> T synthesize(@Nonnull Class<T> annotationClass) { ArgumentUtils.requireNonNull("annotationClass", annotationClass); return null; }
/** * Construct a {@link UserExecutorConfiguration} for the given {@link io.micronaut.scheduling.executor.ExecutorType}. * * @param type The type * @return The configuration */ public static UserExecutorConfiguration of(ExecutorType type) { ArgumentUtils.check("type", type).notNull(); UserExecutorConfiguration configuration = new UserExecutorConfiguration(); configuration.type = type; return configuration; }
/** * Find an {@link AnnotationValue} for the given annotation type. * * @param annotationClass The annotation * @param <T> The annotation type * @return A {@link AnnotationValue} instance */ default @Nonnull <T extends Annotation> Optional<AnnotationValue<T>> findAnnotation(@Nonnull Class<T> annotationClass) { ArgumentUtils.requireNonNull("annotationClass", annotationClass); return Optional.empty(); }
/** * Constructs a new event for the given data. * * @param data The data * @param <ET> The data type * @return The event instance */ static <ET> Event<ET> of(ET data) { ArgumentUtils.check("data", data).notNull(); return new DefaultEvent<>(data); }