当前位置: 首页>>代码示例>>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;未经允许,请勿转载。