List of usage examples for com.google.common.base Optional or
@Beta public abstract T or(Supplier<? extends T> supplier);
From source file:org.knowm.xdropwizard.resources.HelloWorldResource.java
/** Dropwizard automatically records the duration and rate of its invocations as a Metrics Timer. */ @GET/*w ww .j av a 2 s . c o m*/ @Timed public Saying sayHello(@QueryParam("name") Optional<String> name) { return new Saying(counter.incrementAndGet(), String.format(template, name.or(defaultName))); }
From source file:io.scigraph.owlapi.loader.OwlLoadConfigurationLoader.java
public OwlLoadConfiguration loadConfig() throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); OwlLoadConfiguration config = mapper.readValue(configurationFile, OwlLoadConfiguration.class); CurieUtil curieUtil = new CurieUtil(config.getGraphConfiguration().getCuries()); // resolve categories Map<String, String> resolvedCategories = new HashMap<String, String>(); for (Map.Entry<String, String> entry : config.getCategories().entrySet()) { Optional<String> iriOpt = curieUtil.getIri(entry.getKey()); resolvedCategories.put(iriOpt.or(entry.getKey()), entry.getValue()); }/*from ww w . ja va 2 s . c om*/ config.setCategories(resolvedCategories); // resolve MappedProperties List<MappedProperty> resolvedMappedProperties = new ArrayList<MappedProperty>(); for (MappedProperty mappedProperty : config.getMappedProperties()) { MappedProperty resolvedMappedProperty = new MappedProperty(mappedProperty.name); List<String> resolvedProperties = new ArrayList<String>(); for (String property : mappedProperty.getProperties()) { resolvedProperties.add(curieUtil.getIri(property).or(property)); } resolvedMappedProperty.setProperties(resolvedProperties); resolvedMappedProperties.add(resolvedMappedProperty); } config.setMappedProperties(resolvedMappedProperties); return config; }
From source file:com.pinterest.teletraan.resource.Commits.java
/** * Returns a list of CommitInfo from startSha inclusive to endSha exclusive, * or up to the specified size, whichever happens first; * if size == 0, then will return the full list until endSha * if endSha == null, then will return up to size, max_size = 500 * It is recommended to call multiple times (pagination) with size < 30 to avoid timeout *///www. j av a2s. c om @GET public List<CommitBean> getCommits(@QueryParam("repo") String repo, @QueryParam("startSha") String startSha, @QueryParam("endSha") String endSha, @QueryParam("size") Optional<Integer> size) throws Exception { return sourceControlManager.getCommits(repo, startSha, endSha, size.or(DEFAULT_SIZE)); }
From source file:com.pinterest.teletraan.resource.HostTypes.java
@GET @Path("/basic") public Collection<HostTypeBean> getByProviderAndBasic(@QueryParam("provider") String provider, @QueryParam("basic") Optional<Boolean> basic) throws Exception { return hostTypeDAO.getByProviderAndBasic(provider, basic.or(true)); }
From source file:com.pinterest.teletraan.resource.Placements.java
@GET @Path("/basic") public Collection<PlacementBean> getByProviderAndBasic(@QueryParam("provider") String provider, @QueryParam("basic") Optional<Boolean> basic) throws Exception { return placementDAO.getByProviderAndBasic(provider, basic.or(true)); }
From source file:com.pinterest.teletraan.resource.SecurityZones.java
@GET @Path("/basic") public Collection<SecurityZoneBean> getByProviderAndBasic(@QueryParam("provider") String provider, @QueryParam("basic") Optional<Boolean> basic) throws Exception { return securityZoneDAO.getByProviderAndBasic(provider, basic.or(true)); }
From source file:org.jclouds.abiquo.domain.infrastructure.HypervisorType.java
public boolean supportsExtraHardDisks() { Optional<String> constraint = Optional.fromNullable(getConstraints().get("extra_hard_disk")); return Boolean.parseBoolean(constraint.or("true")); }
From source file:io.scigraph.annotation.EntityRecognizer.java
public Collection<Entity> getEntities(String token, EntityFormatConfiguration config) { Query query = new Vocabulary.Query.Builder(token).build(); List<Concept> terms = vocabulary.getConceptsFromTerm(query); Set<Entity> entities = newHashSet(); for (Concept term : terms) { if (shouldAnnotate(term, config)) { Optional<String> id = curieUtil.getCurie(term.getIri()); entities.add(new Entity(term.getLabels(), id.or(term.getIri()), term.getCategories())); }/*from w w w. j a v a 2s . c om*/ } return entities; }
From source file:org.knight.examples.guava.basic.UsingAvoidingNullExamples.java
public void run() { Optional<String> o1 = Optional.of("Guava-library"); if (o1.isPresent()) { log("o1: " + o1.get()); } else {//from w w w . j av a2s .co m log("o1: " + o1.toString()); } Optional<String> o2 = Optional.absent(); try { //will cause a IllegalStateException log("o2: " + o2.get()); } catch (IllegalStateException e) { log("o2 is absent, use get() will cause a IllegalStateException."); } Optional<String> o3 = Optional.fromNullable(null); log("o3 present = " + o3.isPresent()); try { //will cause a IllegalStateException log("o3: " + o3.get()); } catch (IllegalStateException e) { log("o3 is absent, use get() will cause a IllegalStateException."); } if (o3.orNull() == null) { log("o3 is absent, so orNull() returns null."); } Optional<String> o4 = Optional.fromNullable("Hello World"); log("o4: " + o4.or("o4 is present, so this default value will not be printed.")); Optional<Book> o5 = Optional.of(Book.generateBook()); log("o5: " + o5.get().toString()); }
From source file:ninja.rythm.template.TemplateEngineRythmI18nMessageResolver.java
@Override public String getMessage(ITemplate template, String key, Object... args) { Locale locale = null;//from www . j a v a 2s .c o m if (args.length > 0) { Object arg0 = args[0]; if (arg0 instanceof Locale) { locale = (Locale) arg0; Object[] args0 = new Object[args.length - 1]; System.arraycopy(args, 1, args0, 0, args.length - 1); args = args0; } } if (locale == null && template != null) { locale = (template == null) ? RythmEngine.get().renderSettings.locale() : template.__curLocale(); } Optional<String> lang = Optional.absent(); if (locale != null) { // to conform to rfc5646 and BCP 47 lang = Optional.of(locale.toString().replace('_', '-')); } Optional<String> i18nMessage = Optional.absent(); i18nMessage = messages.get(key, lang, args); return i18nMessage.or(""); }