本文整理汇总了Java中com.googlecode.totallylazy.Option.map方法的典型用法代码示例。如果您正苦于以下问题:Java Option.map方法的具体用法?Java Option.map怎么用?Java Option.map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.totallylazy.Option
的用法示例。
在下文中一共展示了Option.map方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: optionMapExampleNone
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
/** Here the same code passing in `none`: */
@Test
public void optionMapExampleNone() {
Option<String> optionalString = none();
Option<Integer> optionalNumber = optionalString.map(Integer::parseInt);
Option<Integer> optionalDouble = optionalNumber.map(n -> 2 * n);
assertEquals(false, optionalDouble.isDefined());
}
示例2: getJavaClass
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
private static Option<JavaClass> getJavaClass(final Class aClass) throws IOException {
Option<URL> option = getJavaSourceFromClassPath(aClass);
option = !option.isEmpty() ? option : getJavaSourceFromFileSystem(aClass);
return option.map(asAJavaClass(aClass));
}
示例3: optionMapExample
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
/** So far this is just a more explicit way to declare a type (and you could do this with the `Optional`
* type of Java 8), but here is how you can avoid boilerplate null/ defined checks when working
* with optional values.
*
* Consider logic to parse a number that is optionally supplied as a string: */
@Test
public void optionMapExample() {
Option<String> optionalString = some("123");
// We can now perform all sorts of operations without checking explicitly:
Option<Integer> optionalNumber = optionalString.map(Integer::parseInt);
Option<Integer> optionalDouble = optionalNumber.map(n -> 2 * n);
assertEquals(true, optionalDouble.isDefined());
assertEquals(Integer.valueOf(246), optionalDouble.get());
}