本文整理汇总了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();
}
}
}
示例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));
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例6: testEmptyOrElseGetNull
import java.util.OptionalLong; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseGetNull() {
OptionalLong empty = OptionalLong.empty();
long got = empty.orElseGet(null);
}
示例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();
}
};
}
示例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);
}
示例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()));
}
示例10: testEmptyGet
import java.util.OptionalLong; //导入方法依赖的package包/类
@Test(expectedExceptions=NoSuchElementException.class)
public void testEmptyGet() {
OptionalLong empty = OptionalLong.empty();
long got = empty.getAsLong();
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}