List of usage examples for com.google.common.base Optional of
public static <T> Optional<T> of(T reference)
From source file:org.eclipse.buildship.core.util.gradle.GradleDistributionValidator.java
/** * Creates a new {@code Validator} instance. * * @return the new instance/* w w w . j a va2 s. c o m*/ */ public static Validator<GradleDistributionWrapper> gradleDistributionValidator() { return new Validator<GradleDistributionWrapper>() { @Override public Optional<String> validate(GradleDistributionWrapper gradleDistribution) { GradleDistributionWrapper.DistributionType type = gradleDistribution.getType(); String configuration = gradleDistribution.getConfiguration(); if (GradleDistributionWrapper.DistributionType.LOCAL_INSTALLATION == type) { if (Strings.isNullOrEmpty(configuration)) { return Optional.of(NLS.bind(CoreMessages.ErrorMessage_0_MustBeSpecified, CoreMessages.GradleDistribution_Label_LocalInstallationDirectory)); } else if (!new File(configuration).exists()) { return Optional.of(NLS.bind(CoreMessages.ErrorMessage_0_DoesNotExist, CoreMessages.GradleDistribution_Label_LocalInstallationDirectory)); } else { return Optional.absent(); } } else if (GradleDistributionWrapper.DistributionType.REMOTE_DISTRIBUTION == type) { if (Strings.isNullOrEmpty(configuration)) { return Optional.of(NLS.bind(CoreMessages.ErrorMessage_0_MustBeSpecified, CoreMessages.GradleDistribution_Label_RemoteDistributionUri)); } else if (!isValidURI(configuration)) { return Optional.of(NLS.bind(CoreMessages.ErrorMessage_0_IsNotValid, CoreMessages.GradleDistribution_Label_RemoteDistributionUri)); } else { return Optional.absent(); } } else if (GradleDistributionWrapper.DistributionType.VERSION == type) { if (Strings.isNullOrEmpty(configuration)) { return Optional.of(NLS.bind(CoreMessages.ErrorMessage_0_MustBeSpecified, CoreMessages.GradleDistribution_Label_SpecificGradleVersion)); } else { return Optional.absent(); } } else { return Optional.absent(); } } private boolean isValidURI(String configuration) { try { new URI(configuration); return true; } catch (URISyntaxException e) { return false; } } }; }
From source file:com.redhat.hss.bugzilla.model.Product.java
public Product(int id, String name, String description) { this.id = Optional.of(id); this.name = name; this.description = description; }
From source file:org.apache.james.transport.mailets.remoteDelivery.ExecutionResult.java
public static ExecutionResult permanentFailure(Exception e) { return new ExecutionResult(ExecutionState.PERMANENT_FAILURE, Optional.of(e)); }
From source file:springfox.documentation.swagger.readers.parameter.ParameterAnnotationReader.java
private static Optional<Method> interfaceMethod(Class<?> iface, Method method) { try {/*from w w w . ja va2 s. com*/ return Optional.of(iface.getMethod(method.getName(), method.getParameterTypes())); } catch (NoSuchMethodException ex) { return Optional.absent(); } }
From source file:flipkart.mongo.replicator.core.model.MongoV.java
public MongoV(int major, int minor, int patch) { this(major, minor, Optional.of(patch)); }
From source file:com.qcadoo.mes.basic.util.StaffNameExtractor.java
private static Optional<String> extract(final Entity staff, final String firstFieldName, final String secondFieldName) { if (staff == null) { return Optional.absent(); }// www. java 2 s .co m String firstFieldValue = staff.getStringField(firstFieldName); String secondFieldValue = staff.getStringField(secondFieldName); return Optional.of(String.format("%s %s", firstFieldValue, secondFieldValue)); }
From source file:org.opendaylight.yangtools.yang.data.impl.schema.tree.ReplaceLeafCandidateNode.java
@Nonnull @Override public Optional<NormalizedNode<?, ?>> getDataBefore() { return Optional.of(oldData); }
From source file:dagger2.internal.codegen.ValidationType.java
Optional<Diagnostic.Kind> diagnosticKind() { switch (this) { case ERROR:/* w ww . j av a 2 s. c om*/ return Optional.of(Diagnostic.Kind.ERROR); case WARNING: return Optional.of(Diagnostic.Kind.WARNING); default: return Optional.absent(); } }
From source file:org.eclipse.recommenders.codesearch.rcp.index.indexer.utils.IndexInformationCache.java
@Override public Optional<Long> getLastIndexed(final File location) { if (cache.containsKey(location)) { return Optional.of(cache.get(location)); }/*from w ww.j a v a 2s .co m*/ return Optional.absent(); }
From source file:org.fabrician.enabler.util.RunCmdAuxiliaryOptions.java
public static Optional<String> build(RuntimeContextVariable var) { try {/*from ww w. ja va 2 s . com*/ RunCmdAuxiliaryOptions val = valueOf(var.getName()); if (var.getTypeInt() != RuntimeContextVariable.OBJECT_TYPE) { String currentValue = StringUtils.trimToEmpty((String) var.getValue()); // empty value means the option is not valid and would be skipped // so that we accept the default if (!currentValue.isEmpty()) { if (val.isBooleanType) { Boolean b = BooleanUtils.toBooleanObject(currentValue); if (b != val.defaultBooleanValue) { return Optional.of(" " + val.optionSwitch + " "); } } else { return Optional.of(" " + val.optionSwitch + " " + currentValue); } } } } catch (Exception ex) { } return Optional.absent(); }