Example usage for java.util Objects requireNonNull

List of usage examples for java.util Objects requireNonNull

Introduction

In this page you can find the example usage for java.util Objects requireNonNull.

Prototype

public static <T> T requireNonNull(T obj) 

Source Link

Document

Checks that the specified object reference is not null .

Usage

From source file:eu.itesla_project.modules.simulation.ImpactAnalysisTool.java

private static void writeCsv(Multimap<String, SecurityIndex> securityIndexesPerContingency, Path outputCsvFile)
        throws IOException {
    Objects.requireNonNull(outputCsvFile);
    try (BufferedWriter writer = Files.newBufferedWriter(outputCsvFile, StandardCharsets.UTF_8)) {
        writer.write("Contingency");
        for (SecurityIndexType securityIndexType : SecurityIndexType.values()) {
            writer.write(CSV_SEPARATOR);
            writer.write(securityIndexType.toString());
        }/*from   w ww. ja  va  2  s  .  com*/
        writer.newLine();

        for (Map.Entry<String, Collection<SecurityIndex>> entry : securityIndexesPerContingency.asMap()
                .entrySet()) {
            String contingencyId = entry.getKey();
            writer.write(contingencyId);
            for (String str : toRow(entry.getValue())) {
                writer.write(CSV_SEPARATOR);
                writer.write(str);
            }
            writer.newLine();
        }
    }
}

From source file:at.gridtec.lambda4j.function.bi.BiBooleanFunction.java

/**
 * Lifts a partial {@link BiBooleanFunction} into a total {@link BiBooleanFunction} that returns an {@link Optional}
 * result./*from   w w w. j  av a 2 s  .c  o m*/
 *
 * @param <R> The type of return value from the function
 * @param partial A function that is only defined for some values in its domain
 * @return A partial {@code BiBooleanFunction} lifted into a total {@code BiBooleanFunction} that returns an {@code
 * Optional} result.
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
static <R> BiBooleanFunction<Optional<R>> lift(@Nonnull final BiBooleanFunction<? extends R> partial) {
    Objects.requireNonNull(partial);
    return (value1, value2) -> Optional.ofNullable(partial.apply(value1, value2));
}

From source file:eu.itesla_project.modules.rules.CheckSecurityTool.java

private static void writeCsv2(Map<String, Map<SecurityIndexId, SecurityRuleCheckStatus>> checkStatusPerBaseCase,
        Path outputCsvFile) throws IOException {
    Objects.requireNonNull(outputCsvFile);

    Set<SecurityIndexId> securityIndexIds = new LinkedHashSet<>();
    for (Map<SecurityIndexId, SecurityRuleCheckStatus> checkStatus : checkStatusPerBaseCase.values()) {
        securityIndexIds.addAll(checkStatus.keySet());
    }//from  ww w .  ja v a  2s  .co m

    try (BufferedWriter writer = Files.newBufferedWriter(outputCsvFile, StandardCharsets.UTF_8)) {
        writer.write("Base case");
        for (SecurityIndexId securityIndexId : securityIndexIds) {
            writer.write(CSV_SEPARATOR);
            writer.write(securityIndexId.toString());
        }
        writer.newLine();

        for (Map.Entry<String, Map<SecurityIndexId, SecurityRuleCheckStatus>> entry : checkStatusPerBaseCase
                .entrySet()) {
            String baseCaseName = entry.getKey();
            writer.write(baseCaseName);

            Map<SecurityIndexId, SecurityRuleCheckStatus> checkStatus = entry.getValue();
            for (SecurityIndexId securityIndexId : securityIndexIds) {
                writer.write(CSV_SEPARATOR);
                SecurityRuleCheckStatus status = checkStatus.get(securityIndexId);
                writer.write(status.name());
            }

            writer.newLine();
        }
    }
}

From source file:io.coala.math3.Math3ProbabilityDistribution.java

@SafeVarargs
public static <T, S> Math3ProbabilityDistribution<T> of(final EnumeratedDistribution<T> dist, //final PseudoRandom stream,
        final S... args) {
    Objects.requireNonNull(dist);
    final Math3ProbabilityDistribution<T> result = new Math3ProbabilityDistribution<T>() {
        @Override/*from ww  w  . j av a2 s  . co  m*/
        public T draw() {
            return dist.sample();
        }
    };
    //      result.stream = stream;
    //      result.params = Arrays.asList( args );
    return result;
}

From source file:at.gridtec.lambda4j.function.tri.TriFunction.java

