Java Code Examples for java.util.Objects.requireNonNull()

The following are Jave code examples for showing how to use requireNonNull() of the java.util.Objects class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jdk8u-jdk   File: ReferencePipeline.java   View Source Code Vote up 10 votes
@Override
public final <R> Stream<R> flatMap(Function<? super P_OUT, ? extends Stream<? extends R>> mapper) {
    Objects.requireNonNull(mapper);
    // We can do better than this, by polling cancellationRequested when stream is infinite
    return new StatelessOp<P_OUT, R>(this, StreamShape.REFERENCE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<P_OUT> opWrapSink(int flags, Sink<R> sink) {
            return new Sink.ChainedReference<P_OUT, R>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(P_OUT u) {
                    try (Stream<? extends R> result = mapper.apply(u)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(downstream);
                    }
                }
            };
        }
    };
}
 
Example 2
Project: jdk8u-jdk   File: StreamSpliterators.java   View Source Code Vote up 6 votes
@Override
public void forEachRemaining(T_CONS action) {
    Objects.requireNonNull(action);

    if (sliceOrigin >= fence)
        return;

    if (index >= fence)
        return;

    if (index >= sliceOrigin && (index + s.estimateSize()) <= sliceFence) {
        // The spliterator is contained within the slice
        s.forEachRemaining(action);
        index = fence;
    } else {
        // The spliterator intersects with the slice
        while (sliceOrigin > index) {
            s.tryAdvance(emptyConsumer());
            index++;
        }
        // Traverse elements up to the fence
        for (;index < fence; index++) {
            s.tryAdvance(action);
        }
    }
}
 
Example 3
Project: powsybl-core   File: UcteNode.java   View Source Code Vote up 6 votes
public UcteNode(UcteNodeCode code, String geographicalName, UcteNodeStatus status, UcteNodeTypeCode typeCode,
                float voltageReference, float activeLoad, float reactiveLoad, float activePowerGeneration,
                float reactivePowerGeneration, float minimumPermissibleActivePowerGeneration,
                float maximumPermissibleActivePowerGeneration, float minimumPermissibleReactivePowerGeneration,
                float maximumPermissibleReactivePowerGeneration, float staticOfPrimaryControl,
                float nominalPowerPrimaryControl, float threePhaseShortCircuitPower, float xrRatio,
                UctePowerPlantType powerPlantType) {
    this.code = Objects.requireNonNull(code);
    this.geographicalName = geographicalName;
    this.status = Objects.requireNonNull(status);
    this.typeCode = Objects.requireNonNull(typeCode);
    this.voltageReference = voltageReference;
    this.activeLoad = activeLoad;
    this.reactiveLoad = reactiveLoad;
    this.activePowerGeneration = activePowerGeneration;
    this.reactivePowerGeneration = reactivePowerGeneration;
    this.minimumPermissibleActivePowerGeneration = minimumPermissibleActivePowerGeneration;
    this.maximumPermissibleActivePowerGeneration = maximumPermissibleActivePowerGeneration;
    this.minimumPermissibleReactivePowerGeneration = minimumPermissibleReactivePowerGeneration;
    this.maximumPermissibleReactivePowerGeneration = maximumPermissibleReactivePowerGeneration;
    this.staticOfPrimaryControl = staticOfPrimaryControl;
    this.nominalPowerPrimaryControl = nominalPowerPrimaryControl;
    this.threePhaseShortCircuitPower = threePhaseShortCircuitPower;
    this.xrRatio = xrRatio;
    this.powerPlantType = powerPlantType;
}
 
Example 4
Project: elasticsearch_my   File: SuggestBuilder.java   View Source Code Vote up 5 votes
/**
 * Adds an {@link org.elasticsearch.search.suggest.SuggestionBuilder} instance under a user defined name.
 * The order in which the <code>Suggestions</code> are added, is the same as in the response.
 * @throws IllegalArgumentException if two suggestions added have the same name
 */
public SuggestBuilder addSuggestion(String name, SuggestionBuilder<?> suggestion) {
    Objects.requireNonNull(name, "every suggestion needs a name");
    if (suggestions.get(name) == null) {
        suggestions.put(name, suggestion);
    } else {
        throw new IllegalArgumentException("already added another suggestion with name [" + name + "]");
    }
    return this;
}
 
