本文整理汇总了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();
}
}
}
示例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)));
}