List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:com.aegiswallet.widgets.AegisTypeface.java
public static void applyTypeface(TextView widget, Optional<Font> font) { Optional<Typeface> typeface = createTypeface(widget, font); if (typeface.isPresent()) { widget.setTypeface(typeface.get()); }/*from ww w . j a v a2s .c om*/ }
From source file:org.eclipse.buildship.core.workspace.internal.EclipseVmUtil.java
private static IVMInstall findOrRegisterVM(String version, File location) { Optional<IVMInstall> vm = findRegisteredVM(version); return vm.isPresent() ? vm.get() : registerNewVM("Java SE " + version, location); }
From source file:ec.nbdemetra.jdbc.OpenJndiJdbcDataSource.java
static void preFillBean(JdbcBean bean, Node node) { Optional<DatabaseConnection> dbConn = findConnection(node); if (dbConn.isPresent()) { bean.setDbName(dbConn.get().getDisplayName()); }/*from w ww . j a va 2 s . co m*/ if (isTableOrView(node)) { bean.setTableName(node.getName()); } }
From source file:org.opendaylight.faas.fabric.utils.InterfaceManager.java
@SuppressWarnings("unchecked") public static InstanceIdentifier<TerminationPoint> convDevPort2FabricPort(DataBroker broker, FabricId fabricid, InstanceIdentifier<TerminationPoint> tpIid) { ReadTransaction rt = broker.newReadOnlyTransaction(); Optional<TerminationPoint> opt = MdSalUtils.syncReadOper(rt, tpIid); if (opt.isPresent()) { TerminationPoint tp = opt.get(); return (InstanceIdentifier<TerminationPoint>) tp.getAugmentation(FabricPortAug.class).getPortRef() .getValue();/* w w w .j av a2 s .c o m*/ } return null; }
From source file:gobblin.writer.partitioner.TimeBasedAvroWriterPartitioner.java
/** * Check if the partition column value is present and is a Long object. Otherwise, use current system time. *//*from w w w .ja v a 2 s. c om*/ private static long getRecordTimestamp(Optional<Object> writerPartitionColumnValue) { return writerPartitionColumnValue.orNull() instanceof Long ? (Long) writerPartitionColumnValue.get() : System.currentTimeMillis(); }
From source file:com.complexible.common.base.Copyables.java
/** * If the {@link Optional} has ({@link Optional#isPresent isPresent a value} a {@link Copyable#copy} is made of the object. * Otherwise, with an absent value, the Optional is returned as-is * * @param theObj the object to copy//from www .j av a 2 s. c o m * @param <T> the object's type * @return an Optional which contains a copy of the object if a value is present on the optional. */ public static <T> Optional<T> copy(final Optional<T> theObj) { if (theObj.isPresent()) { return Optional.of(copy(theObj.get())); } else { // no value, no need to make a copy return theObj; } }
From source file:org.apache.gobblin.compliance.utils.ProxyUtils.java
@SafeVarargs public static HiveProxyQueryExecutor getQueryExecutor(State state, Optional<String>... owners) throws IOException { List<String> proxies = new ArrayList<>(); for (Optional<String> owner : owners) { if (owner.isPresent()) { proxies.add(owner.get()); }/*from ww w. jav a 2 s .co m*/ } return new HiveProxyQueryExecutor(state, proxies); }
From source file:org.fabrician.enabler.util.DockerActivationInfo.java
public static DockerActivationInfo inject(final ActivationInfo info, final String containerIdentity, final DockerClient client) { Optional<Container> c = client.inspectContainer(containerIdentity); if (c.isPresent()) { DockerActivationInfo.instance(info, c.get()).inject(); }// w w w.ja v a2 s. c o m return DockerActivationInfo.instance(info, null); }
From source file:com.shufudong.GuavaExample.collect.OptionalExample.java
/** * @return//from w w w. j av a 2s . c o m * @category <p></p> * <ol> * <li> boolean isPresent()Optional?T?nulltrueTnullfalse</li> * <li>T get()Optional?TT???nullOptionalget()IllegalStateException</li> * <li>T or(T)Optional?T?Optional?T?T</li> * <li>T orNull()Optional??TOptional?null?fromNullable()</li> * <li>Set<T> asSet()??SetSet?Optional??TSet?T??Optional?T??Set</li> * </ol> * @throw */ public static void testMethodReturn() { Optional<Long> value = method(); if (value.isPresent() == true) { System.out.println(": " + value.get()); } else { System.out.println(": " + value.or(-12L)); } System.out.println(" orNull: " + value.orNull()); Optional<Long> valueNoNull = methodNoNull(); if (valueNoNull.isPresent() == true) { Set<Long> set = valueNoNull.asSet(); System.out.println(" set size : " + set.size()); System.out.println(": " + valueNoNull.get()); } else { System.out.println(": " + valueNoNull.or(-12L)); } System.out.println(" orNull: " + valueNoNull.orNull()); }
From source file:org.opendaylight.faas.fabric.utils.InterfaceManager.java
@SuppressWarnings("unchecked") public static InstanceIdentifier<TerminationPoint> convFabricPort2DevicePort(DataBroker broker, FabricId fabricid, TpId tpid) {// w w w . j a v a 2 s .c om InstanceIdentifier<TerminationPoint> iidFPort = MdSalUtils.createFabricPortIId(fabricid, tpid); ReadTransaction rt = broker.newReadOnlyTransaction(); Optional<TerminationPoint> opt = MdSalUtils.syncReadOper(rt, iidFPort); if (opt.isPresent()) { TerminationPoint tp = opt.get(); return (InstanceIdentifier<TerminationPoint>) tp.getAugmentation(FabricPortAugment.class) .getFportAttribute().getDevicePort().getValue(); } return null; }