List of usage examples for com.google.common.base Optional fromNullable
public static <T> Optional<T> fromNullable(@Nullable T nullableReference)
From source file:org.eclipse.che.plugin.gdb.ide.configuration.GdbConfigurationPagePresenter.java
private static String getBinaryPath(DebugConfiguration editedConfiguration) { Map<String, String> connectionProperties = editedConfiguration.getConnectionProperties(); Optional<String> binPathOptional = Optional .fromNullable(connectionProperties.get(BIN_PATH_CONNECTION_PROPERTY)); return binPathOptional.or(""); }
From source file:org.geogit.rest.repository.GeogitResourceUtils.java
public static Optional<String> getRepositoryName(Request request) { final String repo = RESTUtils.getAttribute(request, "repository"); if (repo != null && !repo.contains(":")) { throw new IllegalArgumentException( "Repository name should be of the form <workspace>:<datastore>: " + repo); }//from w w w.j ava2 s . c o m return Optional.fromNullable(repo); }
From source file:info.archinnov.achilles.type.Options.java
public Optional<ConsistencyLevel> getConsistencyLevel() { return Optional.fromNullable(consistency); }
From source file:gobblin.compliance.utils.DatasetUtils.java
public static String getProperty(HivePartitionDataset dataset, String property, long defaultValue) { Optional<String> propertyValueOptional = Optional.fromNullable(dataset.getParams().get(property)); if (!propertyValueOptional.isPresent()) { return Long.toString(defaultValue); }// w w w . ja v a2 s. c om try { long propertyVal = Long.parseLong(propertyValueOptional.get()); if (propertyVal < 0) { return Long.toString(defaultValue); } else { return Long.toString(propertyVal); } } catch (NumberFormatException e) { return Long.toString(defaultValue); } }
From source file:io.mesosphere.mesos.frameworks.cassandra.ZooKeeperSeedProviderConfig.java
private static Optional<Integer> optionalInteger(String key, Map<String, String> parameters) { Optional<String> stringOption = optionalString(key, parameters); if (stringOption.isPresent()) { try {//from w w w. ja va 2s.c om return Optional.fromNullable(Integer.parseInt(stringOption.get())); } catch (NumberFormatException nfe) { LOGGER.error(String.format("failed to parse %s", key), nfe); return Optional.absent(); } } else { return Optional.absent(); } }
From source file:net.es.nsi.pce.pf.PfUtils.java
public static String getSourceStpOrFail(P2PServiceBaseType p2ps) { Optional<String> sourceStp = Optional.fromNullable(Strings.emptyToNull(p2ps.getSourceSTP())); if (sourceStp.isPresent()) { return sourceStp.get(); }//from www . ja v a 2 s. c o m throw Exceptions.missingParameter(Point2PointTypes.getSourceStp().getNamespace(), Point2PointTypes.getSourceStp().getType(), "null"); }
From source file:com.googlesource.gerrit.plugins.github.git.GitHubUser.java
private static Optional<String> initFullName(GHUser gitHubUser) throws IOException { return Optional.fromNullable(gitHubUser != null ? Strings.emptyToNull(gitHubUser.getName()) : null); }
From source file:org.spongepowered.api.entity.living.meta.HorseColors.java
public static Optional<HorseColor> valueOf(String name) { return Optional.fromNullable(null); }
From source file:com.facebook.buck.java.JavaLibraryRules.java
static void addAccumulateClassNamesStep(JavaLibrary javaLibrary, BuildableContext buildableContext, ImmutableList.Builder<Step> steps) { Preconditions.checkNotNull(javaLibrary); Path pathToClassHashes = JavaLibraryRules.getPathToClassHashes(javaLibrary.getBuildTarget()); steps.add(new MkdirStep(pathToClassHashes.getParent())); steps.add(new AccumulateClassNamesStep(Optional.fromNullable(javaLibrary.getPathToOutputFile()), pathToClassHashes));//from w w w. j a va2 s .c om buildableContext.recordArtifact(pathToClassHashes); }
From source file:com.ngdata.hbaseindexer.util.solr.SolrConnectionParamUtil.java
public static int getSolrMaxConnectionsPerRoute(Map<String, String> connectionParameters) { return Integer.parseInt(Optional .fromNullable(connectionParameters.get(SolrConnectionParams.MAX_CONNECTIONS_PER_HOST)).or("128")); }