List of usage examples for com.google.common.base Optional of
public static <T> Optional<T> of(T reference)
From source file:com.shufudong.GuavaExample.collect.OptionalExample.java
/** * @return/*from ww w. j ava 2 s. co m*/ * @category <p>??</p> * <ol> * <li>Optional.of(T)Optional??nullT?T=null</li> * <li>Optional.absent()Optional?</li> * <li>Optional.fromNullable(T)T?OptionalT???[Optional.fromNullable(null)Optional.absent()</li> * </ol> * @throw */ public static void testOptional2() throws Exception { Optional<Integer> possible = Optional.of(6); Optional<Integer> absentOpt = Optional.absent(); Optional<Integer> NullableOpt = Optional.fromNullable(null); Optional<Integer> NoNullableOpt = Optional.fromNullable(10); if (possible.isPresent()) { System.out.println("possible isPresent:" + possible.isPresent()); System.out.println("possible value:" + possible.get()); } if (absentOpt.isPresent()) { System.out.println("absentOpt isPresent:" + absentOpt.isPresent()); } if (NullableOpt.isPresent()) { System.out.println("fromNullableOpt isPresent:" + NullableOpt.isPresent()); } if (NoNullableOpt.isPresent()) { System.out.println("NoNullableOpt isPresent:" + NoNullableOpt.isPresent()); } }
From source file:dagger.internal.codegen.writer.FieldWriter.java
public void setInitializer(String initializer, Object... args) { this.initializer = Optional.of(Snippet.format(initializer, args)); }
From source file:org.opendaylight.netvirt.qosservice.UuidUtil.java
Optional<Uuid> newUuidIfValidPattern(String possibleUuid) { Preconditions.checkNotNull(possibleUuid, "possibleUuid == null"); if (uuidPattern == null) { // Thread safe because it really doesn't matter even if we were to do this initialization more than once if (Uuid.PATTERN_CONSTANTS.size() != 1) { throw new IllegalStateException("Uuid.PATTERN_CONSTANTS.size() != 1"); }/* ww w .java 2 s . c o m*/ uuidPattern = Pattern.compile(Uuid.PATTERN_CONSTANTS.get(0)); } if (uuidPattern.matcher(possibleUuid).matches()) { return Optional.of(new Uuid(possibleUuid)); } else { return Optional.absent(); } }
From source file:ezbake.ezbroadcast.core.InMemoryBroadcaster.java
@Override protected Optional<byte[]> receiveImpl(String topic) throws IOException { return Optional.of(broadcasted.remove(topic)); }
From source file:info.rynkowski.hamsterclient.ui.AndroidApplication.java
private void initializeDependencyInjector() { this.applicationComponent = Optional .of(DaggerApplicationComponent.builder().applicationModule(new ApplicationModule(this)).build()); }
From source file:com.dangdang.ddframe.job.cloud.scheduler.ha.FrameworkIDService.java
/** * ?FrameworkID,?./*from ww w . j a v a2s . c om*/ * * @return ?FrameworkID? */ public Optional<String> fetch() { String frameworkId = regCenter.getDirectly(HANode.FRAMEWORK_ID_NODE); return Strings.isNullOrEmpty(frameworkId) ? Optional.<String>absent() : Optional.of(frameworkId); }
From source file:org.eclipse.buildship.core.util.binding.Validators.java
public static Validator<File> optionalDirectoryValidator(final String prefix) { return new Validator<File>() { @Override/*from w w w . ja va 2 s. c om*/ public Optional<String> validate(File file) { if (file == null) { return Optional.absent(); } else if (!file.exists()) { return Optional.of(NLS.bind(CoreMessages.ErrorMessage_0_DoesNotExist, prefix)); } else if (!file.isDirectory()) { return Optional.of(NLS.bind(CoreMessages.ErrorMessage_0_MustBeDirectory, prefix)); } else { return Optional.absent(); } } }; }
From source file:com.google.cloud.genomics.localrepo.BamFile.java
public static Optional<BamFile> create(File file) { return isReadableFile(file) && file.getName().endsWith(".bam") ? Optional.of(new BamFile(file)) : Optional.<BamFile>absent(); }
From source file:io.crate.analyze.KillAnalyzedStatement.java
public KillAnalyzedStatement(UUID jobId) { this.jobId = Optional.of(jobId); }
From source file:com.facebook.buck.android.ApkGenruleBuilder.java
public ApkGenruleBuilder setBash(String bash) { arg.bash = Optional.of(bash); return this; }