List of usage examples for com.google.common.base Optional absent
public static <T> Optional<T> absent()
From source file:im.dadoo.cas.server.dao.UserDao.java
public Optional<User> findById(int id) { Preconditions.checkArgument(id > 0, "id0"); MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("id", id); List<User> users = this.jdbcTemplate.query(FIND_BY_ID_SQL, sps, this.baseRowMapper); if (users != null && !users.isEmpty()) { return Optional.of(users.get(0)); } else {// w ww . j a va2s . c o m return Optional.absent(); } }
From source file:se.sics.sweep.webservice.toolbox.Result.java
public static Result ok(Object value) { return new Result(Status.OK, Optional.absent(), Optional.fromNullable(value)); }
From source file:de.uniulm.omi.cloudiator.sword.drivers.openstack.strategy.CompositeFloatingIpPoolStrategy.java
@Override public Optional<String> apply(String virtualMachine) { for (FloatingIpPoolStrategy strategy : strategies) { final Optional<String> optionalPool = strategy.apply(virtualMachine); if (optionalPool.isPresent()) { return optionalPool; }//from w ww.j ava2 s .c o m } return Optional.absent(); }
From source file:org.locationtech.geogig.porcelain.RemoteResolve.java
/** * Executes the remote-add operation./*from w ww . j a v a 2 s .com*/ * * @return the {@link Remote} that was added. */ @Override protected Optional<Remote> _call() { if (name == null || name.isEmpty()) { throw new RemoteException(StatusCode.MISSING_NAME); } Optional<Remote> result = Optional.absent(); ConfigDatabase config = configDatabase(); List<String> allRemotes = config.getAllSubsections("remote"); if (allRemotes.contains(name)) { String remoteSection = "remote." + name; Optional<String> remoteFetchURL = config.get(remoteSection + ".url"); Optional<String> remoteFetch = config.get(remoteSection + ".fetch"); Optional<String> remoteMapped = config.get(remoteSection + ".mapped"); Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch"); Optional<String> remoteUserName = config.get(remoteSection + ".username"); Optional<String> remotePassword = config.get(remoteSection + ".password"); if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) { Optional<String> remotePushURL = config.get(remoteSection + ".pushurl"); Remote remote = new Remote(name, remoteFetchURL.get(), remotePushURL.or(remoteFetchURL.get()), remoteFetch.get(), remoteMapped.or("false").equals("true"), remoteMappedBranch.orNull(), remoteUserName.orNull(), remotePassword.orNull()); result = Optional.of(remote); } } return result; }
From source file:org.eclipse.mylyn.internal.wikitext.commonmark.inlines.PotentialEmphasisDelimiter.java
@Override Optional<InlinesSubstitution> secondPass(List<Inline> inlines) { if (!canClose) { return Optional.absent(); }/*from w ww.j a va2s.c o m*/ int indexOfThis = inlines.indexOf(this); Optional<PotentialEmphasisDelimiter> opener = previousOpener(inlines, indexOfThis); if (opener.isPresent()) { PotentialEmphasisDelimiter openingDelimiter = opener.get(); int delimiterSize = delimiterSize(openingDelimiter); int indexOfOpeningDelimiter = inlines.indexOf(openingDelimiter); List<Inline> contents = InlineParser .secondPass(inlines.subList(indexOfOpeningDelimiter + 1, indexOfThis)); int spanOffset = openingDelimiter.getOffset(); int spanLength = getOffset() + getLength() - openingDelimiter.getOffset(); Inline emphasis = createEmphasis(openingDelimiter.getLine(), spanOffset, spanLength, delimiterSize, contents); ImmutableList.Builder<Inline> substitutionInlines = ImmutableList.builder(); if (delimiterSize < openingDelimiter.getLength()) { substitutionInlines.add(createPotentialOpeningDelimiter(openingDelimiter, delimiterSize)); } substitutionInlines.add(emphasis); if (delimiterSize < getLength()) { substitutionInlines.add(createPotentialClosingDelimiter(delimiterSize)); } return Optional.of(new InlinesSubstitution(openingDelimiter, this, substitutionInlines.build())); } return Optional.absent(); }
From source file:org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.resolving.ObjectNameAttributeResolvingStrategy.java
@Override public Optional<ObjectName> parseAttribute(String attrName, Object value) { if (value == null) { return Optional.absent(); }/*from ww w . jav a2 s . c o m*/ Util.checkType(value, ObjectNameAttributeMappingStrategy.MappedDependency.class); ObjectNameAttributeMappingStrategy.MappedDependency mappedDep = (ObjectNameAttributeMappingStrategy.MappedDependency) value; String serviceName = mappedDep.getServiceName(); String refName = mappedDep.getRefName(); String namespace = mappedDep.getNamespace(); LOG.trace("Getting service instance by service name {} : {} and ref name {}", namespace, serviceName, refName); ObjectName on = serviceTracker.getByServiceAndRefName(namespace, serviceName, refName); LOG.debug("Attribute {} : {} parsed to type {}", attrName, value, getOpenType()); return Optional.of(on); }
From source file:org.jclouds.cloudsigma2.domain.PaginatedCollection.java
@Override public Optional<Object> nextMarker() { if (paginationOptions.getLimit() == 0) { return Optional.absent(); }/* ww w . j ava 2 s . c o m*/ if (paginationOptions.getTotalCount() - paginationOptions.getOffset() > paginationOptions.getLimit()) { return Optional.of((Object) new PaginationOptions.Builder().limit(paginationOptions.getLimit()) .offset(paginationOptions.getOffset() + paginationOptions.getLimit()).build()); } return Optional.absent(); }
From source file:com.treasuredata.client.TDClientHttpException.java
public Optional<Date> getRetryAfter() { if (retryAfter == -1) { return Optional.absent(); } else {/*from w ww . java2 s. c o m*/ return Optional.of(new Date(retryAfter)); } }
From source file:org.eclipse.buildship.core.util.file.FileUtils.java
/** * Derives the absolute path from the specified {@code File} instance. * * @param file the file from which to get the absolute path * @return the absolute path if the file is not {@code null}, otherwise * {@link Optional#absent()}//w ww . j ava 2 s .co m */ public static Optional<String> getAbsolutePath(File file) { if (file == null) { return Optional.absent(); } else { return Optional.of(file.getAbsolutePath()); } }
From source file:nih.quack.jythonpygments.Lexers.java
/** * Lookup a Pygments lexer by an alias.// ww w .j a v a2s. c o m * * @param gateway * @param alias language alias for which a lexer is queried */ public Optional<Object> lookupLexer(PyGateway gateway, String alias) { Object result = lexerCache.get(alias); if (result == null) { result = evalLookupLexer(gateway, alias, NULL); lexerCache.put(alias, result); } if (result == NULL) { return Optional.absent(); } else { return Optional.of(result); } }