Example 5
Project: light-session-4j   File: RedisSessionManager.java   View Source Code Vote up 5 votes
public RedisSessionManager(SessionConfig sessionConfig, SessionRepository sessionRepository){
Objects.requireNonNull(sessionConfig);
Objects.requireNonNull(sessionRepository);
this.sessionConfig=sessionConfig;
      this.sessionRepository=sessionRepository;

  }
 
Example 6
Project: elasticsearch_my   File: DateObjectValueSource.java   View Source Code Vote up 5 votes
DateObjectValueSource(IndexFieldData<?> indexFieldData, MultiValueMode multiValueMode, 
                      String methodName, ToIntFunction<ReadableDateTime> function) {
    super(indexFieldData, multiValueMode);

    Objects.requireNonNull(methodName);

    this.methodName = methodName;
    this.function = function;
}
 
Example 7
Project: PoiExcelExport2.0   File: CellValueUtil.java   View Source Code Vote up 5 votes
public static XSSFCell createCellIfNotPresent(XSSFRow row, int colIndex) {
	String message = "XSSFRow must not be null!";
	Objects.requireNonNull(row, () -> message);
	XSSFCell cell = row.getCell(colIndex);
	if (Objects.isNull(cell)) {
		cell = row.createCell(colIndex);
	}
	return cell;
}
 
Example 8
Project: shuffleboard   File: ListUtils.java   View Source Code Vote up 5 votes
/**
 * Replaces the elements in the list with values given by the supplier.
 *
 * @param replacementSupplier the supplier to use to get replacement values
 *
 * @throws IllegalStateException if no values were specified to be replaced with {@link #replace(T)}
 *                               or {@link #replace(Predicate)}
 */
public void with(Supplier<? extends T> replacementSupplier) {
  Objects.requireNonNull(replacementSupplier, "replacementSupplier");
  if (test.equals(ALWAYS_FALSE)) {
    throw new IllegalStateException("No values were specified to be replaced");
  }
  for (int i = 0; i < list.size(); i++) {
    if (test.test(list.get(i))) {
      list.set(i, replacementSupplier.get());
      if (strategy == Strategy.FIRST) {
        return;
      }
    }
  }
}
 
Example 9
Project: power-jambda   File: LambdaLoggerHelper.java   View Source Code Vote up 5 votes
public static void putThreadContext(AwsProxyRequest request, List<String> loggingHeaders) {
    List<String> availableLoggingHeaders = Objects.requireNonNull(loggingHeaders);
    Optional.ofNullable(request.getRequestContext())
        .map(ApiGatewayRequestContext::getIdentity)
        .map(ApiGatewayRequestIdentity::getSourceIp)
        .ifPresent(ip -> ThreadContext.put("sourceIp", ip));
    Optional.ofNullable(request.getHeaders())
        .ifPresent(headers -> availableLoggingHeaders.forEach(
            headerKey -> putIfNotNullValue(headerKey, headers.get(headerKey))));
}
 
Example 10
Project: wurmloch-crdt   File: RGA.java   View Source Code Vote up 5 votes
public RGA(String nodeId, String crdtId) {
    this.crdtId = Objects.requireNonNull(crdtId, "CrtdId must not be null");

    Objects.requireNonNull(nodeId, "NodeId must not be null");
    this.clock = new StrictVectorClock(nodeId);
    this.start = new Vertex<>(null, clock);
    this.vertices = HashMap.of(clock, start);
}
 
Example 11
Project: kafka-0.11.0.0-src-with-comment   File: KStreamImpl.java   View Source Code Vote up 5 votes
@Override
public void foreach(ForeachAction<? super K, ? super V> action) {
    Objects.requireNonNull(action, "action can't be null");
    String name = topology.newName(FOREACH_NAME);

    topology.addProcessor(name, new KStreamPeek<>(action, false), this.name);
}
 
