本文整理汇总了Java中java.util.OptionalInt.empty方法的典型用法代码示例。如果您正苦于以下问题:Java OptionalInt.empty方法的具体用法?Java OptionalInt.empty怎么用?Java OptionalInt.empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.OptionalInt
的用法示例。
在下文中一共展示了OptionalInt.empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEmpty
import java.util.OptionalInt; //导入方法依赖的package包/类
@Test(groups = "unit")
public void testEmpty() {
OptionalInt empty = OptionalInt.empty();
OptionalInt present = OptionalInt.of(1);
// empty
assertTrue(empty.equals(empty));
assertTrue(empty.equals(OptionalInt.empty()));
assertTrue(!empty.equals(present));
assertTrue(0 == empty.hashCode());
assertTrue(!empty.toString().isEmpty());
assertTrue(!empty.isPresent());
empty.ifPresent(v -> { fail(); });
assertEquals(2, empty.orElse(2));
assertEquals(2, empty.orElseGet(()-> 2));
}
示例2: findAffinityArg
import java.util.OptionalInt; //导入方法依赖的package包/类
private static OptionalInt findAffinityArg(Method meth) {
OptionalInt affinityArg = OptionalInt.empty();
if (meth.getParameterCount() > 0) {
for (int i = 0; i < meth.getParameterCount() && !affinityArg.isPresent(); i++) {
Annotation[] annotations = meth.getParameterAnnotations()[i];
for (int j = 0; j < annotations.length; j++) {
if (RpcAffinityKey.class.isAssignableFrom(annotations[j].annotationType())) {
affinityArg = OptionalInt.of(i);
break;
}
}
}
}
return affinityArg;
}
示例3: extractResponseSequenceId
import java.util.OptionalInt; //导入方法依赖的package包/类
@Override
public OptionalInt extractResponseSequenceId(ByteBuf buffer)
{
if (buffer.readableBytes() < HEADER_SEQUENCE_ID_OFFSET + Integer.BYTES) {
return OptionalInt.empty();
}
return OptionalInt.of(buffer.getInt(buffer.readerIndex() + HEADER_SEQUENCE_ID_OFFSET));
}
示例4: getSerializedSnapshotVersion
import java.util.OptionalInt; //导入方法依赖的package包/类
public OptionalInt getSerializedSnapshotVersion(String entityId) {
SnapshotRecord record = retrieveSnapshotRecord(entityId);
if (record != null) {
return OptionalInt.of(record.getHeader().payloadVersion());
} else {
return OptionalInt.empty();
}
}
示例5: toOptionalInt
import java.util.OptionalInt; //导入方法依赖的package包/类
private static OptionalInt toOptionalInt(final String value) {
try {
return OptionalInt.of(Integer.parseInt(value));
} catch (NumberFormatException e) {
return OptionalInt.empty();
}
}
示例6: extract
import java.util.OptionalInt; //导入方法依赖的package包/类
public static OptionalInt extract(String s, String factor) {
StringTokenizer st = new StringTokenizer(s, ".");
while (st.hasMoreTokens()) {
String token = st.nextToken();
if (token.startsWith(factor)) {
try {
return OptionalInt.of(Integer.parseInt(token.substring(factor.length())));
} catch (NumberFormatException ex) {
// continue
}
}
}
return OptionalInt.empty();
}
示例7: testEmptyOrElseThrowNull
import java.util.OptionalInt; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(null);
}
示例8: get
import java.util.OptionalInt; //导入方法依赖的package包/类
@Encoding.Expose
OptionalInt get() {
return present
? OptionalInt.of(value)
: OptionalInt.empty();
}
示例9: StreamingMkvReader
import java.util.OptionalInt; //导入方法依赖的package包/类
StreamingMkvReader(boolean requirePath,
Collection<EBMLTypeInfo> typeInfosToRead,
ParserByteSource byteSource) {
this(requirePath, typeInfosToRead, byteSource, OptionalInt.empty());
}
示例10: getTemporalValue
import java.util.OptionalInt; //导入方法依赖的package包/类
/**
* Returns the temporal pattern value of this ChronoPattern.
* A missing temporal patter value means "every" of the unit.
*
* For example, with a chrono scale unit of SECONDS and a missing temporal value
* this translates to: every second.
*
* @return temporal pattern value, if present
*/
@NotNull
public OptionalInt getTemporalValue() {
if (temporalValue == 0) {
return OptionalInt.empty();
}
return OptionalInt.of(temporalValue);
}
示例11: getMpeg4Duration
import java.util.OptionalInt; //导入方法依赖的package包/类
/**
* Getter for property {@link #mpeg4Duration}.
*
* @return optional value for property {@link #mpeg4Duration}
*/
public OptionalInt getMpeg4Duration() {
return mpeg4Duration == null ? OptionalInt.empty() : OptionalInt.of(mpeg4Duration);
}
示例12: getThumbHeight
import java.util.OptionalInt; //导入方法依赖的package包/类
/**
* Getter for property {@link #thumbHeight}.
*
* @return optional value for property {@link #thumbHeight}
*/
public OptionalInt getThumbHeight() {
return thumbHeight == null ? OptionalInt.empty() : OptionalInt.of(thumbHeight);
}
示例13: getVideoDuration
import java.util.OptionalInt; //导入方法依赖的package包/类
/**
* Getter for property {@link #videoDuration}.
*
* @return optional value for property {@link #videoDuration}
*/
public OptionalInt getVideoDuration() {
return videoDuration == null ? OptionalInt.empty() : OptionalInt.of(videoDuration);
}
示例14: getThumbWidth
import java.util.OptionalInt; //导入方法依赖的package包/类
/**
* Getter for property {@link #thumbWidth}.
*
* @return optional value for property {@link #thumbWidth}
*/
public OptionalInt getThumbWidth() {
return thumbWidth == null ? OptionalInt.empty() : OptionalInt.of(thumbWidth);
}
示例15: findLast
import java.util.OptionalInt; //导入方法依赖的package包/类
/**
* Returns the last element of the specified stream, or {@link OptionalInt#empty} if the stream is
* empty.
*
* <p>Equivalent to {@code stream.reduce((a, b) -> b)}, but may perform significantly better. This
* method's runtime will be between O(log n) and O(n), performing better on <a
* href="http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html">efficiently splittable</a>
* streams.
*
* @see IntStream#findFirst()
* @throws NullPointerException if the last element of the stream is null
*/
public static OptionalInt findLast(IntStream stream) {
// findLast(Stream) does some allocation, so we might as well box some more
java.util.Optional<Integer> boxedLast = findLast(stream.boxed());
return boxedLast.isPresent() ? OptionalInt.of(boxedLast.get()) : OptionalInt.empty();
}