/**
 * Lifts a partial {@link TriFunction} into a total {@link TriFunction} that returns an {@link Optional} result.
 *
 * @param <T> The type of the first argument to the function
 * @param <U> The type of the second argument to the function
 * @param <V> The type of the third argument to the function
 * @param <R> The type of return value from the function
 * @param partial A function that is only defined for some values in its domain
 * @return A partial {@code TriFunction} lifted into a total {@code TriFunction} that returns an {@code Optional}
 * result./*  w  w w .jav a 2s.com*/
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
static <T, U, V, R> TriFunction<T, U, V, Optional<R>> lift(
        @Nonnull final TriFunction<? super T, ? super U, ? super V, ? extends R> partial) {
    Objects.requireNonNull(partial);
    return (t, u, v) -> Optional.ofNullable(partial.apply(t, u, v));
}

From source file:at.gridtec.lambda4j.function.bi.BiIntFunction.java

/**
 * Lifts a partial {@link BiIntFunction} into a total {@link BiIntFunction} that returns an {@link Optional} result.
 *
 * @param <R> The type of return value from the function
 * @param partial A function that is only defined for some values in its domain
 * @return A partial {@code BiIntFunction} lifted into a total {@code BiIntFunction} that returns an {@code
 * Optional} result./*  w ww .  j  av a 2 s  .co  m*/
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
static <R> BiIntFunction<Optional<R>> lift(@Nonnull final BiIntFunction<? extends R> partial) {
    Objects.requireNonNull(partial);
    return (value1, value2) -> Optional.ofNullable(partial.apply(value1, value2));
}

From source file:alfio.controller.api.SpecialPriceApiController.java

@RequestMapping("/events/{eventName}/categories/{categoryId}/send-codes")
public boolean sendCodes(@PathVariable("eventName") String eventName,
        @PathVariable("categoryId") int categoryId, @RequestBody List<SendCodeModification> codes,
        Principal principal) throws IOException {

    Validate.isTrue(StringUtils.isNotEmpty(eventName));
    Objects.requireNonNull(codes);
    Validate.isTrue(!codes.isEmpty(), "Collection of codes cannot be empty");
    specialPriceManager.sendCodeToAssignee(codes, eventName, categoryId, principal.getName());
    return true;/*from www . ja  va2 s . c o  m*/
}

From source file:org.eclipse.hono.messaging.ForwardingDownstreamAdapter.java

/**
 * Creates a new adapter instance for a sender factory.
 * /*from ww w  .  j  a  v a 2s  .  com*/
 * @param vertx The Vert.x instance to run on.
 * @param senderFactory The factory to use for creating new senders for downstream telemetry data.
 * @throws NullPointerException if any of the parameters is {@code null}.
 */
protected ForwardingDownstreamAdapter(final Vertx vertx, final SenderFactory senderFactory) {
    this.vertx = Objects.requireNonNull(vertx);
    this.senderFactory = Objects.requireNonNull(senderFactory);
}

From source file:at.gridtec.lambda4j.function.bi.BiLongFunction.java

/**
 * Lifts a partial {@link BiLongFunction} into a total {@link BiLongFunction} that returns an {@link Optional}
 * result./*w  w  w. ja  va 2  s  . c o  m*/
 *
 * @param <R> The type of return value from the function
 * @param partial A function that is only defined for some values in its domain
 * @return A partial {@code BiLongFunction} lifted into a total {@code BiLongFunction} that returns an {@code
 * Optional} result.
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
static <R> BiLongFunction<Optional<R>> lift(@Nonnull final BiLongFunction<? extends R> partial) {
    Objects.requireNonNull(partial);
    return (value1, value2) -> Optional.ofNullable(partial.apply(value1, value2));
}

From source file:at.gridtec.lambda4j.consumer.bi.BiConsumer2.java

/**
 * Creates a {@link BiConsumer2} which uses the {@code first} parameter of this one as argument for the given {@link
 * Consumer}.// w  w  w  . j  a v  a 2s. c  om
 *
 * @param <T> The type of the first argument to the consumer
 * @param <U> The type of the second argument to the consumer
 * @param consumer The consumer which accepts the {@code first} parameter of this one
 * @return Creates a {@code BiConsumer2} which uses the {@code first} parameter of this one as argument for the
 * given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
static <T, U> BiConsumer2<T, U> onlyFirst(@Nonnull final Consumer<? super T> consumer) {
    Objects.requireNonNull(consumer);
    return (t, u) -> consumer.accept(t);
}