Example 12
Project: Reactive4JavaFlow   File: SingleSchedulerService.java   View Source Code Vote up 5 votes
@Override
public AutoDisposable schedule(Runnable task, long delay, TimeUnit unit) {
    Objects.requireNonNull(task, "task == null");
    ScheduledExecutorService exec = (ScheduledExecutorService)EXEC.getAcquire(this);
    WorkerTask wt = new WorkerTask(task, null);
    try {
        Future<?> f = exec.schedule((Callable<Void>)wt, delay, unit);
        wt.setFutureNoCancel(f);
        return wt;
    } catch (RejectedExecutionException ex) {
        FolyamPlugins.onError(ex);
    }
    return REJECTED;
}
 
Example 13
Project: powsybl-core   File: ImportConfig.java   View Source Code Vote up 5 votes
public static ImportConfig load(PlatformConfig platformConfig) {
    Objects.requireNonNull(platformConfig);
    List<String> postProcessors;
    if (platformConfig.moduleExists("import")) {
        ModuleConfig config = platformConfig.getModuleConfig("import");
        postProcessors = config.getStringListProperty("postProcessors", DEFAULT_POST_PROCESSORS);
    } else {
        postProcessors = DEFAULT_POST_PROCESSORS;
    }
    return new ImportConfig(postProcessors);
}
 
Example 14
Project: Dayflower-Path-Tracer   File: ConvolutionKernel.java   View Source Code Vote up 4 votes
public ConvolutionKernel(final byte[] pixels, final int width, final int height) {
	this.pixels = Objects.requireNonNull(pixels, "pixels == null");
	this.pixelsCopy = pixels.clone();
	this.width = width;
	this.height = height;
}
 
Example 15
Project: buckaroo   File: URLUtils.java   View Source Code Vote up 4 votes
public static Optional<String> getExtension(final URL url) {

        Objects.requireNonNull(url, "url is null");

        final String file = url.getFile();

        if (file.contains(".")) {

            final String sub = file.substring(file.lastIndexOf('.') + 1);

            if (sub.length() == 0) {
                return Optional.empty();
            }

            if (sub.contains("?")) {
                return Optional.of(sub.substring(0, sub.indexOf('?')));
            }

            return Optional.of(sub);
        }

        return Optional.empty();
    }
 
Example 16
Project: bytes-java   File: BytesTransformer.java   View Source Code Vote up 4 votes
ConcatTransformer(byte[] secondArrays) {
    Objects.requireNonNull(secondArrays, "the second byte array must not be null");
    this.secondArray = secondArrays;
}
 
Example 17
Project: tenhou-visualizer   File: AnalyzeZipTask.java   View Source Code Vote up 4 votes
public AnalyzeZipTask(File selectedFile, ObservableList<MahjongScene> observableList) {
    this.selectedFile = Objects.requireNonNull(selectedFile);
    this.observableList = observableList;
}
 
Example 18
Project: Stargraph   File: QueryResponse.java   View Source Code Vote up 4 votes
public QueryResponse(InteractionMode interactionMode, String userQuery) {
    this.interactionMode = Objects.requireNonNull(interactionMode);
    this.userQuery = Objects.requireNonNull(userQuery);
}
 
Example 19
Project: JavaSDK   File: ServiceInvokerBuilder.java   View Source Code Vote up 2 votes
/**
 * Creates an instance for the specified credentials.
 * <p>
 * Call {@link ServiceInvoker#builder(Credentials)} to create an instance.
 *
 * @param credentials  the credentials to use for authentication
 */
ServiceInvokerBuilder(Credentials credentials) {
  this.credentials = Objects.requireNonNull(credentials, "credentials must not be null");
}
 
Example 20
Project: cereebro   File: CereebroSnitchMvcEndpoint.java   View Source Code Vote up 2 votes
/**
 * Snitch actuator Endpoint. Tells everything it knows about the host Spring
 * Boot application and its dependencies.
 * 
 * @param analyzer
 *            An application analyzer that will provide information about
 *            the application and its relationships.
 */
public CereebroSnitchMvcEndpoint(ApplicationAnalyzer analyzer) {
    super(DEFAULT_PATH, true, true);
    this.applicationAnalyzer = Objects.requireNonNull(analyzer, "Application analyzer required");
}