List of usage examples for com.google.common.base Optional isPresent
public abstract boolean isPresent();
From source file:org.opennms.newts.rest.Transform.java
static Optional<Timestamp> toTimestamp(Optional<TimestampParam> value) { return value.isPresent() ? Optional.of(value.get().get()) : Optional.<Timestamp>absent(); }
From source file:org.eclipse.recommenders.examples.models.MappingWorkFlowExample.java
public static void useOfMapping(final IMappingProvider mapping) { DependencyInfo ed = null;//w w w .ja v a 2 s . c o m mapping.addStrategy(new MavenPomPropertiesStrategy()); IProjectCoordinateResolver mappingStrategy = mapping; Optional<ProjectCoordinate> optionalProjectCoordinate = mappingStrategy.searchForProjectCoordinate(ed); ProjectCoordinate projectCoordinate = null; if (optionalProjectCoordinate.isPresent()) { projectCoordinate = optionalProjectCoordinate.get(); } }
From source file:springfox.bean.validators.plugins.BeanValidators.java
public static <T extends Annotation> Optional<T> validatorFromField(ModelPropertyContext context, Class<T> annotationType) { Optional<AnnotatedElement> annotatedElement = context.getAnnotatedElement(); Optional<T> notNull = Optional.absent(); if (annotatedElement.isPresent()) { notNull = Optional.fromNullable(annotatedElement.get().getAnnotation(annotationType)); }//from w w w . j ava 2s . c o m return notNull; }
From source file:org.sonar.server.ws.WsUtils.java
public static <T> T checkFoundWithOptional(java.util.Optional<T> value, String message, Object... messageArguments) { if (!value.isPresent()) { throw new NotFoundException(format(message, messageArguments)); }// w w w . ja v a 2s .com return value.get(); }
From source file:com.facebook.buck.java.DiagnosticPrettyPrinter.java
private static void appendContext(StringBuilder builder, Diagnostic<? extends JavaFileObject> diagnostic, @Nullable JavaFileObject source) { if (source == null) { return;/*from w w w . jav a 2s. c o m*/ } Optional<String> line = getLine(source, diagnostic.getLineNumber()); if (line.isPresent()) { builder.append(line.get()).append("\n"); for (long i = 1; i < diagnostic.getColumnNumber(); i++) { builder.append(" "); } builder.append("^"); } }
From source file:com.empcraft.xpbank.util.ChunkUtil.java
public static Collection<Chunk> getLoadedChunksAroundLocation(Location loc, ExpBankConfig config) { Preconditions.checkNotNull(loc);//w ww .j av a2 s . co m final List<Chunk> chunkAroundList = new ArrayList<>(); final World world = loc.getWorld(); /* * In a imaginary 9x9 board, the player stands in the middle. * This small piece of code will check if nearby chunks in this board are loaded. * If so, they will be added to the around list. */ for (int x = -1; x <= 1; x++) { for (int z = -1; z <= 1; z++) { config.getLogger().log(Level.FINER, "Requesting Chunk at X:[" + x + "], Z:[" + z + "]."); Optional<Chunk> chunk = getLoadedChunk(world, loc.clone().add(x * 16.0D, 0.0D, z * 16.0D)); if (chunk.isPresent()) { chunkAroundList.add(chunk.get()); } } } return chunkAroundList; }
From source file:org.dswarm.graph.gdm.utils.NodeTypeUtils.java
public static Optional<NodeType> getNodeType(final Optional<Node> optionalNode, final Optional<Boolean> optionalIsType) { if (!optionalNode.isPresent()) { return Optional.absent(); }//from w ww. j av a 2 s. c o m return getNodeTypeByGDMNodeType(Optional.of(optionalNode.get().getType()), optionalIsType); }
From source file:google.registry.config.YamlUtils.java
/** * Recursively merges two YAML documents together. * * <p>Any fields that are specified in customYaml will override fields of the same path in * defaultYaml. Additional fields in customYaml that aren't specified in defaultYaml will be * ignored. The schemas of all fields that are present must be identical, e.g. it is an error to * override a field that has a Map value in the default YAML with a field of any other type in the * custom YAML./*from ww w. ja v a2 s .co m*/ * * <p>Only maps are handled recursively; lists are simply overridden in place as-is, as are maps * whose name is suffixed with "Map" -- this allows entire maps to be overridden, rather than * merged. */ static String mergeYaml(String defaultYaml, String customYaml) { Yaml yaml = new Yaml(); Map<String, Object> yamlMap = loadAsMap(yaml, defaultYaml).get(); Optional<Map<String, Object>> customMap = loadAsMap(yaml, customYaml); if (customMap.isPresent()) { yamlMap = mergeMaps(yamlMap, customMap.get()); logger.infofmt("Successfully loaded environment configuration YAML file."); } else { logger.infofmt("Ignoring empty environment configuration YAML file."); } return yaml.dump(yamlMap); }
From source file:gobblin.hive.HiveSchemaManager.java
/** * Get an instance of {@link HiveSchemaManager}. * * @param type The {@link HiveSchemaManager} type. It could be AVRO, NOP or the name of a class that implements * {@link HiveSchemaManager}. The specified {@link HiveSchemaManager} type must have a constructor that takes a * {@link State} object.// w ww . j a v a2s .c om * @param props A {@link State} object used to instantiate {@link HiveSchemaManager}. */ public static HiveSchemaManager getInstance(String type, State props) { Optional<Implementation> implementation = Enums.getIfPresent(Implementation.class, type.toUpperCase()); if (implementation.isPresent()) { try { return (HiveSchemaManager) ConstructorUtils .invokeConstructor(Class.forName(implementation.get().toString()), props); } catch (ReflectiveOperationException e) { throw new RuntimeException( "Unable to instantiate " + HiveSchemaManager.class.getSimpleName() + " with type " + type, e); } } else { log.info(String.format("%s with type %s does not exist. Using %s", HiveSchemaManager.class.getSimpleName(), type, HiveNopSchemaManager.class.getSimpleName())); return new HiveNopSchemaManager(props); } }
From source file:org.opendaylight.netvirt.openstack.netvirt.NetvirtProvider.java
public static boolean isMasterProviderInstance() { if (entityOwnershipService != null) { Optional<EntityOwnershipState> state = entityOwnershipService.getOwnershipState(ownerInstanceEntity); return state.isPresent() && state.get().isOwner(); }//from w w w. ja va 2s. c o m return false; }