java.util.Objects#requireNonNull ( )源码实例Demo

下面列出了java.util.Objects#requireNonNull ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: LongStream.java
/**
 * 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);
}
 
源代码2 项目: JMCCC   文件: MojangAPIImpl.java
@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;
		}
	});
}
 
源代码3 项目: atlas   文件: AtlasGlossary.java
@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");
    }
}
 
源代码4 项目: terracotta-platform   文件: Connection.java
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);
}
 
源代码5 项目: Bytecoder   文件: DoublePipeline.java
@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));
}
 
源代码6 项目: bt   文件: TorrentClientBuilder.java
/**
 * 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;
}
 
源代码7 项目: openjdk-jdk8u   文件: AbstractPipeline.java
@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;
}
 
源代码8 项目: TerasologyLauncher   文件: Config.java
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);
}
 
源代码9 项目: tikv-client-lib-java   文件: TableCodec.java
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);
}
 
源代码10 项目: pinpoint   文件: DotGroups.java
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);
}
 
源代码11 项目: powsybl-core   文件: AbstractExtensionAdder.java
protected AbstractExtensionAdder(T extendable) {
    this.extendable = Objects.requireNonNull(extendable);
}
 
源代码12 项目: JDKSourceCode1.8   文件: Sink.java
public ChainedReference(Sink<? super E_OUT> downstream) {
    this.downstream = Objects.requireNonNull(downstream);
}
 
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");
}
 
源代码14 项目: vertx-config   文件: EventBusConfigStoreFactory.java
@Override
public ConfigStore create(Vertx vertx, JsonObject configuration) {
  String address = configuration.getString("address");
  Objects.requireNonNull(address);
  return new EventBusConfigStore(vertx, address);
}
 
源代码15 项目: pinpoint   文件: DefaultApplicationsMapCreator.java
public DefaultApplicationsMapCreator(ApplicationMapCreator applicationMapCreator, Executor executor) {
    this.applicationMapCreator = Objects.requireNonNull(applicationMapCreator, "applicationMapCreator");
    this.executor = Objects.requireNonNull(executor, "executor");
}
 
源代码16 项目: Bytecoder   文件: LocalTime.java
/**
 * 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;
}
 
源代码17 项目: jdk8u-jdk   文件: AnnotatedElement.java
/**
 * 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;
 }
 
源代码18 项目: bistoury   文件: Base64.java
/**
 * 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);
}
 
/**
 * Creates VoidIndexable.
 *
 * @param key the key.
 */
public VoidIndexable(String key) {
    Objects.requireNonNull(key);
    this.key = key;
}
 
源代码20 项目: openAGV   文件: ConfigurationItemTO.java
/**
 * Sets this configuration item's key.
 *
 * @param key The new key.
 */
public void setKey(String key) {
  this.key = Objects.requireNonNull(key, "key is null");
}