本文整理汇总了Java中com.googlecode.totallylazy.Option.get方法的典型用法代码示例。如果您正苦于以下问题:Java Option.get方法的具体用法?Java Option.get怎么用?Java Option.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.totallylazy.Option
的用法示例。
在下文中一共展示了Option.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: optionExampleNone
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
/**
* Here an option without a value (none):
*/
@Test
public void optionExampleNone() {
Option<String> optionalString = none();
assertEquals(false, optionalString.isDefined());
try {
optionalString.get();
fail("This should fail as the option is not defined");
} catch (NoSuchElementException ignored) {}
}
示例2: get
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
public UnitOfMeasure get(final String symbol) {
if (companions.size() == 0) initQuantityCompanions();
for (Dimension c : companions) {
Option unit = c.symbolToUnit(symbol);
if (!unit.isEmpty()) return (UnitOfMeasure) unit.get();
}
return null;
}
示例3: put
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
@Override
public Object put(String key, Object value) {
try {
Option<Field> field = field(key);
if (field.isDefined()) {
Field actual = field.get();
actual.set(this, Coercer.coerce(actual.getGenericType(), value));
return Fields.get(actual, this);
} else {
return _otherFields.put(key, value);
}
} catch (IllegalAccessException e) {
throw lazyException(e);
}
}
示例4: getNext
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
@Override
protected A getNext() throws Exception {
Option<Pair<A, B>> result = callable.call(state);
if (result.isEmpty()) return finished();
Pair<A, B> pair = result.get();
state = pair.second();
return pair.first();
}
示例5: expectNode
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
public static Node expectNode(final Node node, String xpath) {
Option<Node> foundNode = selectNode(node, xpath);
if (foundNode.isEmpty())
throw new NoSuchElementException("No node for xpath " + xpath);
return foundNode.get();
}
示例6: expectElement
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
public static Element expectElement(final Node node, String xpath) {
Option<Element> element = selectElement(node, xpath);
if (element.isEmpty())
throw new NoSuchElementException("No element for xpath " + xpath);
return element.get();
}