當前位置: 首頁>>代碼示例>>Java>>正文


Java OptionalInt.empty方法代碼示例

本文整理匯總了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));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:BasicInt.java

示例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;
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:20,代碼來源:RpcMethodInfo.java

示例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));
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:9,代碼來源:HeaderMessageEncoding.java

示例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();
    }
}
 
開發者ID:goodees,項目名稱:goodees,代碼行數:9,代碼來源:InMemorySnapshotStoreWithSerialization.java

示例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();
	}
}
 
開發者ID:jenetics,項目名稱:prngine,代碼行數:8,代碼來源:DieHarder.java

示例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();
}
 
開發者ID:mbuzdalov,項目名稱:non-dominated-sorting,代碼行數:15,代碼來源:IdUtils.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:7,代碼來源:BasicInt.java

示例8: get

import java.util.OptionalInt; //導入方法依賴的package包/類
@Encoding.Expose
OptionalInt get() {
  return present
      ? OptionalInt.of(value)
      : OptionalInt.empty();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:7,代碼來源:CompactOptionalInt.java

示例9: StreamingMkvReader

import java.util.OptionalInt; //導入方法依賴的package包/類
StreamingMkvReader(boolean requirePath,
        Collection<EBMLTypeInfo> typeInfosToRead,
        ParserByteSource byteSource) {
    this(requirePath, typeInfosToRead, byteSource, OptionalInt.empty());
}
 
開發者ID:aws,項目名稱:amazon-kinesis-video-streams-parser-library,代碼行數:6,代碼來源:StreamingMkvReader.java

示例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);
}
 
開發者ID:BFergerson,項目名稱:Chronetic,代碼行數:17,代碼來源:ChronoPattern.java

示例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);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:InlineQueryResultMpeg4Gif.java

示例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);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:InlineQueryResultVenue.java

示例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);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:InlineQueryResultVideo.java

示例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);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:InlineQueryResultContact.java

示例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();
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:18,代碼來源:Streams.java


注:本文中的java.util.OptionalInt.empty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。