Java Code Examples for java.util.Objects#requireNonNull()
The following examples show how to use
java.util.Objects#requireNonNull() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LongStream.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Returns an infinite sequential ordered {@code LongStream} produced by iterative * application of a function {@code f} to an initial element {@code seed}, * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)}, * {@code f(f(seed))}, etc. * * <p>The first element (position {@code 0}) in the {@code LongStream} will * be the provided {@code seed}. For {@code n > 0}, the element at position * {@code n}, will be the result of applying the function {@code f} to the * element at position {@code n - 1}. * * @param seed the initial element * @param f a function to be applied to the previous element to produce * a new element * @return a new sequential {@code LongStream} */ public static LongStream iterate(final long seed, final LongUnaryOperator f) { Objects.requireNonNull(f); final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() { long t = seed; @Override public boolean hasNext() { return true; } @Override public long nextLong() { long v = t; t = f.applyAsLong(t); return v; } }; return StreamSupport.longStream(Spliterators.spliteratorUnknownSize( iterator, Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false); }
Example 2
Source File: MojangAPIImpl.java From JMCCC with MIT License | 6 votes |
@Override public FormerName[] getNameHistory(final UUID uuid) throws AuthenticationException { Objects.requireNonNull(uuid); return invokeOperation(new Callable<FormerName[]>() { @Override public FormerName[] call() throws Exception { JSONArray response = requireJsonArray(requester.request("GET", api.nameHistory(uuid))); FormerName[] names = new FormerName[response.length()]; for (int i = 0; i < names.length; i++) { JSONObject entry = response.getJSONObject(i); String name = entry.getString("name"); Long changedToAt = entry.has("changedToAt") ? entry.getLong("changedToAt") : null; names[i] = new FormerName(name, changedToAt); } return names; } }); }
Example 3
Source File: AtlasGlossary.java From atlas with Apache License 2.0 | 6 votes |
@JsonIgnore @Override public void setAttribute(String attrName, String attrVal) { Objects.requireNonNull(attrName, "AtlasGlossary attribute name"); switch (attrName) { case "name": setName(attrVal); break; case "shortDescription": setShortDescription(attrVal); break; case "longDescription": setLongDescription(attrVal); break; case "language": setLanguage(attrVal); break; case "usage": setUsage(attrVal); break; default: throw new IllegalArgumentException("Invalid attribute '" + attrName + "' for object AtlasGlossary"); } }
Example 4
Source File: Connection.java From terracotta-platform with Apache License 2.0 | 5 votes |
public static Connection create(String logicalConnectionUid, Server server, Endpoint clientEndpoint) { Objects.requireNonNull(logicalConnectionUid); Objects.requireNonNull(server); Objects.requireNonNull(clientEndpoint); return new Connection( key(logicalConnectionUid, server, clientEndpoint), logicalConnectionUid, server, clientEndpoint); }
Example 5
Source File: DoublePipeline.java From Bytecoder with Apache License 2.0 | 5 votes |
@Override public final <R> R collect(Supplier<R> supplier, ObjDoubleConsumer<R> accumulator, BiConsumer<R, R> combiner) { Objects.requireNonNull(combiner); BinaryOperator<R> operator = (left, right) -> { combiner.accept(left, right); return left; }; return evaluate(ReduceOps.makeDouble(supplier, accumulator, operator)); }
Example 6
Source File: TorrentClientBuilder.java From bt with Apache License 2.0 | 5 votes |
/** * Set custom torrent file supplier * * @see #torrent(URL) * @since 1.4 */ @SuppressWarnings("unchecked") public B torrent(Supplier<Torrent> torrentSupplier) { this.torrentUrl = null; this.torrentSupplier = Objects.requireNonNull(torrentSupplier, "Missing torrent supplier"); this.magnetUri = null; return (B) this; }
Example 7
Source File: AbstractPipeline.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") final <P_IN> Sink<P_IN> wrapSink(Sink<E_OUT> sink) { Objects.requireNonNull(sink); for ( @SuppressWarnings("rawtypes") AbstractPipeline p=AbstractPipeline.this; p.depth > 0; p=p.previousStage) { sink = p.opWrapSink(p.previousStage.combinedFlags, sink); } return (Sink<P_IN>) sink; }
Example 8
Source File: DotGroups.java From pinpoint with Apache License 2.0 | 5 votes |
void addDot(Coordinates coordinates, Dot dot) { Objects.requireNonNull(dot, "dot"); Key key = new Key(coordinates, dot.getSimpleExceptionCode()); DotGroup dotGroup = dotGroupMap.get(key); if (dotGroup == null) { dotGroup = new DotGroup(coordinates); dotGroupMap.put(key, dotGroup); } dotGroup.addDot(dot); }
Example 9
Source File: Config.java From TerasologyLauncher with Apache License 2.0 | 5 votes |
public Config build() { Objects.requireNonNull(gameConfig, "gameConfig must not be null"); Objects.requireNonNull(locale, "locale must not be null"); Objects.requireNonNull(launcherDir, "launcherDir must not be null"); return new Config(this); }
Example 10
Source File: TableCodec.java From tikv-client-lib-java with Apache License 2.0 | 5 votes |
public static void tryDecodeRowKey(long tableId, byte[] rowKey, DecodeResult outResult) { Objects.requireNonNull(rowKey, "rowKey cannot be null"); if (rowKey.length == 0) { outResult.status = Status.UNKNOWN_INF; return; } CodecDataOutput cdo = new CodecDataOutput(); appendTableRecordPrefix(cdo, tableId); byte [] tablePrefix = cdo.toBytes(); int res = FastByteComparisons.compareTo( tablePrefix, 0, tablePrefix.length, rowKey, 0, Math.min(rowKey.length, tablePrefix.length)); if (res > 0) { outResult.status = Status.MIN; return; } if (res < 0) { outResult.status = Status.MAX; return; } CodecDataInput cdi = new CodecDataInput(rowKey); cdi.skipBytes(tablePrefix.length); if (cdi.available() == 8) { outResult.status = Status.EQUAL; } else if (cdi.available() < 8) { outResult.status = Status.LESS; } else if (cdi.available() > 8) { outResult.status = Status.GREATER; } outResult.handle = IntegerType.readPartialLong(cdi); }
Example 11
Source File: DefaultApplicationsMapCreator.java From pinpoint with Apache License 2.0 | 4 votes |
public DefaultApplicationsMapCreator(ApplicationMapCreator applicationMapCreator, Executor executor) { this.applicationMapCreator = Objects.requireNonNull(applicationMapCreator, "applicationMapCreator"); this.executor = Objects.requireNonNull(executor, "executor"); }
Example 12
Source File: EventBusConfigStoreFactory.java From vertx-config with Apache License 2.0 | 4 votes |
@Override public ConfigStore create(Vertx vertx, JsonObject configuration) { String address = configuration.getString("address"); Objects.requireNonNull(address); return new EventBusConfigStore(vertx, address); }
Example 13
Source File: HBaseSampledTotalThreadCountDaoV2.java From pinpoint with Apache License 2.0 | 4 votes |
public HBaseSampledTotalThreadCountDaoV2(HbaseAgentStatDaoOperationsV2 operations, TotalThreadCountDecoder totalThreadCountDecoder, TotalThreadCountSampler totalThreadCountSampler) { this.operations = Objects.requireNonNull(operations, "operations"); this.totalThreadCountDecoder = Objects.requireNonNull(totalThreadCountDecoder, "totalThreadCountDecoder"); this.totalThreadCountSampler = Objects.requireNonNull(totalThreadCountSampler, "totalThreadCountSampler"); }
Example 14
Source File: Sink.java From JDKSourceCode1.8 with MIT License | 4 votes |
public ChainedReference(Sink<? super E_OUT> downstream) { this.downstream = Objects.requireNonNull(downstream); }
Example 15
Source File: AbstractExtensionAdder.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
protected AbstractExtensionAdder(T extendable) { this.extendable = Objects.requireNonNull(extendable); }
Example 16
Source File: AnnotatedElement.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * Returns this element's annotation for the specified type if * such an annotation is <em>directly present</em>, else null. * * This method ignores inherited annotations. (Returns null if no * annotations are directly present on this element.) * * @implSpec The default implementation first performs a null check * and then loops over the results of {@link * #getDeclaredAnnotations} returning the first annotation whose * annotation type matches the argument type. * * @param <T> the type of the annotation to query for and return if directly present * @param annotationClass the Class object corresponding to the * annotation type * @return this element's annotation for the specified annotation type if * directly present on this element, else null * @throws NullPointerException if the given annotation class is null * @since 1.8 */ default <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) { Objects.requireNonNull(annotationClass); // Loop over all directly-present annotations looking for a matching one for (Annotation annotation : getDeclaredAnnotations()) { if (annotationClass.equals(annotation.annotationType())) { // More robust to do a dynamic cast at runtime instead // of compile-time only. return annotationClass.cast(annotation); } } return null; }
Example 17
Source File: LocalTime.java From Bytecoder with Apache License 2.0 | 3 votes |
/** * Obtains an instance of {@code LocalTime} from a temporal object. * <p> * This obtains a local time based on the specified temporal. * A {@code TemporalAccessor} represents an arbitrary set of date and time information, * which this factory converts to an instance of {@code LocalTime}. * <p> * The conversion uses the {@link TemporalQueries#localTime()} query, which relies * on extracting the {@link ChronoField#NANO_OF_DAY NANO_OF_DAY} field. * <p> * This method matches the signature of the functional interface {@link TemporalQuery} * allowing it to be used as a query via method reference, {@code LocalTime::from}. * * @param temporal the temporal object to convert, not null * @return the local time, not null * @throws DateTimeException if unable to convert to a {@code LocalTime} */ public static LocalTime from(TemporalAccessor temporal) { Objects.requireNonNull(temporal, "temporal"); LocalTime time = temporal.query(TemporalQueries.localTime()); if (time == null) { throw new DateTimeException("Unable to obtain LocalTime from TemporalAccessor: " + temporal + " of type " + temporal.getClass().getName()); } return time; }
Example 18
Source File: ConfigurationItemTO.java From openAGV with Apache License 2.0 | 2 votes |
/** * Sets this configuration item's key. * * @param key The new key. */ public void setKey(String key) { this.key = Objects.requireNonNull(key, "key is null"); }
Example 19
Source File: VoidIndexable.java From autorest-clientruntime-for-java with MIT License | 2 votes |
/** * Creates VoidIndexable. * * @param key the key. */ public VoidIndexable(String key) { Objects.requireNonNull(key); this.key = key; }
Example 20
Source File: Base64.java From bistoury with GNU General Public License v3.0 | 2 votes |
/** * Returns an input stream for decoding {@link Base64} encoded byte stream. * * <p> The {@code read} methods of the returned {@code InputStream} will * throw {@code IOException} when reading bytes that cannot be decoded. * * <p> Closing the returned input stream will close the underlying * input stream. * * @param is the input stream * @return the input stream for decoding the specified Base64 encoded * byte stream */ public InputStream wrap(InputStream is) { Objects.requireNonNull(is); return new DecInputStream(is, isURL ? fromBase64URL : fromBase64, isMIME); }