本文整理匯總了Java中java.util.OptionalInt.of方法的典型用法代碼示例。如果您正苦於以下問題:Java OptionalInt.of方法的具體用法?Java OptionalInt.of怎麽用?Java OptionalInt.of使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.OptionalInt
的用法示例。
在下文中一共展示了OptionalInt.of方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: intToNearest8Mult
import java.util.OptionalInt; //導入方法依賴的package包/類
default IntType intToNearest8Mult(IntType t) {
if (t.getSize().isPresent()) {
int size = t.getSize().getAsInt();
int limit = 8;
while (size > limit) {
limit = limit + limit;
}
return new IntType(OptionalInt.of(limit), t.isSigned());
} else {
return new IntType(OptionalInt.of(32), t.isSigned());
}
}
示例2: testPresent
import java.util.OptionalInt; //導入方法依賴的package包/類
@Test(groups = "unit")
public void testPresent() {
OptionalInt empty = OptionalInt.empty();
OptionalInt present = OptionalInt.of(1);
// present
assertTrue(present.equals(present));
assertFalse(present.equals(OptionalInt.of(0)));
assertTrue(present.equals(OptionalInt.of(1)));
assertFalse(present.equals(empty));
assertTrue(Integer.hashCode(1) == present.hashCode());
assertFalse(present.toString().isEmpty());
assertTrue(-1 != present.toString().indexOf(Integer.toString(present.getAsInt()).toString()));
assertEquals(1, present.getAsInt());
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));
}
示例3: get
import java.util.OptionalInt; //導入方法依賴的package包/類
@Encoding.Expose
OptionalInt get() {
return present
? OptionalInt.of(value)
: OptionalInt.empty();
}
示例4: makeInt
import java.util.OptionalInt; //導入方法依賴的package包/類
/**
* Constructs a {@code TerminalOp} that implements a functional reduce on
* {@code int} values, producing an optional integer result.
*
* @param operator the combining function
* @return a {@code TerminalOp} implementing the reduction
*/
public static TerminalOp<Integer, OptionalInt>
makeInt(IntBinaryOperator operator) {
Objects.requireNonNull(operator);
class ReducingSink
implements AccumulatingSink<Integer, OptionalInt, ReducingSink>, Sink.OfInt {
private boolean empty;
private int state;
public void begin(long size) {
empty = true;
state = 0;
}
@Override
public void accept(int t) {
if (empty) {
empty = false;
state = t;
}
else {
state = operator.applyAsInt(state, t);
}
}
@Override
public OptionalInt get() {
return empty ? OptionalInt.empty() : OptionalInt.of(state);
}
@Override
public void combine(ReducingSink other) {
if (!other.empty)
accept(other.state);
}
}
return new ReduceOp<Integer, OptionalInt, ReducingSink>(StreamShape.INT_VALUE) {
@Override
public ReducingSink makeSink() {
return new ReducingSink();
}
};
}
示例5: serverPort
import java.util.OptionalInt; //導入方法依賴的package包/類
public OptionalInt serverPort() {
final int port = config.getInt("server-port", 0);
return port != 0 ? OptionalInt.of(port) : OptionalInt.empty();
}
示例6: getTotalTrackCount
import java.util.OptionalInt; //導入方法依賴的package包/類
public OptionalInt getTotalTrackCount() {
return OptionalInt.of(totalTrackCount);
}
示例7: test_optionalInt
import java.util.OptionalInt; //導入方法依賴的package包/類
public void test_optionalInt() throws Exception {
OptionalInt val = OptionalInt.of(3);
String text = JSON.toJSONString(val);
Assert.assertEquals("3", text);
OptionalInt val2 = JSON.parseObject(text, OptionalInt.class);
Assert.assertEquals(val.getAsInt(), val2.getAsInt());
}
示例8: getVideoWidth
import java.util.OptionalInt; //導入方法依賴的package包/類
/**
* Getter for property {@link #videoWidth}.
*
* @return optional value for property {@link #videoWidth}
*/
public OptionalInt getVideoWidth() {
return videoWidth == null ? OptionalInt.empty() : OptionalInt.of(videoDuration);
}
示例9: getMpeg4Width
import java.util.OptionalInt; //導入方法依賴的package包/類
/**
* Getter for property {@link #mpeg4Width}.
*
* @return optional value for property {@link #mpeg4Width}
*/
public OptionalInt getMpeg4Width() {
return mpeg4Width == null ? OptionalInt.empty() : OptionalInt.of(mpeg4Width);
}
示例10: 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);
}
示例11: getSize
import java.util.OptionalInt; //導入方法依賴的package包/類
/**
* Getter for property {@link #size}.
*
* @return optional value for property {@link #size}
*/
public OptionalInt getSize() {
return size == null ? OptionalInt.empty() : OptionalInt.of(size);
}
示例12: getHeight
import java.util.OptionalInt; //導入方法依賴的package包/類
/**
* Getter for property {@link #height}.
*
* @return optional value for property {@link #height}
*/
public OptionalInt getHeight() {
return height == null ? OptionalInt.empty() : OptionalInt.of(height);
}
示例13: getGifHeight
import java.util.OptionalInt; //導入方法依賴的package包/類
/**
* Getter for property {@link #gifHeight}.
*
* @return optional value for property {@link #gifHeight}
*/
public OptionalInt getGifHeight() {
return gifHeight == null ? OptionalInt.empty() : OptionalInt.of(gifHeight);
}
示例14: getMpeg4Height
import java.util.OptionalInt; //導入方法依賴的package包/類
/**
* Getter for property {@link #mpeg4Height}.
*
* @return optional value for property {@link #mpeg4Height}
*/
public OptionalInt getMpeg4Height() {
return mpeg4Height == null ? OptionalInt.empty() : OptionalInt.of(mpeg4Height);
}
示例15: 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);
}