List of usage examples for com.google.common.base Optional of
public static <T> Optional<T> of(T reference)
From source file:com.viadeo.kasper.exposition.http.jetty.resource.KasperDocResource.java
@GET @Path("domain/{domainName}/{type}") @Produces(MediaType.APPLICATION_JSON)/* w ww . j a v a 2 s .co m*/ public Object getEntities(@PathParam("domainName") final String domainName, @PathParam("type") final String type) { if (null == domainName) { return new RetUnexistent(DocumentedElementType.DOMAIN.getType(), DEFAULT_UNSPECIFIED); } final Optional<DocumentedDomain> domain = documentedPlatform.getDomain(domainName); if (!domain.isPresent()) { return new RetUnexistent(DocumentedElementType.DOMAIN.getType(), domainName); } final Optional<DocumentedElementType> documentedElementType = DocumentedElementType.of(type); if (documentedElementType.isPresent() && documentedElementType.get().getPluralType().equals(type)) { final DocumentedElementType elementType = documentedElementType.get(); final List<AbstractDomainElement> documentedElements = get(domain.get(), elementType); return new RetMap(elementType.getType(), documentedElements); } return new RetUnexistent("type", type); }
From source file:com.viadeo.kasper.exposition.http.jetty.resource.KasperDocResource.java
@GET @Path("domain/{domainName}/{type}/{entityName}") @Produces(MediaType.APPLICATION_JSON)//from w w w .jav a2s .c om public Object getEntity(@PathParam("domainName") final String domainName, @PathParam("type") final String type, @PathParam("entityName") final String entityName) { if (null == domainName) { return new RetUnexistent(DocumentedElementType.DOMAIN.getType(), DEFAULT_UNSPECIFIED); } final Optional<DocumentedDomain> domain = documentedPlatform.getDomain(domainName); if (!domain.isPresent()) { return new RetUnexistent(DocumentedElementType.DOMAIN.getType(), DEFAULT_UNSPECIFIED); } final Optional<DocumentedElementType> documentedElementType = DocumentedElementType.of(type); if (documentedElementType.isPresent()) { final DocumentedElementType elementType = documentedElementType.get(); final Optional<AbstractDomainElement> documentedElement = get(domain.get(), elementType, entityName); if (documentedElement.isPresent()) { return documentedElement.get(); } return new RetUnexistent(elementType.getType(), entityName); } return new RetUnexistent("type", type); }
From source file:gobblin.runtime.task.TaskUtils.java
/** * Parse the {@link TaskFactory} in the state if one is defined. *//*from w w w .j ava 2 s. c om*/ public static Optional<TaskFactory> getTaskFactory(State state) { try { if (state.contains(TASK_FACTORY_CLASS)) { return Optional.of((TaskFactory) Class.forName(state.getProp(TASK_FACTORY_CLASS)).newInstance()); } else { return Optional.absent(); } } catch (ReflectiveOperationException roe) { throw new RuntimeException("Could not create task factory.", roe); } }
From source file:org.brooklyncentral.catalog.scrape.CatalogItemScraper.java
private static Optional<String> getGithubRawText(String repoUrl, String fileName) { String rawGithubUrl = generateRawGithubUrl(repoUrl, fileName); try (InputStream inputStream = new URL(rawGithubUrl).openStream()) { return Optional.of(Streams.readFullyString(inputStream)); } catch (Exception e) { // TODO Log or something: String error = // "Unable to read raw Github URL " + rawGithubUrl + ": " + e, // e);/*from w w w . ja va2 s . c om*/ return Optional.absent(); } }
From source file:com.google.devtools.build.lib.syntax.compiler.LoopLabels.java
/** * Only use Optional-wrapped instances of this class. *///from ww w . j a va 2s .c o m public static Optional<LoopLabels> of(Label continueLabel, Label breakLabel) { return Optional.of(new LoopLabels(continueLabel, breakLabel)); }
From source file:com.ayuget.redface.util.UserUtils.java
/** * Ugly method to fetch a user id from stored cookies *///from w ww . j a v a2 s.c o m public static Optional<Integer> getLoggedInUserId(User user, OkHttpClient httpClient) { CookieManager cookieManager = (CookieManager) httpClient.getCookieHandler(); CookieStore cookieStore = cookieManager.getCookieStore(); for (HttpCookie cookie : cookieStore.getCookies()) { if (cookie.getName().equals("md_id")) { return Optional.of(Integer.valueOf(cookie.getValue())); } } return Optional.absent(); }
From source file:de.flapdoodle.guava.Expectations.java
private static <T> Optional<T> intNoneOrOne(Iterator<T> iterator) { Preconditions.checkNotNull(iterator, "iterator is null"); if (!iterator.hasNext()) { return Optional.absent(); }//from w ww. j a v a 2 s . co m return Optional.of(iterator.next()); }
From source file:org.puder.trs80.ActivityHelper.java
/** * Returns an extra value with the given key, if the intent, the extras and the key itself are * present./* w ww . j a v a 2s .co m*/ */ static Optional<Integer> getIntExtra(Intent intent, String key) { if (intent == null) { Log.i(TAG, "No intent."); return Optional.absent(); } if (!intent.hasExtra(key)) { Log.i(TAG, StrUtil.form("No extra named '%s'.", key)); return Optional.absent(); } return Optional.of(intent.getIntExtra(key, 0)); }
From source file:com.google.template.soy.types.VeType.java
public static VeType of(String dataType) { Preconditions.checkNotNull(dataType); if (NullType.getInstance().toString().equals(dataType)) { return NO_DATA; }// w ww . j a v a 2 s .co m return new VeType(Optional.of(dataType)); }
From source file:com.facebook.buck.cli.JavaUtilLogHandlers.java
public static Optional<ConsoleHandler> getConsoleHandler() { // We can't stop someone from mutating this array, but we can minimize the chance. ImmutableList<Handler> handlers = ImmutableList.copyOf(Logger.getLogger("").getHandlers()); for (Handler handler : handlers) { if (handler instanceof ConsoleHandler) { return Optional.of((ConsoleHandler) handler); } else if (handler instanceof Callable<?>) { // com.facebook.buck.cli.bootstrapper.ConsoleHandler is not // visible to us, so thunk it through Callable<Handler> so // we can get at the real ConsoleHandler. Callable<?> callable = (Callable<?>) handler; try { Object innerHandler = callable.call(); if (innerHandler instanceof ConsoleHandler) { return Optional.of((ConsoleHandler) innerHandler); }//from w ww .ja v a2s . c o m } catch (Exception e) { throw new RuntimeException(e); } } } // If we hit this, something has gone wrong and we can't find the // ConsoleHandler from the list of registered log handlers. // // This means SuperConsole will not be notified when we print log // messages to console, so it will not disable itself, causing log // console logs to collide with SuperConsole output. System.err.println("WARNING: Cannot find ConsoleHandler log handler. " + "Logs printed to console will likely be lost."); return Optional.absent(); }