当前位置: 首页>>代码示例>>Java>>正文


Java OptionalLong.of方法代码示例

本文整理汇总了Java中java.util.OptionalLong.of方法的典型用法代码示例。如果您正苦于以下问题:Java OptionalLong.of方法的具体用法?Java OptionalLong.of怎么用?Java OptionalLong.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.OptionalLong的用法示例。


在下文中一共展示了OptionalLong.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: getLongProperty

import java.util.OptionalLong; //导入方法依赖的package包/类
default OptionalLong getLongProperty(String name) {
    Optional<String> optValue = getProperty(name);
    if (optValue.isPresent()) {
        return OptionalLong.of(Long.parseLong(optValue.get()));
    } else {
        return OptionalLong.empty();
    }
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:9,代码来源:StroomPropertyService.java

示例4: testPresent

import java.util.OptionalLong; //导入方法依赖的package包/类
@Test(groups = "unit")
    public void testPresent() {
    OptionalLong empty = OptionalLong.empty();
    OptionalLong present = OptionalLong.of(1L);

    // present
    assertTrue(present.equals(present));
    assertFalse(present.equals(OptionalLong.of(0L)));
    assertTrue(present.equals(OptionalLong.of(1L)));
    assertFalse(present.equals(empty));
    assertTrue(Long.hashCode(1) == present.hashCode());
    assertFalse(present.toString().isEmpty());
    assertTrue(-1 != present.toString().indexOf(Long.toString(present.getAsLong()).toString()));
    assertEquals(1L, present.getAsLong());
    try {
        present.ifPresent(v -> { throw new ObscureException(); });
        fail();
    } catch(ObscureException expected) {

    }
    assertEquals(1, present.orElse(2));
    assertEquals(1, present.orElseGet(null));
    assertEquals(1, present.orElseGet(()-> 2));
    assertEquals(1, present.orElseGet(()-> 3));
    assertEquals(1, present.<RuntimeException>orElseThrow(null));
    assertEquals(1, present.<RuntimeException>orElseThrow(ObscureException::new));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:BasicLong.java

示例5: 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(); });

    AtomicBoolean emptyCheck = new AtomicBoolean();
    empty.ifPresentOrElse(v -> fail(), () -> emptyCheck.set(true));
    assertTrue(emptyCheck.get());

    try {
        empty.ifPresentOrElse(v -> fail(), () -> { throw new ObscureException(); });
        fail();
    } catch (ObscureException expected) {
    } catch (AssertionError e) {
        throw e;
    } catch (Throwable t) {
        fail();
    }

    assertEquals(2, empty.orElse(2));
    assertEquals(2, empty.orElseGet(()-> 2));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:BasicLong.java

示例6: fromProto

import java.util.OptionalLong; //导入方法依赖的package包/类
@NonNull
public OptionalLong fromProto(@NonNull MSG_OptionalSerial serialOf) {
    // note that an unsigned is used to transport the serial. Serials MUST be >0
    if (serialOf.getPresent() && serialOf.getSerial() > 0) {
        return OptionalLong.of(serialOf.getSerial());
    } else {
        return OptionalLong.empty();
    }
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:10,代码来源:ProtoConverter.java

示例7: setMillisBehindLatestAndContinuationToken

import java.util.OptionalLong; //导入方法依赖的package包/类
private void setMillisBehindLatestAndContinuationToken() {
    final Map<String, String> tagNameToTagValueMap = getTagNameToValueMap();
    //Do not overwrite an existing value with Optional.absent

    String millisBehindString = tagNameToTagValueMap.get(MILLIS_BEHIND_NOW_KEY);
    if (millisBehindString != null) {
        millisBehindNow = (OptionalLong.of(Long.parseLong(millisBehindString)));
    }
    String continutationTokenString = tagNameToTagValueMap.get(CONTINUATION_TOKEN_KEY);
    if (continutationTokenString != null) {
        continuationToken = Optional.of(continutationTokenString);
    }
}
 
开发者ID:aws,项目名称:amazon-kinesis-video-streams-parser-library,代码行数:14,代码来源:FragmentMetadataVisitor.java

示例8: PropertyMapperTestEntity

import java.util.OptionalLong; //导入方法依赖的package包/类
public PropertyMapperTestEntity(final int id) {
	this.id = id;
	this.name = Optional.of("name");
	this.intValue = OptionalInt.of(2);
	this.longValue = OptionalLong.of(3);
	this.doubleValue = OptionalDouble.of(4.5);
	this.dateValue = LocalDate.now();
	this.datetimeValue = LocalDateTime.now();
	this.enumValue = TesEnum.B_VALUE;
	this.bigIntValue = BigInteger.TEN;
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:12,代码来源:PropertyMapperTest.java

示例9: OptionalLongExample

import java.util.OptionalLong; //导入方法依赖的package包/类
public OptionalLongExample(Long value) {
    this.value = OptionalLong.of(value);
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:4,代码来源:OptionalLongExample.java

示例10: get

import java.util.OptionalLong; //导入方法依赖的package包/类
@Override
public OptionalLong get() {
    return hasValue ? OptionalLong.of(value) : null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:FindOps.java

示例11: payloadLen

import java.util.OptionalLong; //导入方法依赖的package包/类
@Override
public void payloadLen(long value) {
    checkAndSetOrder(p -> p == 5 || p == 6, n -> 7);
    payloadLen = OptionalLong.of(value);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:ReaderTest.java

示例12: 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

示例13: test_optionalLong

import java.util.OptionalLong; //导入方法依赖的package包/类
public void test_optionalLong() throws Exception {
    OptionalLong val = OptionalLong.of(3);
    
    String text = JSON.toJSONString(val);
    
    Assert.assertEquals("3", text);
    
    OptionalLong val2 = JSON.parseObject(text, OptionalLong.class);
    Assert.assertEquals(val.getAsLong(), val2.getAsLong());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:OptionalTest.java

示例14: 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

示例15: 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


注:本文中的java.util.OptionalLong.of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。