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.rentmycourt.api.core.helpers.SimpleAuthenticator.java

/**
 *
 * @param credentials/*from w  w w  .j a va  2 s. c o m*/
 * @return
 * @throws io.dropwizard.auth.AuthenticationException.<error>
 */
@Override
public Optional<User> authenticate(BasicCredentials credentials) throws AuthenticationException {
    if ("secret".equals(credentials.getPassword())) {
        return Optional.of(new User(credentials.getUsername()));
    }
    return Optional.absent();
}

From source file:org.opendaylight.groupbasedpolicy.util.DataStoreHelper.java

/**
 * Reads data from datastore as synchrone call.
 * @return {@link Optional#isPresent()} is {@code true} if reading was successful and data exists in datastore; {@link Optional#isPresent()} is {@code false} otherwise
 *//*from   w w  w .  ja v a 2  s  . c om*/
public static <T extends DataObject> Optional<T> readFromDs(LogicalDatastoreType store,
        InstanceIdentifier<T> path, ReadTransaction rTx) {
    CheckedFuture<Optional<T>, ReadFailedException> resultFuture = rTx.read(store, path);
    try {
        return resultFuture.checkedGet();
    } catch (ReadFailedException e) {
        LOG.warn("Read failed from DS.", e);
        return Optional.absent();
    }
}

From source file:cc.ilo.cc.ilo.pipeline.pipes.AbstractFilterPipe.java

@Override
public Optional<T> process(T input) throws Exception {
    if (accept(input)) {
        return Optional.of(input);
    } else {//from ww w  .  j av  a  2 s. c  o  m
        return Optional.absent();
    }

}

From source file:dagger2.internal.codegen.InjectionAnnotations.java

static Optional<AnnotationMirror> getQualifier(Element e) {
    checkNotNull(e);/*from   www  .j  ava  2  s. c  o m*/
    ImmutableSet<? extends AnnotationMirror> qualifierAnnotations = getQualifiers(e);
    switch (qualifierAnnotations.size()) {
    case 0:
        return Optional.absent();
    case 1:
        return Optional.<AnnotationMirror>of(qualifierAnnotations.iterator().next());
    default:
        throw new IllegalArgumentException(e + " was annotated with more than one @Qualifier annotation");
    }
}

From source file:com.android.camera.one.v2.Camera2OneCameraManagerImpl.java

/**
 * Create a new camera2 api hardware manager.
 *//*  w  w w  .  j  ava2 s.  c o m*/
public static Optional<Camera2OneCameraManagerImpl> create() {
    if (!ApiHelper.HAS_CAMERA_2_API) {
        return Optional.absent();
    }
    CameraManager cameraManager;
    try {
        cameraManager = AndroidServices.instance().provideCameraManager();
    } catch (IllegalStateException ex) {
        Log.e(TAG, "camera2.CameraManager is not available.");
        return Optional.absent();
    }
    Camera2OneCameraManagerImpl hardwareManager = new Camera2OneCameraManagerImpl(cameraManager);
    return Optional.of(hardwareManager);
}

From source file:com.google.template.soy.jbcsrc.BytecodeCompiler.java

/**
 * Compiles all the templates in the given registry.
 *
 * @return CompiledTemplates or {@code absent()} if compilation fails, in which case errors will
 *     have been reported to the error reporter.
 *///from w  ww  .  j ava  2 s .c  o  m
public static Optional<CompiledTemplates> compile(TemplateRegistry registry, ErrorReporter reporter) {
    ErrorReporter.Checkpoint checkpoint = reporter.checkpoint();
    checkForUnsupportedFeatures(registry, reporter);
    if (reporter.errorsSince(checkpoint)) {
        return Optional.absent();
    }
    CompiledTemplateRegistry compilerRegistry = new CompiledTemplateRegistry(registry);

    // TODO(lukes): currently we compile all the classes, but you could easily imagine being
    // configured in such a way that we load the classes from the system class loader.  Then we
    // could add a build phase that writes the compiled templates out to a jar.  Then in the non
    // development mode case we could skip even parsing templates!
    MemoryClassLoader loader = compileTemplates(registry, compilerRegistry, reporter);
    if (reporter.errorsSince(checkpoint)) {
        return Optional.absent();
    }
    ImmutableMap.Builder<String, CompiledTemplate.Factory> factories = ImmutableMap.builder();
    for (TemplateNode node : registry.getAllTemplates()) {
        String name = node.getTemplateName();
        factories.put(name, loadFactory(compilerRegistry.getTemplateInfo(name), loader));
    }
    return Optional.of(new CompiledTemplates(factories.build()));
}

From source file:net.awairo.mcmod.spawnchecker.client.common.Refrection.java

/**
 * ??????????.//from  w w w . j  a  va2 s  .  c o m
 * 
 * @return ??.
 */
public static Optional<InetSocketAddress> getServerAddress() {
    checkState(GAME.theWorld != null, "world is not started");
    checkState(GAME.getIntegratedServer() == null, "current mode is the single player.");

    final NetHandlerPlayClient sendQueue = getFieldValue(WorldClient.class, GAME.theWorld, "sendQueue",
            ConstantsConfig.instance().sendQueueSrgName);

    if (sendQueue == null)
        return Optional.absent();

    final NetworkManager netManager = sendQueue.getNetworkManager();

    if (netManager.getSocketAddress() instanceof InetSocketAddress)
        return Optional.fromNullable((InetSocketAddress) netManager.getSocketAddress());

    if (LOGGER.isDebugEnabled() && netManager.getSocketAddress() != null)
        LOGGER.debug(netManager.getSocketAddress().getClass().getName());

    LOGGER.warn("not found InetSocketAddress");

    return Optional.absent();
}

From source file:com.complexible.common.base.Reflect.java

/**
 * Returns the class with the given name.  A ClassNotFoundException will not be thrown if
 * the class does not exist, an {@link com.google.common.base.Optional} with an absent value will be returned instead.
 * Similarly, if a ClassCastException is thrown, because the class name is valid, but is
 * not of the correct type of class requested by the user, an Optional without a value will be returned..
 *
 * @param theClassName   the class name/*from w ww.  j a v a  2 s.c om*/
 * @return            the class, or null if it does not exist
 */
public static <T> Optional<Class<T>> getClass(final String theClassName) {
    try {
        return Optional.of((Class<T>) Class.forName(theClassName));
    } catch (ClassNotFoundException e) {
        return Optional.absent();
    } catch (ClassCastException e) {
        return Optional.absent();
    }
}

From source file:org.opendaylight.yangtools.yang.data.impl.schema.tree.DeleteLeafCandidateNode.java

@Override
@Nonnull
public Optional<NormalizedNode<?, ?>> getDataAfter() {
    return Optional.absent();
}

From source file:gobblin.data.management.copy.watermark.CopyableFileWatermarkHelper.java

/**
 * Get Optional {@link CopyableFileWatermarkGenerator} from {@link State}.
 *///from w  ww . j  a va 2 s.  c om
public static Optional<CopyableFileWatermarkGenerator> getCopyableFileWatermarkGenerator(State state)
        throws IOException {
    try {
        if (state.contains(WATERMARK_CREATOR)) {
            Class<?> watermarkCreatorClass = Class.forName(state.getProp(WATERMARK_CREATOR));
            return Optional.of((CopyableFileWatermarkGenerator) watermarkCreatorClass.newInstance());
        } else {
            return Optional.absent();
        }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new IOException("Failed to instantiate watermarkCreator.");
    }
}