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


Java OptionalLong.empty方法代碼示例

本文整理匯總了Java中java.util.OptionalLong.empty方法的典型用法代碼示例。如果您正苦於以下問題:Java OptionalLong.empty方法的具體用法?Java OptionalLong.empty怎麽用?Java OptionalLong.empty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.OptionalLong的用法示例。


在下文中一共展示了OptionalLong.empty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: serialOf

import java.util.OptionalLong; //導入方法依賴的package包/類
@Override
public OptionalLong serialOf(UUID l) {
    try (Context time = seqLookupLatency.time();) {
        List<Long> res = jdbcTemplate.query(PGConstants.SELECT_SER_BY_ID, new Object[] {
                "{\"id\":\"" + l + "\"}" }, this::extractSerFromResultSet);

        if (res.size() > 1) {
            throw new IllegalStateException("Event ID appeared twice!?");
        } else if (res.isEmpty()) {
            return OptionalLong.empty();
        }

        Long ser = res.get(0);
        if (ser != null && ser.longValue() > 0) {
            return OptionalLong.of(ser.longValue());
        } else {
            return OptionalLong.empty();
        }

    }
}
 
開發者ID:uweschaefer,項目名稱:factcast,代碼行數:22,代碼來源:PGFactStore.java

示例2: testEmpty

