List of usage examples for com.google.common.base Optional of
public static <T> Optional<T> of(T reference)
From source file:org.geogit.api.porcelain.ConfigGet.java
/** * Executes the config command with the specified options. * /* www . j a va2s. c o m*/ * @return Optional<String> if querying for a value, empty Optional if no matching name was * found. * @throws ConfigException if an error is encountered. More specific information can be found in * the exception's statusCode. */ @Override public Optional<String> call() { ConfigScope scope = global ? ConfigScope.GLOBAL : ConfigScope.LOCAL; Optional<Map<String, String>> result = command(ConfigOp.class).setAction(ConfigAction.CONFIG_GET) .setName(name).setScope(scope).call(); if (result.isPresent()) { return Optional.of(result.get().get(name)); } else { return Optional.absent(); } }
From source file:fr.javatronic.damapping.test.mappermethod.MultiConstructorWithGenericsAndMultipleParameters.java
@Nullable public Optional<String> apply(@Nullable Map<C, Set<BigDecimal>> input, Object[] objs) { return Optional.of("doesn't matter"); }
From source file:google.registry.tools.params.OptionalParameterConverterValidator.java
@Override public final Optional<T> convert(String value) { if (value.equals(NULL_STRING) || value.isEmpty()) { return Optional.absent(); } else {/* w w w . j a v a2s. com*/ return Optional.of(validator.convert(value)); } }
From source file:fr.javatronic.damapping.test.guava.MultiConstructorWithGenerics.java
@Nullable @Override// www. jav a2s . c om public Optional<String> apply(@Nullable Map<C, Set<BigDecimal>> input) { return Optional.of("doesn't matter"); }
From source file:org.geoserver.jdbcstore.H2TestSupport.java
@Override public void stubConfig(JDBCResourceStoreProperties config) { expect(config.getInitScript())/*from w ww. j av a 2 s .c o m*/ .andStubReturn(URIs.asResource(JDBCResourceStoreProperties.class.getResource("init.h2.sql"))); expect(config.getJdbcUrl()).andStubReturn(Optional.of("jdbc:h2:mem:test")); expect(config.getJndiName()).andStubReturn(Optional.<String>absent()); expect(config.getProperty(eq("driverClassName"))).andStubReturn("org.h2.Driver"); expect(config.getProperty(eq("driverClassName"), (String) anyObject())).andStubReturn("org.h2.Driver"); }
From source file:se.sics.ktoolbox.util.config.options.InetAddressOption.java
@Override public Optional<InetAddress> readValue(Config config) { Optional ip = config.readValue(name); if (ip.isPresent()) { if (ip.get() instanceof InetAddress) { return ip; } else if (ip.get() instanceof String) { try { return Optional.of(InetAddress.getByName((String) ip.get())); } catch (UnknownHostException ex) { throw new RuntimeException(ex); }/* w ww . j a va2s .c om*/ } } return Optional.absent(); }
From source file:com.axemblr.provisionr.api.software.RepositoryBuilder.java
public RepositoryBuilder key(String key) { this.key = Optional.of(key); return this; }
From source file:com.infobip.jira.IssueKey.java
/** * Generates {@link IssueKey} from {@link Commit changesets} message. * * @param changeset containing message with Jira issue key * * @return first {@link IssueKey} that could be extracted, else {@link Optional#absent()} *///w w w . java 2 s. co m public static Optional<IssueKey> from(Commit changeset) { Matcher matcher = pattern.matcher(changeset.getMessage()); if (!matcher.find()) { return Optional.absent(); } return Optional.of(new IssueKey(new ProjectKey(matcher.group(1)), new IssueId(matcher.group(2)))); }
From source file:org.opendaylight.controller.netconf.cli.reader.impl.DecisionReader.java
public Optional<Boolean> read(final ConsoleIO console, final String questionMessageBlueprint, final Object... questionMessageArgs) throws IOException, ReadingException { final ConsoleContext ctx = getContext(); console.enterContext(ctx);/* www . j av a 2s . c o m*/ try { console.formatLn(questionMessageBlueprint, questionMessageArgs); final String rawValue = console.read(); if (YES.equals(rawValue.toUpperCase())) { return Optional.of(Boolean.TRUE); } else if (NO.equals(rawValue.toUpperCase())) { return Optional.of(Boolean.FALSE); } else if (SKIP.equals(rawValue)) { return Optional.absent(); } else { final String message = String.format("Incorrect possibility (%s) was selected", rawValue); Log.error(message); throw new ReadingException(message); } } finally { console.leaveContext(); } }
From source file:gobblin.writer.partitioner.TimeBasedAvroWriterPartitioner.java
private static Optional<List<String>> getWriterPartitionColumns(State state, int numBranches, int branchId) { String propName = ForkOperatorUtils.getPropertyNameForBranch(WRITER_PARTITION_COLUMNS, numBranches, branchId);/*w w w . j av a 2 s . c om*/ return state.contains(propName) ? Optional.of(state.getPropAsList(propName)) : Optional.<List<String>>absent(); }