List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:com.jivesoftware.sdk.utils.DateTimeUtils.java
public static String dateToIso(Optional<Date> date) { if (!date.isPresent()) { return null; }/*from w w w . j a v a 2 s .c o m*/ try { return fullISODate.format(date.get()); } catch (Exception e) { log.info("Failed converting date to ISO date string: " + date, e); return null; } }
From source file:com.mycelium.wallet.BitcoinUriWithAddress.java
public static Optional<BitcoinUriWithAddress> parseWithAddress(String uri, NetworkParameters network) { Optional<? extends BitcoinUri> bitcoinUri = BitcoinUri.parse(uri, network); if (!bitcoinUri.isPresent()) { return Optional.absent(); }//from w w w . j ava 2 s . co m return fromBitcoinUri(bitcoinUri.get()); }
From source file:com.google.gitiles.ArchiveFormat.java
static ArchiveFormat getDefault(Config cfg) { for (String allowed : cfg.getStringList("archive", null, "format")) { Optional<ArchiveFormat> result = Enums.getIfPresent(ArchiveFormat.class, allowed.toUpperCase()); if (result.isPresent()) { return result.get(); }/*from w w w .j a v a 2 s .c o m*/ } return TGZ; }
From source file:org.geogit.storage.sqlite.SQLiteStorage.java
/** * Returns the .geogit directory for the platform object. *//*from w w w . j a v a2 s. co m*/ public static File geogitDir(Platform platform) { Optional<URL> url = new ResolveGeogitDir(platform).call(); if (!url.isPresent()) { throw new RuntimeException("Unable to resolve .geogit directory"); } try { return new File(url.get().toURI()); } catch (URISyntaxException e) { throw new RuntimeException("Error resolving .geogit directory", e); } }
From source file:org.apache.gobblin.compliance.utils.ProxyUtils.java
public static FileSystem getOwnerFs(State state, Optional<String> owner) throws IOException { if (owner.isPresent()) { state.setProp(ComplianceConfigurationKeys.GOBBLIN_COMPLIANCE_PROXY_USER, owner.get()); }/* w w w .j a va 2 s.c om*/ ProxyUtils.setProxySettingsForFs(state); return WriterUtils.getWriterFs(state); }
From source file:org.opendaylight.unimgr.mef.nrp.common.MountPointHelper.java
/** * Find a node's NETCONF mount point and then retrieve its DataBroker. * e.g.//from w w w . ja va2s.c o m * http://localhost:8080/restconf/config/network-topology:network-topology/ * topology/topology-netconf/node/{nodeName}/yang-ext:mount/ */ public static Optional<DataBroker> getDataBroker(MountPointService mountService, String nodeName) { NodeId nodeId = new NodeId(nodeName); InstanceIdentifier<Node> nodeInstanceId = InstanceIdentifier.builder(NetworkTopology.class) .child(Topology.class, new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName()))) .child(Node.class, new NodeKey(nodeId)).build(); final Optional<MountPoint> nodeOptional = mountService.getMountPoint(nodeInstanceId); if (!nodeOptional.isPresent()) { return Optional.absent(); } MountPoint nodeMountPoint = nodeOptional.get(); return Optional.of(nodeMountPoint.getService(DataBroker.class).get()); }
From source file:org.fusesource.fabric.service.jclouds.functions.ToTemplate.java
public static Template apply(CreateJCloudsContainerOptions options) { ComputeService service = options.getComputeService(); TemplateOptions templateOptions = service.templateOptions(); TemplateBuilder builder = service.templateBuilder().any(); applyInstanceType(builder, options); applyImageType(builder, options);//from w w w .j a va 2 s . com applyLocation(builder, options); applyProviderSpecificOptions(templateOptions, options); Optional<AdminAccess> adminAccess = ToAdminAccess.apply(options); if (adminAccess.isPresent()) { templateOptions.runScript(adminAccess.get()); } builder = builder.options(templateOptions); return builder.build(); }
From source file:com.github.jeluard.extend.osgi.OSGILoader.java
private static <T> T setIfAbsentAndReturn(final AtomicReference<Optional<T>> reference, final Supplier<T> callable) { //TODO conc.//ww w .j ava 2 s .c o m final Optional<T> optionalValue = reference.get(); if (optionalValue.isPresent()) { return optionalValue.get(); } final T value = callable.get(); reference.set(Optional.fromNullable(value)); return value; }
From source file:io.urmia.md.model.job.JobGetRequest.java
public static ObjectRequest fromJobGetHttpRequest(String uri) { int loc = uri.indexOf("/stor/"); if (loc <= 0) throw new IllegalArgumentException("invalid job get uri: " + uri); String path = uri.substring(loc + 5); Optional<ObjectName> on = ObjectName.of(path); if (!on.isPresent()) throw new IllegalArgumentException("invalid job get path: " + path); return new ObjectRequest(on.get()); }
From source file:com.empcraft.xpbank.util.ChunkUtil.java
public static Collection<Chunk> getLoadedChunksAroundLocation(Location loc, ExpBankConfig config) { Preconditions.checkNotNull(loc);//w w w.j a v a 2 s . c om 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; }