List of usage examples for com.google.common.base Optional fromNullable
public static <T> Optional<T> fromNullable(@Nullable T nullableReference)
From source file:org.locationtech.geogig.api.plumbing.diff.DefaultGeometryDiffImpl.java
public DefaultGeometryDiffImpl(String s) { String[] tokens = s.split("\t"); Preconditions.checkArgument(tokens.length == 2, "Wrong difference definition:", s); oldGeom = Optional.fromNullable( (Geometry) TextValueSerializer.fromString(FieldType.forBinding(Geometry.class), tokens[0])); newGeom = Optional.fromNullable( (Geometry) TextValueSerializer.fromString(FieldType.forBinding(Geometry.class), tokens[1])); }
From source file:org.envirocar.server.core.util.pagination.Paginated.java
public Paginated(Pagination current, long elements) { this.current = Optional.fromNullable(current); this.elements = elements; if (this.current.isPresent()) { this.last = this.current.get().last(this.elements); this.first = this.current.get().first(this.elements); this.prev = this.current.get().previous(this.elements); this.next = this.current.get().next(this.elements); } else {// ww w .j av a2s. c o m Optional<Pagination> absent = Optional.absent(); this.last = absent; this.first = absent; this.prev = absent; this.next = absent; } }
From source file:io.macgyver.core.resource.ResourceProvider.java
public Optional<Resource> findResourceByHash(String hash) throws IOException { for (Resource r : findResources()) { if (r.getHash().equals(hash)) { return Optional.fromNullable(r); }/*from ww w . j a v a 2s . c o m*/ } return Optional.absent(); }
From source file:flipkart.mongo.replicator.core.model.ReplicationEvent.java
public ReplicationEvent(String operation, BsonTimestamp v, long h, String namespace, Document eventData, Document objectId) {/*ww w . j a v a2 s . c o m*/ this.v = v; this.h = h; this.eventData = eventData; this.objectId = Optional.fromNullable(objectId); this.namespace = namespace; String[] namespaceSplit = namespace.split("\\.", 2); this.databaseName = namespaceSplit[0]; this.collectionName = namespaceSplit[1]; this.operation = getOperationType(operation, eventData); }
From source file:com.preferanser.server.dao.objectify.Ofy.java
public <T> Optional<T> get(Key<T> key) { return Optional.fromNullable(load().key(key).now()); }
From source file:org.croudtrip.db.BasicCredentialsDAO.java
public Optional<BasicCredentials> findByUserId(long userId) { return Optional.fromNullable(uniqueResult(namedQuery(BasicCredentials.QUERY_NAME_FIND_BY_USER_ID) .setParameter(BasicCredentials.QUERY_PARAM_USER_ID, userId))); }
From source file:org.basepom.mojo.propertyhelper.beans.DateDefinition.java
public Optional<Long> getValue() { return Optional.fromNullable(value); }
From source file:org.apache.james.core.filesystem.SimpleUrl.java
private static void extractComponents(String urlWithUnixSeparators) { Matcher m = URL_REGEXP.matcher(urlWithUnixSeparators); m.matches();/*from w w w . j a v a 2s. com*/ protocol = Optional.fromNullable(m.group(1)).or(""); path = Optional.fromNullable(m.group(2)).or(""); }
From source file:org.apache.aurora.scheduler.updater.InstanceActionHandler.java
static Optional<IScheduledTask> getExistingTask(MutableStoreProvider storeProvider, IInstanceKey instance) { return Optional.fromNullable(Iterables.getOnlyElement( storeProvider.getTaskStore().fetchTasks(Query.instanceScoped(instance).active()), null)); }
From source file:org.geogit.api.Remote.java
/** * Constructs a new remote with the given parameters. * //from ww w. j av a 2 s .c om * @param name the name of the remote * @param fetchurl the fetch URL of the remote * @param pushurl the push URL of the remote * @param fetch the fetch string of the remote * @param mapped whether or not this remote is mapped * @param mappedBranch the branch the remote is mapped to */ public Remote(String name, String fetchurl, String pushurl, String fetch, boolean mapped, @Nullable String mappedBranch) { this.name = name; this.fetchurl = checkURL(fetchurl); this.pushurl = checkURL(pushurl); this.fetch = fetch; this.mapped = mapped; this.mappedBranch = Optional.fromNullable(mappedBranch).or("*"); }