List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:org.locationtech.geogig.cli.Logging.java
static void tryConfigureLogging(Platform platform) { // instantiate and call ResolveGeogigDir directly to avoid calling getGeogig() and hence get // some logging events before having configured logging final Optional<URL> geogigDirUrl = new ResolveGeogigDir(platform).call(); if (!geogigDirUrl.isPresent() || !"file".equalsIgnoreCase(geogigDirUrl.get().getProtocol())) { // redirect java.util.logging to SLF4J anyways SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install();/*from w w w . j a v a 2s . c o m*/ return; } final File geogigDir; try { geogigDir = new File(geogigDirUrl.get().toURI()); } catch (URISyntaxException e) { throw Throwables.propagate(e); } if (geogigDir.equals(geogigDirLoggingConfiguration)) { return; } if (!geogigDir.exists() || !geogigDir.isDirectory()) { return; } final URL loggingFile = getOrCreateLoggingConfigFile(geogigDir); if (loggingFile == null) { return; } try { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); loggerContext.reset(); /* * Set the geogigdir variable for the config file can resolve the default location * ${geogigdir}/log/geogig.log */ loggerContext.putProperty("geogigdir", geogigDir.getAbsolutePath()); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(loggingFile); // redirect java.util.logging to SLF4J SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); geogigDirLoggingConfiguration = geogigDir; } catch (JoranException e) { LOGGER.error("Error configuring logging from file {}. '{}'", loggingFile, e.getMessage(), e); } }
From source file:org.opendaylight.faas.fabrics.vxlan.adapters.ovs.utils.OfFlowUtils.java
public static Table getTable(NodeBuilder nodeBuilder, short table, ReadOnlyTransaction readTx, final LogicalDatastoreType store) { try {//from w w w .jav a2s . co m Optional<Table> data = readTx.read(store, createTablePath(nodeBuilder, table)).get(); if (data.isPresent()) { return data.get(); } } catch (InterruptedException | ExecutionException e) { LOG.error("Failed to get table {}", table, e); } LOG.info("Cannot find data for table {} in {}", table, store); return null; }
From source file:org.opendaylight.vtn.manager.it.util.inventory.InventoryUtils.java
/** * Determine whether the given node has at least one edge port in up state * or not./*from w w w . j a va 2 s . co m*/ * * @param rtx A read-only MD-SAL datastore transaction. * @param nid The node identifier string. * @return {@code true} is returned if the given node has at least one * edge port in up state. Otherwise {@code false} is returned. */ public static boolean hasEdgePort(ReadTransaction rtx, String nid) { Optional<VtnNode> opt = DataStoreUtils.read(rtx, getVtnNodeIdentifier(nid)); return (opt.isPresent()) ? hasEdgePort(opt.get()) : false; }
From source file:org.onos.yangtools.yang.data.api.schema.tree.StoreTreeNodes.java
/** * Finds a node in tree//from ww w . j av a 2 s . c o m * * @param tree Data Tree * @param path Path to the node * @return Optional with node if the node is present in tree, {@link Optional#absent()} otherwise. */ public static <T extends StoreTreeNode<T>> Optional<T> findNode(final T tree, final YangInstanceIdentifier path) { Optional<T> current = Optional.<T>of(tree); Iterator<PathArgument> pathIter = path.getPathArguments().iterator(); while (current.isPresent() && pathIter.hasNext()) { current = current.get().getChild(pathIter.next()); } return current; }
From source file:springfox.documentation.spring.web.readers.operation.ResponseMessagesReader.java
public static int httpStatusCode(OperationContext context) { Optional<ResponseStatus> responseStatus = context.findAnnotation(ResponseStatus.class); int httpStatusCode = HttpStatus.OK.value(); if (responseStatus.isPresent()) { httpStatusCode = responseStatus.get().value().value(); }/*w w w .j a va 2s .c o m*/ return httpStatusCode; }
From source file:com.eucalyptus.util.async.AsyncExceptions.java
/** * Test if the given throwable was caused by a web service error with the specified code. * * @param throwable The possibly wer service caused throwable. * @param code The error code to test for * @return True if the throwable was caused by a web service error with the given code *//*from ww w . j a v a2 s . co m*/ public static boolean isWebServiceErrorCode(final Throwable throwable, final String code) { boolean codeMatch = false; final Optional<AsyncWebServiceError> serviceErrorOption = AsyncExceptions.asWebServiceError(throwable); if (serviceErrorOption.isPresent()) { codeMatch = code.equals(serviceErrorOption.get().getCode()); } return codeMatch; }
From source file:org.onos.yangtools.yang.data.impl.schema.tree.AbstractDataTreeCandidateNode.java
static DataTreeCandidateNode deltaChild( final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData, final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> newData, final PathArgument identifier) { final Optional<NormalizedNode<?, ?>> maybeNewChild = getChild(newData, identifier); final Optional<NormalizedNode<?, ?>> maybeOldChild = getChild(oldData, identifier); if (maybeOldChild.isPresent()) { final NormalizedNode<?, ?> oldChild = maybeOldChild.get(); if (maybeNewChild.isPresent()) { return AbstractRecursiveCandidateNode.replaceNode(oldChild, maybeNewChild.get()); } else {/*from w w w. ja v a 2 s . c o m*/ return TO_DELETED_NODE.apply(oldChild); } } else { if (maybeNewChild.isPresent()) { return TO_WRITTEN_NODE.apply(maybeNewChild.get()); } else { return null; } } }
From source file:org.opendaylight.controller.md.sal.dom.store.impl.tree.TreeNodeUtils.java
public static <T extends StoreTreeNode<T>> T findNodeChecked(final T tree, final InstanceIdentifier path) { T current = tree;/*from w ww .j av a2 s .c o m*/ List<PathArgument> nested = new ArrayList<>(path.getPath().size()); for (PathArgument pathArg : path.getPath()) { Optional<T> potential = current.getChild(pathArg); nested.add(pathArg); Preconditions.checkArgument(potential.isPresent(), "Child %s is not present in tree.", nested); current = potential.get(); } return current; }
From source file:utils.PasswordManager.java
/** * Encrypt a password. A master password must have been provided in the constructor. * @param plain A plain password to be encrypted. * @return The encrypted password./* ww w .ja v a2 s . c o m*/ */ public static String encryptPassword(String plain, Optional<String> masterPassword) { Optional<BasicTextEncryptor> encryptor = getEncryptor(masterPassword); Preconditions.checkArgument(getEncryptor(masterPassword).isPresent(), ERROR_ENCRY_MSG); try { return encryptor.get().encrypt(plain); } catch (Exception e) { throw new RuntimeException("Failed to encrypt password", e); } }
From source file:info.gehrels.voting.singleTransferableVote.VoteState.java
public static <CANDIDATE_TYPE extends Candidate> Optional<VoteState<CANDIDATE_TYPE>> forBallotAndElection( Ballot<CANDIDATE_TYPE> ballot, Election<CANDIDATE_TYPE> election) { validateThat(ballot, is(notNullValue())); validateThat(election, is(notNullValue())); Optional<Vote<CANDIDATE_TYPE>> vote = ballot.getVote(election); if (!vote.isPresent()) { return Optional.absent(); }/*w ww .j a va 2 s.c o m*/ return Optional.of(new VoteState<>(ballot.id, vote.get())); }