List of usage examples for com.google.common.base Optional orNull
@Nullable public abstract T orNull();
From source file:zipkin.autoconfigure.storage.elasticsearch.http.ZipkinElasticsearchHttpStorageAutoConfiguration.java
public static Optional<String> regionFromAwsUrls(List<String> hosts) { Optional<String> awsRegion = Optional.absent(); for (String url : hosts) { Matcher matcher = AWS_URL.matcher(url); if (matcher.find()) { String matched = matcher.group(1); checkArgument(awsRegion.or(matched).equals(matched), "too many regions: saw '%s' and '%s'", awsRegion, matched); awsRegion = Optional.of(matcher.group(1)); } else {/*w w w . j a v a 2s. co m*/ checkArgument(!awsRegion.isPresent(), "mismatched regions; saw '%s' but no awsRegion found in '%s'", awsRegion.orNull(), url); } } return awsRegion; }
From source file:com.twitter.common.args.ArgumentInfo.java
/** * Extracts the {@code Arg} from the given field. * * @param field The field containing the {@code Arg}. * @param instance An optional object instance containing the field. * @return The extracted {@code} Arg.//from w w w . j a v a 2s .c om * @throws IllegalArgumentException If the field does not contain an arg. */ protected static Arg<?> getArgForField(Field field, Optional<?> instance) { Preconditions.checkArgument(field.getType() == Arg.class, "Field is annotated for argument parsing but is not of Arg type: " + field); Preconditions.checkArgument(Modifier.isStatic(field.getModifiers()) || instance.isPresent(), "Non-static argument fields are not supported, found " + field); field.setAccessible(true); try { return (Arg<?>) field.get(instance.orNull()); } catch (IllegalAccessException e) { throw new RuntimeException("Cannot get arg value for " + field); } }
From source file:org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.java
public static Lsp createLsp(final long plspId, final boolean sync, final Optional<Tlvs> tlvs, final boolean isDelegatedLsp, final boolean remove) { final LspBuilder lspBuilder = new LspBuilder(); lspBuilder.setAdministrative(true);//www .j a v a2 s.com lspBuilder.setDelegate(isDelegatedLsp); lspBuilder.setIgnore(false); lspBuilder.setOperational(OperationalStatus.Up); lspBuilder.setPlspId(new PlspId(plspId)); lspBuilder.setProcessingRule(false); lspBuilder.setRemove(remove); lspBuilder.setSync(sync); lspBuilder.setTlvs(tlvs.orNull()); return lspBuilder.build(); }
From source file:zipkin.autoconfigure.storage.elasticsearch.aws.ZipkinElasticsearchAwsStorageAutoConfiguration.java
static Optional<String> regionFromAwsUrls(List<String> hosts) { Optional<String> awsRegion = Optional.absent(); for (String url : hosts) { Matcher matcher = AWS_URL.matcher(url); if (matcher.find()) { String matched = matcher.group(1); checkArgument(awsRegion.or(matched).equals(matched), "too many regions: saw '%s' and '%s'", awsRegion, matched); awsRegion = Optional.of(matcher.group(1)); } else {/*w w w . j av a 2 s. c o m*/ checkArgument(!awsRegion.isPresent(), "mismatched regions; saw '%s' but no awsRegion found in '%s'", awsRegion.orNull(), url); } } return awsRegion; }
From source file:org.locationtech.geogig.spring.service.AbstractRepositoryService.java
public Repository getRepository(RepositoryProvider provider, String repoName) { Optional<Repository> geogig = provider.getGeogig(repoName); return geogig.orNull(); }
From source file:org.onos.yangtools.yang.data.impl.codec.Int8StringCodec.java
protected Int8StringCodec(final Optional<IntegerTypeDefinition> typeDef) { super(typeDef, extractRange(typeDef.orNull()), Byte.class); }
From source file:org.onos.yangtools.yang.data.impl.codec.Int16StringCodec.java
protected Int16StringCodec(final Optional<IntegerTypeDefinition> typeDef) { super(typeDef, extractRange(typeDef.orNull()), Short.class); }
From source file:org.onos.yangtools.yang.data.impl.codec.Int32StringCodec.java
protected Int32StringCodec(final Optional<IntegerTypeDefinition> typeDef) { super(typeDef, extractRange(typeDef.orNull()), Integer.class); }
From source file:org.onos.yangtools.yang.data.impl.codec.Int64StringCodec.java
protected Int64StringCodec(final Optional<IntegerTypeDefinition> typeDef) { super(typeDef, extractRange(typeDef.orNull()), Long.class); }
From source file:org.opendaylight.yangtools.yang.data.impl.codec.Int16StringCodec.java
Int16StringCodec(final Optional<IntegerTypeDefinition> typeDef) { super(typeDef, extractRange(typeDef.orNull()), Short.class); }