import java.util.OptionalLong; //導入方法依賴的package包/類
@Test(groups = "unit")
public void testEmpty() {
    OptionalLong empty = OptionalLong.empty();
    OptionalLong present = OptionalLong.of(1);

    // empty
    assertTrue(empty.equals(empty));
    assertTrue(empty.equals(OptionalLong.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,代碼來源:BasicLong.java

示例3: parseLong

import java.util.OptionalLong; //導入方法依賴的package包/類
@Nonnull
public static OptionalLong parseLong(@Nonnull String s) {
    try {
        return OptionalLong.of(Long.parseLong(s));
    } catch (NumberFormatException e) {
        return OptionalLong.empty();
    }
}
 
開發者ID:lucko,項目名稱:helper,代碼行數:9,代碼來源:Numbers.java

示例4: serialOf

import java.util.OptionalLong; //導入方法依賴的package包/類
@Override
public OptionalLong serialOf(UUID l) {
    // hilariously inefficient
    for (Map.Entry<Long, Fact> e : store.entrySet()) {
        if (l.equals(e.getValue().id())) {
            return OptionalLong.of(e.getKey().longValue());
        }
    }
    return OptionalLong.empty();
}
 
開發者ID:uweschaefer,項目名稱:factcast,代碼行數:11,代碼來源:InMemFactStore.java

示例5: getValue

import java.util.OptionalLong; //導入方法依賴的package包/類
@Override
public OptionalLong getValue(final JavaType type, final ResultSet rs, final int columnIndex,
		final PropertyMapperManager mapperManager) throws SQLException {
	long value = rs.getLong(columnIndex);
	if (!rs.wasNull()) {
		return OptionalLong.of(value);
	} else {
		return OptionalLong.empty();
	}
}
 
開發者ID:future-architect,項目名稱:uroborosql,代碼行數:11,代碼來源:OptionalLongPropertyMapper.java

示例6: testEmptyOrElseGetNull

import java.util.OptionalLong; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseGetNull() {
    OptionalLong empty = OptionalLong.empty();

    long got = empty.orElseGet(null);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:BasicLong.java

示例7: makeLong

import java.util.OptionalLong; //導入方法依賴的package包/類
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code long} values, producing an optional long result.
 *
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Long, OptionalLong>
makeLong(LongBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Long, OptionalLong, ReducingSink>, Sink.OfLong {
        private boolean empty;
        private long state;

        public void begin(long size) {
            empty = true;
            state = 0;
        }

        @Override
        public void accept(long t) {
            if (empty) {
                empty = false;
                state = t;
            }
            else {
                state = operator.applyAsLong(state, t);
            }
        }

        @Override
        public OptionalLong get() {
            return empty ? OptionalLong.empty() : OptionalLong.of(state);
        }

        @Override
        public void combine(ReducingSink other) {
            if (!other.empty)
                accept(other.state);
        }
    }
    return new ReduceOp<Long, OptionalLong, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:50,代碼來源:ReduceOps.java

示例8: testEmptyOrElseThrowNull

import java.util.OptionalLong; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
    OptionalLong empty = OptionalLong.empty();

    long got = empty.orElseThrow(null);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:BasicLong.java

示例9: testEmpty

import java.util.OptionalLong; //導入方法依賴的package包/類
@Test
public void testEmpty() {
	OptionalLongParameterMapper mapper = new OptionalLongParameterMapper();
	OptionalLong optional = OptionalLong.empty();
	assertThat(mapper.toJdbc(optional, null, null), is(nullValue()));
}
 
開發者ID:future-architect,項目名稱:uroborosql,代碼行數:7,代碼來源:OptionalLongParameterMapperTest.java

示例10: testEmptyGet

import java.util.OptionalLong; //導入方法依賴的package包/類
@Test(expectedExceptions=NoSuchElementException.class)
public void testEmptyGet() {
    OptionalLong empty = OptionalLong.empty();

    long got = empty.getAsLong();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:7,代碼來源:BasicLong.java

示例11: getLastTested

import java.util.OptionalLong; //導入方法依賴的package包/類
/**
 * Return the time in milliseconds when this cooldown was last {@link #test()}ed.
 *
 * @return the last call time
 */
@Override
public OptionalLong getLastTested() {
    return lastTested == 0 ? OptionalLong.empty() : OptionalLong.of(lastTested);
}
 
開發者ID:lucko,項目名稱:helper,代碼行數:10,代碼來源:Cooldown.java

示例12: findLast

import java.util.OptionalLong; //導入方法依賴的package包/類
/**
 * Returns the last element of the specified stream, or {@link OptionalLong#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 LongStream#findFirst()
 * @throws NullPointerException if the last element of the stream is null
 */
public static OptionalLong findLast(LongStream stream) {
  // findLast(Stream) does some allocation, so we might as well box some more
  java.util.Optional<Long> boxedLast = findLast(stream.boxed());
  return boxedLast.isPresent() ? OptionalLong.of(boxedLast.get()) : OptionalLong.empty();
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:18,代碼來源:Streams.java

示例13: getEditDate

import java.util.OptionalLong; //導入方法依賴的package包/類
/**
 * Getter for property {@link #editDate}.
 *
 * @return optional value for property {@link #editDate}
 */
public OptionalLong getEditDate() {
  return editDate == null ? OptionalLong.empty() : OptionalLong.of(editDate);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:Message.java

示例14: getMigrateToChatId

import java.util.OptionalLong; //導入方法依賴的package包/類
/**
 * Getter for property {@link #migrateToChatId}.
 *
 * @return optional value for property {@link #migrateToChatId}
 */
public OptionalLong getMigrateToChatId() {
  return migrateToChatId == null ? OptionalLong.empty() : OptionalLong.of(migrateToChatId);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:ResponseParameters.java

示例15: makeLong

import java.util.OptionalLong; //導入方法依賴的package包/類
/**
 * Constructs a {@code TerminalOp} for streams of longs.
 *
 * @param mustFindFirst whether the {@code TerminalOp} must produce the
 *        first element in the encounter order
 * @return a {@code TerminalOp} implementing the find operation
 */
public static TerminalOp<Long, OptionalLong> makeLong(boolean mustFindFirst) {
    return new FindOp<>(mustFindFirst, StreamShape.LONG_VALUE, OptionalLong.empty(),
                        OptionalLong::isPresent, FindSink.OfLong::new);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:12,代碼來源:FindOps.java


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