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


Java Some类代码示例

本文整理汇总了Java中com.googlecode.totallylazy.Some的典型用法代码示例。如果您正苦于以下问题:Java Some类的具体用法?Java Some怎么用?Java Some使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: indirectRateFor

import com.googlecode.totallylazy.Some; //导入依赖的package包/类
/**
 * Return an Option on an exchange rate.  If a direct rate exists an Option on that will be returned.
 * Otherwise, if a cross rate can be determined (1 hop limit), it will be created and returned in an Option.
 * Otherwise, None will be returned
 *
 * @param curA Currency A
 * @param curB Currency B
 * @return
 * @throws NoSuchExchangeRateException 
 */
public Option<CurrencyExchangeRate> indirectRateFor(final Currency curA, final Currency curB) throws NoSuchExchangeRateException {

  // TODO Improve this to attempt to use defaultCurrency first
  Option<CurrencyExchangeRate> directRateFor = directRateFor(curA, curB);
  if (!directRateFor.isEmpty()) {
    return directRateFor;
  } else {
    List<CurrencyExchangeRate> ratesWithCurA = new ArrayList<CurrencyExchangeRate>();
    List<CurrencyExchangeRate> ratesWithCurB = new ArrayList<CurrencyExchangeRate>();
    for (CurrencyExchangeRate r : this.rates) {
      if (r.base.currency == curA || r.counter.currency == curA) {
        ratesWithCurA.add(r);
      }
      if (r.base.currency == curB || r.counter.currency == curB) {
        ratesWithCurB.add(r);
      }
    }
    List<Currency> curs = new ArrayList<Currency>();
    for (Currency cur : this.currencies) {
      if ((containsBaseCurrency(ratesWithCurA, cur) || containsCounterCurrency(ratesWithCurA, cur)) && 
          (containsBaseCurrency(ratesWithCurB, cur) || containsCounterCurrency(ratesWithCurB, cur))) {
        curs.add(cur);
      }
    }
    if (curs.size() > 0) {
      Money m = Money(1d, curs.get(0));
      return Some.some(new CurrencyExchangeRate(convert(m, curA), convert(m, curB)));
    } else {
      return None.none();
    }
  }
}
 
开发者ID:synapplix,项目名称:jquants,代码行数:43,代码来源:MoneyContext.java

示例2: canCastOption

import com.googlecode.totallylazy.Some; //导入依赖的package包/类
@Test
public void canCastOption() throws Exception {
    assertThat(Structural.castOption(Closeable.class, new Object() {
        void close() {}
    }), instanceOf(Some.class));
    assertThat(Structural.castOption(Closeable.class, new Object()), is(none(Closeable.class)));
}
 
开发者ID:bodar,项目名称:totallylazy,代码行数:8,代码来源:StructuralTest.java


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