List of usage examples for com.google.common.base Optional absent
public static <T> Optional<T> absent()
From source file:org.code_house.ebus.common.BasicCodecRegistry.java
@Override public <T, R> Optional<CommandCodec<T, R>> find(Command<T, R> command) { if (codecs.containsKey(command)) { return Optional.of(codecs.get(command)); }// w w w .j ava2 s. c o m return Optional.absent(); }
From source file:org.apache.druid.tasklogs.NoopTaskLogs.java
@Override public Optional<ByteSource> streamTaskLog(String taskid, long offset) { return Optional.absent(); }
From source file:com.addthis.hydra.job.spawn.jersey.DefaultAuthenticator.java
@Override public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException { if (!StringUtils.isEmpty(credentials.getUsername())) { return Optional.of(new User(credentials.getUsername(), credentials.getUsername(), true)); //default admin }/* w ww . jav a2s.co m*/ return Optional.absent(); }
From source file:com.facebook.buck.util.concurrent.AssertScopeExclusiveAccess.java
public AssertScopeExclusiveAccess() { inScope = new AtomicBoolean(); inScopeStack = Optional.absent(); }
From source file:io.crate.sql.tree.KillStatement.java
public KillStatement() { this.jobId = Optional.absent(); }
From source file:org.geogit.api.plumbing.ResolveBranchId.java
@Override public Optional<Ref> call() { Preconditions.checkState(id != null, "id has not been set."); Predicate<Ref> filter = new Predicate<Ref>() { @Override//from w ww .ja va 2 s.co m public boolean apply(@Nullable Ref ref) { return ref.getObjectId().equals(id); } }; ImmutableSet<Ref> refs = command(ForEachRef.class).setFilter(filter).call(); if (refs.isEmpty()) { return Optional.absent(); } else { return Optional.of(refs.iterator().next()); } }
From source file:org.knight.examples.guava.basic.UsingAvoidingNullExamples.java
public void run() { Optional<String> o1 = Optional.of("Guava-library"); if (o1.isPresent()) { log("o1: " + o1.get()); } else {/*from www. j av a 2 s . c o m*/ log("o1: " + o1.toString()); } Optional<String> o2 = Optional.absent(); try { //will cause a IllegalStateException log("o2: " + o2.get()); } catch (IllegalStateException e) { log("o2 is absent, use get() will cause a IllegalStateException."); } Optional<String> o3 = Optional.fromNullable(null); log("o3 present = " + o3.isPresent()); try { //will cause a IllegalStateException log("o3: " + o3.get()); } catch (IllegalStateException e) { log("o3 is absent, use get() will cause a IllegalStateException."); } if (o3.orNull() == null) { log("o3 is absent, so orNull() returns null."); } Optional<String> o4 = Optional.fromNullable("Hello World"); log("o4: " + o4.or("o4 is present, so this default value will not be printed.")); Optional<Book> o5 = Optional.of(Book.generateBook()); log("o5: " + o5.get().toString()); }
From source file:org.onos.yangtools.yang.data.api.schema.tree.spi.ValueNode.java
@Override public Optional<TreeNode> getChild(final PathArgument childId) { LOG.warn("Attempted to access child {} of value-node {}", childId, this); return Optional.absent(); }
From source file:com.dowdandassociates.gentoo.bootstrap.InstanceUtils.java
public static Optional<Instance> onDemandInstance(AmazonEC2 ec2Client, Optional<Image> image, Integer minCount, Integer maxCount, SecurityGroupInformation securityGroupInformation, KeyPairInformation keyPairInformation, Optional<String> instanceType, Optional<String> availabilityZone, Long sleep) {// w w w . j a va 2s . c o m if (!image.isPresent()) { return Optional.absent(); } RunInstancesRequest runInstancesRequest = new RunInstancesRequest().withImageId(image.get().getImageId()) .withMinCount(minCount).withMaxCount(maxCount) .withSecurityGroups(securityGroupInformation.getGroupName()) .withKeyName(keyPairInformation.getName()); log.info("ImageId=" + image.get().getImageId()); log.info("MinCount=" + minCount); log.info("MaxCount=" + maxCount); log.info("SecurityGroups.1=" + securityGroupInformation.getGroupName()); log.info("KeyName=" + keyPairInformation.getName()); if (instanceType.isPresent()) { runInstancesRequest.setInstanceType(instanceType.get()); log.info("InstanceType=" + instanceType.get()); } if (availabilityZone.isPresent()) { runInstancesRequest.setPlacement(new Placement().withAvailabilityZone(availabilityZone.get())); log.info("Placement.AvailabilityZone=" + availabilityZone.get()); } RunInstancesResult runInstancesResult = ec2Client.runInstances(runInstancesRequest); DescribeInstanceStatusRequest describeInstanceStatusRequest = new DescribeInstanceStatusRequest() .withInstanceIds(runInstancesResult.getReservation().getInstances().get(0).getInstanceId()); try { while (true) { log.info("Sleeping for " + sleep + " ms"); Thread.sleep(sleep); DescribeInstanceStatusResult describeInstanceStatusResult = ec2Client .describeInstanceStatus(describeInstanceStatusRequest); if (describeInstanceStatusResult.getInstanceStatuses().isEmpty()) { continue; } InstanceStatus instance = describeInstanceStatusResult.getInstanceStatuses().get(0); String instanceState = instance.getInstanceState().getName(); log.info("instanceState = " + instanceState); if ("pending".equals(instanceState)) { continue; } if (!"running".equals(instanceState)) { return Optional.absent(); } String instanceStatus = instance.getInstanceStatus().getStatus(); String systemStatus = instance.getSystemStatus().getStatus(); log.info("instanceStatus = " + instanceStatus); log.info("systemStatus = " + systemStatus); if ("impaired".equals(instanceStatus)) { return Optional.absent(); } if ("impaired".equals(systemStatus)) { return Optional.absent(); } if (!"ok".equals(instanceStatus)) { continue; } if (!"ok".equals(systemStatus)) { continue; } break; } } catch (InterruptedException e) { return Optional.absent(); } DescribeInstancesResult describeInstancesResult = ec2Client.describeInstances(new DescribeInstancesRequest() .withInstanceIds(runInstancesResult.getReservation().getInstances().get(0).getInstanceId())); return Optional.fromNullable(describeInstancesResult.getReservations().get(0).getInstances().get(0)); }
From source file:org.fabrician.enabler.util.RunCmdAuxiliaryOptions.java
public static Optional<String> build(RuntimeContextVariable var) { try {// ww w.j a va 2 s . com RunCmdAuxiliaryOptions val = valueOf(var.getName()); if (var.getTypeInt() != RuntimeContextVariable.OBJECT_TYPE) { String currentValue = StringUtils.trimToEmpty((String) var.getValue()); // empty value means the option is not valid and would be skipped // so that we accept the default if (!currentValue.isEmpty()) { if (val.isBooleanType) { Boolean b = BooleanUtils.toBooleanObject(currentValue); if (b != val.defaultBooleanValue) { return Optional.of(" " + val.optionSwitch + " "); } } else { return Optional.of(" " + val.optionSwitch + " " + currentValue); } } } } catch (Exception ex) { } return Optional.absent(); }