本文整理汇总了Java中com.googlecode.totallylazy.Option.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java Option.isEmpty方法的具体用法?Java Option.isEmpty怎么用?Java Option.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.totallylazy.Option
的用法示例。
在下文中一共展示了Option.isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
/**
* Converts a Money value to the specified currency.
*
* The conversion first attempts to use an existing exchange rate for the two currencies in question.
* If no direct exchange works, a cross rate (limited to 1 hop) will be calculated and used.
* If no cross rate can be calculated a NoSuchElementException is thrown
*
* @param money Money to be converted
* @param currency Currency to be converted to
* @return
* @throws NoSuchExchangeRateException when no exchange rate is available
*/
public Money convert(Money money, Currency currency) throws NoSuchExchangeRateException {
if (money.currency == currency) {
return money;
}else {
Option<CurrencyExchangeRate> rate = directRateFor(money.currency, currency);
if (!rate.isEmpty()) {
return rate.get().convert(money);
} else {
if (allowIndirectConversions) {
Option<CurrencyExchangeRate> crossRate = indirectRateFor(money.currency, currency);
if (!crossRate.isEmpty()) {
return crossRate.get().convert(money);
} else {
throw new NoSuchExchangeRateException(String.format("Rate for currency pair %s / %s)", money.currency, currency));
}
}
}
}
throw new NoSuchExchangeRateException(String.format("Rate for currency pair %s / %s)", money.currency, currency));
}
示例2: collectTestMethods
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
private static Sequence<TestMethod> collectTestMethods(Class aClass, Sequence<Method> methods) throws IOException {
final Option<JavaClass> javaClass = getJavaClass(aClass);
if (javaClass.isEmpty()) {
return empty();
}
Map<String, List<JavaMethod>> sourceMethodsByName = getMethods(javaClass.get()).toMap(sourceMethodName());
Map<String, List<Method>> reflectionMethodsByName = methods.toMap(reflectionMethodName());
List<TestMethod> testMethods = new ArrayList<TestMethod>();
TestMethodExtractor extractor = new TestMethodExtractor();
for (String name : sourceMethodsByName.keySet()) {
List<JavaMethod> javaMethods = sourceMethodsByName.get(name);
List<Method> reflectionMethods = reflectionMethodsByName.get(name);
testMethods.add(extractor.toTestMethod(aClass, javaMethods.get(0), reflectionMethods.get(0)));
// TODO: If people overload test methods we will have to use the full name rather than the short name
}
Sequence<TestMethod> myTestMethods = sequence(testMethods);
Sequence<TestMethod> parentTestMethods = collectTestMethods(aClass.getSuperclass(), methods);
return myTestMethods.join(parentTestMethods);
}
示例3: snap
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
@POST
@Hidden
@Path("snap")
@Produces(MediaType.APPLICATION_JSON)
public Response snap(@FormParam("id") String id) {
Option<WebConsoleClientHandler> clientHandler = agent.client(id);
if (!clientHandler.isEmpty()) {
String snapId = UUID.randomUUID().toString();
Files.write(clientHandler.get().history().toString("\n").getBytes(), snapFile(snapId));
return ok()
.entity(emptyMap(String.class, Object.class)
.insert("snap", snapId)
.insert("uri", snapUri(snapId).toString())
);
} else {
return response(BAD_REQUEST);
}
}
示例4: call
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
public CompletionResult call(String expression) throws Exception {
final int lastSeparator = lastIndexOfSeparator(characters(" "), expression) + 1;
final String packagePart = expression.substring(lastSeparator);
Option<Pair<Class<?>, String>> completion = completionFor(packagePart);
if (!completion.isEmpty()) {
Function1<CompletionCandidate, String> value = CompletionCandidate::value;
Sequence<CompletionCandidate> candidates = reflectionOf(completion.get().first())
.declaredMembers()
.filter(isStatic().and(isPublic()).and(not(isSynthetic())))
.groupBy(candidateName())
.map(candidate())
.filter(where(value, startsWith(completion.get().second())));
final int beginIndex = packagePart.lastIndexOf('.') + 1;
return new CompletionResult(expression, lastSeparator + beginIndex, candidates);
} else {
return new CompletionResult(expression, 0, Sequences.empty(CompletionCandidate.class));
}
}
示例5: parseExpression
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
private Option<Pair<String, Sequence<String>>> parseExpression(Pair<String, Sequence<String>> expression) {
Option<Class<?>> expressionClass = evaluator.classFrom(expression.first());
if (!expressionClass.isEmpty()) {
return some(expression);
}
if (expression.first().contains(".")) {
final String packagePart = expression.first().substring(0, expression.first().lastIndexOf("."));
final String classPart = expression.first().substring(expression.first().lastIndexOf(".") + 1);
return parseExpression(pair(packagePart, expression.second().cons(classPart)));
}
return Option.none();
}
示例6: main
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {
console = new ResultPrinter(printColors(args));
ConsoleReader consoleReader = new ConsoleReader(System.in, AnsiConsole.out);
JavaREPLClient client = clientFor(hostname(args), port(args));
Sequence<String> initialExpressions = initialExpressionsFromFile().join(initialExpressionsFromArgs(args));
ExpressionReader expressionReader = expressionReaderFor(consoleReader, client, initialExpressions);
Option<String> expression = none();
Option<EvaluationResult> result = none();
while (expression.isEmpty() || !result.isEmpty()) {
expression = expressionReader.readExpression();
if (!expression.isEmpty()) {
result = client.execute(expression.get());
if (!result.isEmpty()) {
for (EvaluationLog log : result.get().logs()) {
if (!handleTerminalCommand(log)) {
handleTerminalMessage(log);
}
}
}
}
}
}
示例7: execute
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
public void execute(String expression) {
Option<String> path = parseStringCommand(expression).second();
if (!path.isEmpty()) {
try {
evaluator.evaluate(Strings.lines(path.map(asFile()).get()).toString("\n"))
.leftOption()
.forEach(throwException());
logger.success(format("Loaded source file from %s", path.get()));
} catch (Exception e) {
logger.error(format("Could not load source file from %s.\n %s", path.get(), e.getLocalizedMessage()));
}
} else {
logger.error(format("Path not specified"));
}
}
示例8: 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;
}
示例9: indirectRateFor
import com.googlecode.totallylazy.Option; //导入方法依赖的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();
}
}
}
示例10: lookup
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
@Override
public List lookup(Term key) {
Option<Term> result = set.lookup(key);
if (result.isEmpty()) {
return List.nil;
} else {
return List.of(result.get());
}
}
示例11: get
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
@tailrec
public Option<V> get(Segment<K> key) {
if(key.isEmpty()) return value;
Option<Trie<K, V>> child = childFor(key);
if(child.isEmpty()) return none();
return child.get().get(key.tail());
}
示例12: contains
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
@tailrec
public boolean contains(K[] key) {
if (Arrays.isEmpty(key)) return !value.isEmpty();
Option<ArrayTrie<K, V>> child = childFor(key);
if (child.isEmpty()) return false;
return child.get().contains(tail(key));
}
示例13: get
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
@tailrec
public Option<V> get(K[] key) {
if (Arrays.isEmpty(key)) return value;
Option<ArrayTrie<K, V>> child = childFor(key);
if (child.isEmpty()) return none();
return child.get().get(tail(key));
}
示例14: 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();
}
示例15: removeClient
import com.googlecode.totallylazy.Option; //导入方法依赖的package包/类
public synchronized Option<WebConsoleClientHandler> removeClient(String id) {
Option<WebConsoleClientHandler> clientHandler = clients.lookup(id);
if (!clientHandler.isEmpty()) {
clientHandler.get().shutdown();
clients = clients.delete(clientHandler.get().id());
}
return clientHandler;
}