List of usage examples for com.google.common.base Optional of
public static <T> Optional<T> of(T reference)
From source file:google.registry.tldconfig.idn.IdnLabelValidator.java
/** * Returns name of first matching {@link IdnTable} if domain label is valid for the given TLD. * * <p>A label is valid if it is considered valid by at least one configured IDN table for that * TLD. If no match is found, an absent value is returned. *//*from ww w . j ava 2 s.c o m*/ public static Optional<String> findValidIdnTableForTld(String label, String tld) { String unicodeString = Idn.toUnicode(label); for (IdnTableEnum idnTable : Optional.fromNullable(idnTableListsPerTld.get(tld)).or(DEFAULT_IDN_TABLES)) { if (idnTable.getTable().isValidLabel(unicodeString)) { return Optional.of(idnTable.getTable().getName()); } } return Optional.absent(); }
From source file:org.eclipse.mylyn.internal.wikitext.commonmark.inlines.LineBreakSpan.java
@Override public Optional<? extends Inline> createInline(Cursor cursor) { char c = cursor.getChar(); if (c == '\n' || c == ' ') { Matcher matcher = cursor.matcher(pattern); if (matcher.matches()) { int length = matcher.group(1).length(); if (length > 2 || matcher.group(2) != null) { return Optional.of(new HardLineBreak(cursor.getLineAtOffset(), cursor.getOffset(), length)); }/* w w w.j av a2 s . com*/ return Optional.of(new SoftLineBreak(cursor.getLineAtOffset(), cursor.getOffset(), length)); } } return Optional.absent(); }
From source file:com.streamsets.pipeline.hbase.api.common.producer.HBaseColumn.java
public void setCf(byte[] cf) { this.cf = Optional.of(cf); }
From source file:org.apache.gobblin.util.io.MeteredInputStream.java
/** * Find the lowest {@link MeteredInputStream} in a chain of {@link FilterInputStream}s. */// w ww. ja va 2 s . c o m public static Optional<MeteredInputStream> findWrappedMeteredInputStream(InputStream is) { if (is instanceof FilterInputStream) { try { Optional<MeteredInputStream> meteredInputStream = findWrappedMeteredInputStream( FilterStreamUnpacker.unpackFilterInputStream((FilterInputStream) is)); if (meteredInputStream.isPresent()) { return meteredInputStream; } } catch (IllegalAccessException iae) { log.warn("Cannot unpack input stream due to SecurityManager.", iae); // Do nothing, we can't unpack the FilterInputStream due to security restrictions } } if (is instanceof MeteredInputStream) { return Optional.of((MeteredInputStream) is); } return Optional.absent(); }
From source file:dagger.internal.codegen.writer.FieldWriter.java
public void setInitializer(Snippet initializer) { this.initializer = Optional.of(initializer); }
From source file:de.flapdoodle.logparser.StreamProcessException.java
public <T> Optional<T> entry(Class<T> type) { if (entry != null) { if (type.isInstance(entry)) { return Optional.of((T) entry); }// w w w . j a v a 2 s . c o m } return Optional.absent(); }
From source file:org.osiam.resources.helper.SCIMHelper.java
/** * try to extract an email from the User. * If the User has a primary email address this email will be returned. * If not the first email address found will be returned. * If no Email has been found email.isPresent() == false * * @param user a {@link User} with a possible email * @return an email if found//w ww . ja v a 2 s . c o m * @deprecated Please use the method {@link User#getPrimaryOrFirstEmail()} */ @Deprecated public static Optional<Email> getPrimaryOrFirstEmail(User user) { for (Email email : user.getEmails()) { if (email.isPrimary()) { return Optional.of(email); } } if (user.getEmails().size() > 0) { return Optional.of(user.getEmails().get(0)); } return Optional.absent(); }
From source file:io.crate.planner.Limits.java
public static Optional<Symbol> mergeAdd(Optional<Symbol> s1, Optional<Symbol> s2) { if (s1.isPresent()) { if (s2.isPresent()) { return Optional.of(AddFunction.of(s1.get(), s2.get())); }/* ww w. ja va 2 s .c o m*/ return s1; } return s2; }
From source file:com.jivesoftware.os.hwal.permit.ExpirablePermit.java
public Optional<Integer> getPermit() { Permit permit = expirableDelegatePermit.get(); if (permit == null) { return Optional.absent(); } else {//from w ww . j a v a 2 s. co m return Optional.of(permit.id); } }
From source file:org.apache.gobblin.util.io.MeteredOutputStream.java
/** * Find the lowest {@link MeteredOutputStream} in a chain of {@link FilterOutputStream}s. *///from w ww . j av a 2 s .c o m public static Optional<MeteredOutputStream> findWrappedMeteredOutputStream(OutputStream os) { if (os instanceof FilterOutputStream) { try { Optional<MeteredOutputStream> meteredOutputStream = findWrappedMeteredOutputStream( FilterStreamUnpacker.unpackFilterOutputStream((FilterOutputStream) os)); if (meteredOutputStream.isPresent()) { return meteredOutputStream; } } catch (IllegalAccessException iae) { log.warn("Cannot unpack input stream due to SecurityManager.", iae); // Do nothing, we can't unpack the FilterInputStream due to security restrictions } } if (os instanceof MeteredOutputStream) { return Optional.of((MeteredOutputStream) os); } return Optional.absent(); }