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


Java OptionalInt.of方法代碼示例

本文整理匯總了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());
    }
}
 
開發者ID:exelixi,項目名稱:exelixi-am,代碼行數:13,代碼來源:ExelixiChannels.java

示例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));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:28,代碼來源:BasicInt.java

示例3: get

import java.util.OptionalInt; //導入方法依賴的package包/類
@Encoding.Expose
OptionalInt get() {
  return present
      ? OptionalInt.of(value)
      : OptionalInt.empty();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:7,代碼來源:CompactOptionalInt.java

示例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();
        }
    };
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:50,代碼來源:ReduceOps.java

示例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();
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:5,代碼來源:ListingConfiguration.java

示例6: getTotalTrackCount

import java.util.OptionalInt; //導入方法依賴的package包/類
public OptionalInt getTotalTrackCount() {
  return OptionalInt.of(totalTrackCount);
}
 
開發者ID:FelixGail,項目名稱:gplaymusic,代碼行數:4,代碼來源:Track.java

示例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());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:OptionalTest.java

示例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);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:InlineQueryResultVideo.java

示例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);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:InlineQueryResultMpeg4Gif.java

示例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);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:InlineQueryResultLocation.java

示例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);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:Sticker.java

示例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);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:InputMediaVideo.java

示例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);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:InlineQueryResultGif.java

示例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);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:InlineQueryResultMpeg4Gif.java

示例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);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:9,代碼來源:InlineQueryResultVenue.java


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