List of usage examples for com.google.common.base Optional of
public static <T> Optional<T> of(T reference)
From source file:internal.msm.spikes.dw.server.health.TemplateHealthCheck.java
@Override protected Result check() throws Exception { template.render(Optional.of("woo")); template.render(Optional.<String>absent()); return Result.healthy(); }
From source file:org.code_house.ebus.common.BasicCodecRegistry.java
@Override public <T, R> Optional<CommandCodec<T, R>> find(Command<T, R> command) { if (codecs.containsKey(command)) { return Optional.of(codecs.get(command)); }/*from w ww .j a v a 2 s . c o m*/ return Optional.absent(); }
From source file:com.stepstone.sonar.plugin.coldfusion.cflint.xml.LocationAttributes.java
public LocationAttributes(XMLStreamReader stream) { file = getAttributeValue("file", stream); message = getAttributeValue("message", stream); Optional<String> line = getAttributeValue("line", stream); if (line.isPresent()) { this.line = Optional.of(Integer.parseInt(line.get())); } else {// ww w. j a v a 2s.c o m this.line = Optional.absent(); } }
From source file:eu.thebluemountain.customers.dctm.brownbag.badcontentslister.Command.java
/** * The method that parses the elements in the arguments to build a map * containing the commands and the related value if any * @param args carries the command-line arguments * @return the commands/*from ww w. j a v a2s. c o m*/ */ public static Map<Command, Optional<String>> parse(String[] args) { final int size = args.length; Map<Command, Optional<String>> cmds = Maps.newHashMap(); for (int index = 0; index < size; index++) { Command cmd = of(args[index]); Preconditions.checkArgument(!cmds.containsKey(cmd), "duplicate arguments introducing command %s", cmd); if (cmd.requiresvalue) { index++; Preconditions.checkArgument(index < size, "command '%s' requires missing value", cmd); String value = args[index]; cmds.put(cmd, Optional.of(value)); } else { cmds.put(cmd, Optional.<String>absent()); } } return cmds; }
From source file:org.eclipse.mylyn.internal.wikitext.commonmark.inlines.HtmlEntitySpan.java
@Override public Optional<? extends Inline> createInline(Cursor cursor) { char c = cursor.getChar(); if (c == '&') { Matcher matcher = cursor.matcher(pattern); if (matcher.matches()) { String ent = matcher.group(1); return Optional .of(new HtmlEntity(cursor.getLineAtOffset(), cursor.getOffset(), ent.length() + 2, ent)); }//from w w w . j a va2 s.c om } return Optional.absent(); }
From source file:controllers.ApiController.java
public Result getMessageWithParamsJson(@PathParam("key") String key, Context ctx, @Params(value = "params") String[] params) { Result result = Results.json(); Optional<Result> optResult = Optional.of(result); Optional<String> message = msg.get(key, ctx, optResult, params); if (message.isPresent() == false) { return result.render(new Error(msg.get("error.notFound", ctx, optResult, key).get())); }// ww w . j a va2 s .com return result.render(new Message(key, message.get())); }
From source file:bear.task.TaskResult.java
public static <T extends TaskResult<?>> Optional<T> okOrAbsent(@Nullable T result) { if (result != null && result.ok()) return Optional.of(result); return Optional.absent(); }
From source file:gg.uhc.fancyfreeze.uhc.UhcModule.java
public static Optional<UhcModule> hook(Plugin uhcPlugin, Freezer freezer) { UhcModule module = new UhcModule(freezer); boolean loaded = ((UHC) uhcPlugin).getRegistry().register(module); if (loaded)//from w w w . j a v a 2s .c o m return Optional.of(module); return Optional.absent(); }
From source file:net.wouterdanes.docker.remoteapi.exception.DockerException.java
public DockerException(final String message, final String apiResponse) { super(message); this.apiResponse = Optional.of(apiResponse); }
From source file:org.opendaylight.controller.config.yang.store.impl.YangStoreActivator.java
@Override public void start(BundleContext context) throws Exception { // get blacklist Optional<Pattern> maybeBlacklistPattern = Optional.absent(); String blacklist = context.getProperty("yangstore.blacklist"); if (blacklist != null) { try {// w w w. j a v a2 s. c o m maybeBlacklistPattern = Optional.of(Pattern.compile(blacklist)); } catch (RuntimeException e) { logger.error("Cannot parse blacklist regex " + blacklist, e); throw e; } } ExtenderYangTracker extenderYangTracker = new ExtenderYangTracker(maybeBlacklistPattern, context); Dictionary<String, ?> properties = new Hashtable<>(); context.registerService(YangStoreService.class, extenderYangTracker, properties); }