List of usage examples for com.google.common.base Optional fromNullable
public static <T> Optional<T> fromNullable(@Nullable T nullableReference)
From source file:org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource.java
public static SourceIdentifier identifierFromFilename(final String name) { final String baseName; if (name.endsWith(YangConstants.RFC6020_YIN_FILE_EXTENSION)) { baseName = name.substring(0, name.length() - YangConstants.RFC6020_YIN_FILE_EXTENSION.length()); } else if (name.endsWith(XML_EXTENSION)) { // FIXME: BUG-7061: remove this once we do not need it LOG.warn("XML file {} being loaded as YIN", name); baseName = name.substring(0, name.length() - XML_EXTENSION.length()); } else {/*from w w w. ja v a 2 s .com*/ throw new IllegalArgumentException("Filename " + name + " does not have a .yin or .xml extension"); } final Entry<String, String> parsed = YangNames.parseFilename(baseName); return RevisionSourceIdentifier.create(parsed.getKey(), Optional.fromNullable(parsed.getValue())); }
From source file:com.facebook.buck.util.environment.MacWifiSsidFinder.java
/** * Finds the SSID of the default Wi-Fi interface using Mac OS X APIs. *//*from www. j a v a 2s.co m*/ public static Optional<String> findCurrentSsid() { LOG.debug("Getting current SSID.."); // Grab a handle to the Objective-C runtime. Client objcClient = Client.getInstance(); // Try the OS X 10.10 and later supported API, then fall // back to the OS X 10.6 API. Pointer wifiClientClass = RuntimeUtils.cls("CWWiFiClient"); Optional<Proxy> defaultInterface; if (wifiClientClass != null) { LOG.verbose("Getting default interface using +[CWWiFiClient sharedWiFiClient]"); defaultInterface = getDefaultWifiInterface(objcClient, wifiClientClass); } else { LOG.verbose("Getting default interface using +[CWInterface defaultInterface]"); // CWInterface *defaultInterface = [CWInterface interface]; defaultInterface = Optional.fromNullable(objcClient.sendProxy("CWInterface", "interface")); } return getSsidFromInterface(defaultInterface); }
From source file:com.googlecode.blaisemath.style.ImmutableAttributeSet.java
/** * Makes an immutable copy of the provided attribute set. * @param set the set to copy//from w w w .java 2 s . co m * @param par the parent * @return an immutable copy */ static ImmutableAttributeSet immutableCopyOf(AttributeSet set, @Nullable AttributeSet par) { ImmutableAttributeSet res = new ImmutableAttributeSet(); res.parent = Optional.fromNullable(par); res.attributeMap.putAll(set.attributeMap); return res; }
From source file:storm.mesos.logviewer.LogViewerController.java
public LogViewerController(Map conf) { port = Optional.fromNullable((Number) conf.get(Config.LOGVIEWER_PORT)).or(8000).intValue(); setUrlDetector(new SocketUrlDetection(port)); }
From source file:at.ac.univie.isc.asio.nest.InferJdbcSchema.java
@Nonnull @Override// w w w. java 2s . co m public NestConfig apply(final NestConfig input) { final Jdbc jdbc = input.getJdbc(); final Optional<String> dataset = Optional.fromNullable(input.getDataset().getName()) .transform(Functions.toStringFunction()); if (jdbc.getSchema() == null) { jdbc.setSchema(JdbcTools.inferSchema(jdbc.getUrl()).or(dataset).orNull()); } return input; }
From source file:io.crate.sql.tree.ShowSchemas.java
public ShowSchemas(@Nullable String likePattern, @Nullable Expression whereExpr) { this.likePattern = Optional.fromNullable(likePattern); this.whereExpression = Optional.fromNullable(whereExpr); }
From source file:org.jclouds.ultradns.ws.xml.UltraWSExceptionHandler.java
@Override public UltraDNSWSError getResult() { return code != -1 ? UltraDNSWSError.fromCodeAndDescription(code, Optional.fromNullable(description)) : null; }
From source file:com.comoyo.commons.amazonaws.AwsEC2InstanceIdentity.java
/** * Find AWS EC2 instance metadata for running host. * * @return optionally, a map of [key, value] pairs describing the * hosting EC2 instance.// w w w.j av a 2 s . com */ public static Optional<Map<String, String>> getMetadata() { final Optional<Map<String, String>> metadata = metadataRef.get(); if (metadata != null) { return metadata; } if (hypervisorAbsent()) { metadataRef.set(Optional.<Map<String, String>>absent()); return metadataRef.get(); } final ObjectMapper mapper = new ObjectMapper(); try { final URL url = new URL(INSTANCE_DATA_URL); final URLConnection connection = url.openConnection(); connection.setConnectTimeout(CONNECT_TIMEOUT_MS); connection.connect(); final Map<String, String> response = mapper.readValue(connection.getInputStream(), new TypeReference<Map<String, String>>() { }); metadataRef.set(Optional.fromNullable(response != null ? Collections.unmodifiableMap(response) : null)); } catch (IOException e) { metadataRef.set(Optional.<Map<String, String>>absent()); } return metadataRef.get(); }
From source file:org.opendaylight.distributed.tx.spi.CachedData.java
/** * Get the data from cache. * * @return optional of the data object. */ public Optional<DataObject> getData() { return Optional.fromNullable(data); }
From source file:io.crate.sql.tree.OptimizeStatement.java
public OptimizeStatement(List<Table> tables, @Nullable GenericProperties properties) { this.tables = tables; this.properties = Optional.fromNullable(properties); }