use of org.activityinfo.model.formula.diagnostic.AmbiguousSymbolException in project activityinfo by bedatadriven.
the class FormSymbolTable method tryResolveSymbol.
public Optional<FormField> tryResolveSymbol(String name) {
FormField field = idMap.get(name);
if (field != null) {
return Optional.of(field);
}
Collection<FormField> matching = codeMap.get(name.toLowerCase());
if (matching.isEmpty()) {
// as last resort, try matching against label
matching = labelMap.get(name.toLowerCase());
}
if (matching.size() > 1) {
throw new AmbiguousSymbolException(name);
} else if (matching.isEmpty()) {
return Optional.absent();
} else {
return Optional.of(Iterables.getOnlyElement(matching));
}
}
Aggregations