List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.util.Env.java
@NotNull public static String get(@NotNull final String key) { final Optional<String> opt = option(key); if (opt.isPresent()) { return opt.get(); } else {// ww w . j av a 2 s . c o m throw new IllegalStateException(String.format("Environment variable %s is not defined", key)); } }
From source file:com.facebook.buck.util.Optionals.java
public static <T> void addIfPresent(Optional<T> optional, ImmutableCollection.Builder<T> collection) { if (optional.isPresent()) { collection.add(optional.get()); }/* w w w . j a v a2 s . c om*/ }
From source file:info.rynkowski.hamsterclient.ui.utils.TimeConverter.java
public static @NonNull String toString(@NonNull Optional<Calendar> calendar, @NonNull String format) { if (calendar.isPresent()) { return toString(calendar.get(), format); }// www . jav a 2s.c o m return ""; }
From source file:org.igov.service.business.object.ObjectPlaceService.java
/** * This method allows to swap two entities by Primary Key (PK). * * @param entity - entity with new parameters * @param persistedEntity - persisted entity with registered PK in DB * @param dao - type-specific dao implementation **//*from ww w .j a v a 2 s . com*/ @SuppressWarnings("unchecked") public static <T extends AbstractEntity> boolean swap(T entity, Optional<T> persistedEntity, EntityDao dao) { if (persistedEntity.isPresent()) { entity.setId(persistedEntity.get().getId()); dao.saveOrUpdate(entity); return true; } return false; }
From source file:org.opendaylight.yangtools.yang.data.api.schema.tree.spi.AbstractContainerNode.java
static TreeNode getChildFromData(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data, final PathArgument childId, final Version version) { final Optional<NormalizedNode<?, ?>> child = data.getChild(childId); return child.isPresent() ? TreeNodeFactory.createTreeNode(child.get(), version) : null; }
From source file:org.raml.api.RamlTypes.java
public static RamlType fromType(Type type) { Optional<ScalarType> scalarTypeOptional = ScalarType.fromType(type); if (scalarTypeOptional.isPresent()) { return scalarTypeOptional.get(); }/*from w w w.j a v a 2 s .c om*/ throw new RuntimeException(format("unknown type: %s", type)); }
From source file:com.facebook.buck.util.Optionals.java
public static <K, T> void putIfPresent(Optional<T> optional, K key, ImmutableMap.Builder<K, T> collection) { if (optional.isPresent()) { collection.put(key, optional.get()); }/*from ww w . ja va 2s .c o m*/ }
From source file:org.apache.gobblin.util.JvmUtils.java
/** * Formats the specified jvm arguments such that any tokens are replaced with concrete values; * @param jvmArguments//from w w w . j a va 2 s . c o m * @return The formatted jvm arguments. */ public static String formatJvmArguments(Optional<String> jvmArguments) { if (jvmArguments.isPresent()) { return PORT_UTILS.replacePortTokens(jvmArguments.get()); } return StringUtils.EMPTY; }
From source file:org.fabrician.enabler.util.BuildCmdOptions.java
public static String buildAll(RuntimeContext rtc) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < rtc.getVariableCount(); i++) { RuntimeContextVariable var = rtc.getVariable(i); Optional<String> option = build(var); if (option.isPresent()) { sb.append(option.get()); }/*from ww w. j a v a 2 s . co m*/ } return sb.toString(); }
From source file:org.mayocat.image.ImageDataLoader.java
private static <T> Function<Optional<T>, T> extract() { return new Function<Optional<T>, T>() { public T apply(Optional<T> optional) { return optional.get(); }//ww w .j a va 2s. c o m }; }