Guava Optional - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava Optional class.

This code example shows how to use the following methods:get, isPresent
   public Location apply(String bucket) {
      Set<? extends Location> locations = this.locations.get();
      if (locations.size() == 1) 
         return get(locations, 0);
      final Optional<String> region = bucketToRegion.apply(bucket);
      if (region.isPresent()) {
         try { 
            return find(locations, idEquals(region.get()));
         } catch (NoSuchElementException e) {
            logger.debug("could not get location for region %s in %s", region, locations);
         } 
      } else { 
         logger.debug("could not get region for %s", bucket);
      } 
      return null; 
   } 
} 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get, isPresent
 
        @Override 
        public void apply(int position,
                          PreparedStatement statement,
                          StatementContext ctx) throws SQLException {
            if (value.isPresent()) {
                statement.setObject(position, value.get());
            } else { 
                statement.setNull(position, Types.OTHER);
            } 
        } 
    } 
 
    private static class MsSqlOptionalArgument implements Argument { 
        private final Optional<?> value;
 
        private MsSqlOptionalArgument(Optional<?> value) {
            this.value = value;
        } 
 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get, isPresent
 
   @Override 
   public URI apply(Object from) {
      String bucket = from.toString();
      Optional<String> region = bucketToRegion.apply(bucket);
      if (region.isPresent()) {
         return delegate.apply(region.get());
      } 
      return delegate.apply(null);
   } 
} 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isPresent
      other = parser.parse(input, ParseContext.forBaseName(target.getBaseName()));
    } catch (BuildTargetParseException e) {
      throw new MacroException(e.getMessage(), e);
    } 
    Optional<BuildRule> rule = resolver.getRuleOptional(other);
    if (!rule.isPresent()) {
      throw new MacroException(String.format("no rule %s", other));
    } 
    return expand(filesystem, rule.get());
  } 
 
  @Override 
  public ImmutableList<BuildTarget> extractTargets(
      BuildTarget target,
      String input) {
    return ImmutableList.of(parser.parse(input, ParseContext.forBaseName(target.getBaseName())));
  } 
 
} 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get, isPresent
  /** Utility class: do not instantiate. */ 
  private Optionals() {} 
 
  public static <T> void addIfPresent(Optional<T> optional,
                                      ImmutableCollection.Builder<T> collection) {
    if (optional.isPresent()) {
      collection.add(optional.get());
    } 
  } 
 
  public static <K, T> void putIfPresent(Optional<T> optional,
                                         K key,
                                         ImmutableMap.Builder<K, T> collection) {
    if (optional.isPresent()) {
      collection.put(key, optional.get());
    } 
  } 
} 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isPresent
   @BeforeClass(groups = { "integration", "live" }) 
   @Override 
   public void setup() { 
      super.setup(); 
      tenantAdminOption = api.getTenantAdminApi();
      if (!tenantAdminOption.isPresent()) {
         throw new SkipException( 
               "The tests are skipped since OS-KSADM extension is not exposed through the Keystone API"); 
      } 
      tenantApi = api.getTenantApi();
   } 
 
   @AfterClass(groups = { "integration", "live" }) 
   @Override 
   protected void tearDown() { 
      if (testTenant != null) {
         final String tenantId = testTenant.getId();
         boolean success = tenantAdminOption.get().delete(tenantId);
         assertTrue(retry(new Predicate<TenantApi>() {
            public boolean apply(TenantApi tenantApi) {
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get, isPresent
 
    Optional<Path> path = propertyFinder.findDirectoryByPropertiesThenEnvironmentVariable(
        "NOT_A_PROPERTY_NAME", 
        "SOME_ENVIRONMENT_VARIABLE" 
    ); 
    assertTrue(path.isPresent());
    assertEquals(path.get(), Paths.get("."));
  } 
} 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isPresent
   @BeforeClass(groups = { "integration", "live" }) 
   @Override 
   public void setup() { 
      super.setup(); 
      roleAdminOption = api.getRoleAdminApi();
      if (!roleAdminOption.isPresent()) {
         throw new SkipException("The tests are skipped since OS-KSADM extension is not exposed through the Keystone API"); 
      } 
   } 
 
   @AfterClass(groups = { "integration", "live" }) 
   @Override 
   protected void tearDown() { 
      if (testRole != null) {
         final String roleId = testRole.getId();
         boolean success = roleAdminOption.get().delete(roleId);
         assertTrue(retry(new Predicate<RoleAdminApi>() {
            public boolean apply(RoleAdminApi roleApi) {
               return roleApi.get(roleId) == null;
            } 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get, isPresent
      return equal(this.code, that.code) && equal(this.description, that.description);
   } 
 
   @Override 
   public String toString() {
      return description.isPresent() ? format("Error %s: %s", code, description.get()) : format("Error %s", code);
   } 
} 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get, isPresent
   * @return The path to the proguard.jar file that is overridden by the current project.  If not 
   * specified, the Android platform proguard.jar will be used. 
   */ 
  public Optional<Path> getProguardJarOverride() {
    Optional<String> pathString = delegate.getValue("tools", "proguard");
    if (pathString.isPresent()) {
      return delegate.checkPathExists(pathString.get(), "Overridden proguard path not found: ");
    } 
    return Optional.absent();
  } 
 
  /** 
   * @return The upper heap size limit for Proguard if specified. 
   */ 
  public String getProguardMaxHeapSize() {
    return delegate.getValue("tools", "proguard-max-heap-size").or("1024M");
  } 
 
} 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Guava Optional Methods: