Example usage for com.google.common.base Optional absent

List of usage examples for com.google.common.base Optional absent

Introduction

In this page you can find the example usage for com.google.common.base Optional absent.

Prototype

public static <T> Optional<T> absent() 

Source Link

Document

Returns an Optional instance with no contained reference.

Usage

From source file:com.eucalyptus.auth.tokens.RoleSecurityTokenAttributes.java

public static <T extends RoleSecurityTokenAttributes> Optional<T> fromContext(Class<T> type) {
    try {// w  w w. ja va2  s.c om
        final Context context = Contexts.lookup();
        final UserPrincipal principal = context.getUser();
        if (principal != null) {
            final Optional<RoleSecurityTokenAttributes> attributes = RoleSecurityTokenAttributes
                    .forUser(principal);
            if (attributes.isPresent() && type.isInstance(attributes.get())) {
                return Optional.of(type.cast(attributes.get()));
            }
        }
    } catch (final IllegalContextAccessException e) {
        // absent
    }
    return Optional.absent();

}

From source file:google.registry.tools.params.OptionalParameterConverterValidator.java

@Override
public final Optional<T> convert(String value) {
    if (value.equals(NULL_STRING) || value.isEmpty()) {
        return Optional.absent();
    } else {/*from  w  ww .  j ava 2s .c o  m*/
        return Optional.of(validator.convert(value));
    }
}

From source file:org.sonar.server.computation.task.projectanalysis.measure.MeasureDtoToMeasure.java

public Optional<Measure> toMeasure(@Nullable MeasureDto measureDto, Metric metric) {
    requireNonNull(metric);//  w  ww .ja  v a 2s.  c  om
    if (measureDto == null) {
        return Optional.absent();
    }
    Double value = measureDto.getValue();
    String data = measureDto.getData();
    switch (metric.getType().getValueType()) {
    case INT:
        return toIntegerMeasure(measureDto, value, data);
    case LONG:
        return toLongMeasure(measureDto, value, data);
    case DOUBLE:
        return toDoubleMeasure(measureDto, value, data);
    case BOOLEAN:
        return toBooleanMeasure(measureDto, value, data);
    case STRING:
        return toStringMeasure(measureDto, data);
    case LEVEL:
        return toLevelMeasure(measureDto, data);
    case NO_VALUE:
        return toNoValueMeasure(measureDto);
    default:
        throw new IllegalArgumentException("Unsupported Measure.ValueType " + metric.getType().getValueType());
    }
}

From source file:org.apache.usergrid.persistence.index.CandidateResults.java

public CandidateResults(List<CandidateResult> candidates,
        final Collection<SelectFieldMapping> getFieldMappings) {
    this.candidates = candidates;
    this.getFieldMappings = getFieldMappings;
    offset = Optional.absent();
}

From source file:org.zanata.email.ContactAdminAnonymousEmailStrategy.java

@Override
public Optional<InternetAddress[]> getReplyToAddress() {
    return Optional.absent();
}

From source file:com.wealdtech.jersey.exceptions.HttpException.java

/**
 * Generate an HTTP exception with underlying application exception.
 * @param status an HTTP status to be sent back to the requestor
 * @param message an explanation of the error
 * @param userMessage TODO/*from w  w w  .  java 2  s .  c  om*/
 */
public HttpException(final Status status, final String message, String userMessage) {
    super(message, userMessage, null, null);
    this.status = status;
    this.retryAfter = Optional.absent();
}

From source file:org.splevo.jamopp.refactoring.java.caslicensehandler.cheatsheet.actions.JaMoPPRoutines.java

/**
 * Returns the concrete classifier (JaMoPP) for the given type (JavaCore).
 * //from  w w w  .j  a v a 2  s .co m
 * @param type
 *            represents the type.
 * @return the matched classifier.
 */
public static Optional<ConcreteClassifier> getConcreteClassifierOf(IType type) {
    ResourceSet resourceSet = ((JaMoPPJavaSoftwareElement) CASLicenseHandlerConfiguration.getInstance()
            .getVariationPoint().getLocation()).getJamoppElement().eResource().getResourceSet();

    final String typeName = type.getElementName();
    URI resourceURI = URI.createPlatformResourceURI(type.getResource().getFullPath().toString(), true);
    Resource r = resourceSet.getResource(resourceURI, true);
    for (CompilationUnit cu : Iterables.filter(r.getContents(), CompilationUnit.class)) {
        LinkedList<ConcreteClassifier> queue = Lists.newLinkedList(cu.getClassifiers());
        while (!queue.isEmpty()) {
            ConcreteClassifier classifier = queue.pop();
            if (typeName.equals(classifier.getName())) {
                return Optional.of(classifier);
            }
        }
    }

    return Optional.absent();
}

From source file:org.sonar.server.platform.ServerIdLoader.java

public Optional<ServerId> get() {
    Optional<String> rawId = getRaw();
    if (!rawId.isPresent()) {
        return Optional.absent();
    }/*  w w w .  ja  va 2  s  . c  om*/

    String organization = settings.getString(CoreProperties.ORGANISATION);
    String ipAddress = settings.getString(CoreProperties.SERVER_ID_IP_ADDRESS);
    boolean validated = organization != null && ipAddress != null
            && idGenerator.validate(organization, ipAddress, rawId.get());

    return Optional.of(new ServerId(rawId.get(), validated));
}

From source file:com.dasasian.chok.command.StartLuceneNodeCommand.java

@Override
protected void parseArguments(ZkConfiguration zkConf, String[] args, Map<String, String> optionMap) {
    Optional<Integer> startPort = Optional.absent();
    if (optionMap.containsKey("-p")) {
        startPort = Optional.of(Integer.parseInt(optionMap.get("-p")));
    }/*from  w  ww .  j a  va  2 s . c o m*/

    Optional<File> shardFolder = Optional.absent();
    if (optionMap.containsKey("-f")) {
        shardFolder = Optional.of(new File(optionMap.get("-f")));
    }

    try {
        nodeConfiguration = LuceneNodeConfigurationLoader.loadConfiguration(startPort, shardFolder);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }

    server = new LuceneServer();
}

From source file:com.hellblazer.glassHouse.demo.ExampleAuthenticator.java

@Override
public Optional<AuthenticatedUser> authenticate(final BasicCredentials credentials)
        throws AuthenticationException {
    if ("secret".equals(credentials.getPassword())) {
        AuthenticatedUser user = new AuthenticatedUser() {
            private final String name = credentials.getUsername();

            @Override//from  w ww.  ja  va  2  s . c  o  m
            public String getName() {
                return name;
            }
        };
        return Optional.of(user);
    }
    return Optional.absent();
}