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

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

Introduction

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

Prototype

@Nullable
public abstract T orNull();

Source Link

Document

Returns the contained instance if it is present; null otherwise.

Usage

From source file:com.streamsets.pipeline.stage.lib.hive.HMSCache.java

/**
 * Returns if the {@link HMSCache} has the corresponding {@link HMSCacheSupport.HMSCacheInfo} and qualified table name.
 * @param hmsCacheType {@link HMSCacheType}
 * @param qualifiedTableName qualified table name
 * @param <T> {@link HMSCacheSupport.HMSCacheInfo}
 * @return Corresponding {@link HMSCacheSupport.HMSCacheInfo} for the qualified table name.
 * @throws StageException if the {@link HMSCacheType} is not supported by {@link HMSCache}
 *//*from  ww w. j a  va 2  s  .  c  o  m*/
@SuppressWarnings("unchecked")
public <T extends HMSCacheSupport.HMSCacheInfo> T getIfPresent(HMSCacheType hmsCacheType,
        String qualifiedTableName) throws StageException {
    if (!cacheMap.containsKey(hmsCacheType)) {
        throw new StageException(Errors.HIVE_16, hmsCacheType);
    }
    Optional<HMSCacheSupport.HMSCacheInfo> ret = cacheMap.get(hmsCacheType).getIfPresent(qualifiedTableName);
    return ret == null ? null : (T) ret.orNull();
}

From source file:net.pterodactylus.sone.web.ImageBrowserPage.java

/**
 * {@inheritDoc}/*from   www .jav a 2 s. c o  m*/
 */
@Override
protected void processTemplate(FreenetRequest request, TemplateContext templateContext)
        throws RedirectException {
    super.processTemplate(request, templateContext);
    String albumId = request.getHttpRequest().getParam("album", null);
    if (albumId != null) {
        Album album = webInterface.getCore().getAlbum(albumId, false);
        templateContext.set("albumRequested", true);
        templateContext.set("album", album);
        templateContext.set("page", request.getHttpRequest().getParam("page"));
        return;
    }
    String imageId = request.getHttpRequest().getParam("image", null);
    if (imageId != null) {
        Image image = webInterface.getCore().getImage(imageId, false);
        templateContext.set("imageRequested", true);
        templateContext.set("image", image);
        return;
    }
    String soneId = request.getHttpRequest().getParam("sone", null);
    if (soneId != null) {
        Optional<Sone> sone = webInterface.getCore().getSone(soneId);
        templateContext.set("soneRequested", true);
        templateContext.set("sone", sone.orNull());
        return;
    }
    String mode = request.getHttpRequest().getParam("mode", null);
    if ("gallery".equals(mode)) {
        templateContext.set("galleryRequested", true);
        List<Album> albums = new ArrayList<Album>();
        for (Sone sone : webInterface.getCore().getSones()) {
            albums.addAll(from(sone.getRootAlbum().getAlbums()).transformAndConcat(FLATTENER).filter(NOT_EMPTY)
                    .toList());
        }
        Collections.sort(albums, TITLE_COMPARATOR);
        Pagination<Album> albumPagination = new Pagination<Album>(albums, 12)
                .setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
        templateContext.set("albumPagination", albumPagination);
        templateContext.set("albums", albumPagination.getItems());
        return;
    }
    Sone sone = getCurrentSone(request.getToadletContext(), false);
    templateContext.set("soneRequested", true);
    templateContext.set("sone", sone);
}

From source file:com.squid.kraken.v4.persistence.dao.AccessTokenDAO.java

public Optional<AccessToken> read(AccessTokenPK id) {
    Optional<AccessToken> object = instanceCache.getOptional(id);
    if (object == null) {
        object = ds.read(null, type, id);
        instanceCache.put(id, object.orNull());
    }//  w ww. j  a va2s  .  c o  m
    return object;
}

From source file:org.opendaylight.yangtools.yang.data.api.schema.tree.NormalizedNodeDataTreeCandidateNode.java

@Override
public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
    if (data instanceof NormalizedNodeContainer) {
        @SuppressWarnings({ "rawtypes", "unchecked" })
        final Optional<? extends NormalizedNode<?, ?>> child = ((NormalizedNodeContainer) data)
                .getChild(identifier);/*from  w w w. j  av a 2s  .  c o  m*/
        return FACTORY_FUNCTION.apply(child.orNull());
    }
    return null;
}

From source file:org.onos.yangtools.yang.data.api.schema.tree.NormalizedNodeDataTreeCandidateNode.java

@Override
public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
    if (data instanceof NormalizedNodeContainer) {
        @SuppressWarnings({ "rawtypes", "unchecked" })
        final Optional<? extends NormalizedNode<?, ?>> child = ((NormalizedNodeContainer) data)
                .getChild(identifier);/*  ww  w. java  2s.  c om*/
        return FACTORY_FUNCTION.apply(child.orNull());
    } else {
        return null;
    }
}

From source file:com.qcadoo.mes.deviationCausesReporting.listeners.DeviationsReportGeneratorViewListeners.java

private void redirectToPdf(final ViewDefinitionState view) {
    Optional<String> dateFrom = getComponentValue(view, DeviationReportGeneratorViewReferences.DATE_FROM);
    Optional<String> dateTo = getComponentValue(view, DeviationReportGeneratorViewReferences.DATE_TO);
    String url = String.format("/deviationCausesReporting/deviations.pdf?dateFrom=%s&dateTo=%s", dateFrom.get(),
            dateTo.orNull());
    view.redirectTo(url, true, false);/*from w w w .  j  a  v  a 2  s  .  com*/
}

From source file:org.robotninjas.barge.log.RaftLog.java

public void lastVotedFor(@Nonnull Optional<Replica> vote) {
    LOGGER.debug("Voting for {}", vote.orNull());
    votedFor = vote;//  w w  w.  j  a va  2s.c o m
    journal.appendVote(vote);
}

From source file:org.geogig.osm.cli.commands.OSMExport.java

private Iterator<EntityContainer> getFeatures(String ref) {
    Optional<ObjectId> id = geogig.command(RevParse.class).setRefSpec(ref).call();
    if (!id.isPresent()) {
        return Collections.emptyIterator();
    }/*from w  w w  .  j  a va  2s  .  co  m*/
    LsTreeOp op = geogig.command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES)
            .setReference(ref);
    if (bbox != null) {
        final Envelope env;
        try {
            env = new Envelope(Double.parseDouble(bbox.get(0)), Double.parseDouble(bbox.get(2)),
                    Double.parseDouble(bbox.get(1)), Double.parseDouble(bbox.get(3)));
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Wrong bbox definition");
        }
        Predicate<Bounded> filter = new Predicate<Bounded>() {
            @Override
            public boolean apply(final Bounded bounded) {
                boolean intersects = bounded.intersects(env);
                return intersects;
            }
        };
        op.setBoundsFilter(filter);
    }
    Iterator<NodeRef> iterator = op.call();
    final EntityConverter converter = new EntityConverter();
    final Function<NodeRef, EntityContainer> function = (nr) -> {
        RevFeature revFeature = geogig.command(RevObjectParse.class).setObjectId(nr.getObjectId())
                .call(RevFeature.class).get();
        SimpleFeatureType featureType;
        if (nr.path().startsWith(OSMUtils.NODE_TYPE_NAME)) {
            featureType = OSMUtils.nodeType();
        } else {
            featureType = OSMUtils.wayType();
        }
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
        RevFeatureType revFeatureType = RevFeatureTypeBuilder.build(featureType);
        List<PropertyDescriptor> descriptors = revFeatureType.descriptors();
        for (int i = 0; i < descriptors.size(); i++) {
            PropertyDescriptor descriptor = descriptors.get(i);
            Optional<Object> value = revFeature.get(i);
            featureBuilder.set(descriptor.getName(), value.orNull());
        }
        SimpleFeature feature = featureBuilder.buildFeature(nr.name());
        Entity entity = converter.toEntity(feature, null);
        EntityContainer container;
        if (entity instanceof Node) {
            container = new NodeContainer((Node) entity);
        } else {
            container = new WayContainer((Way) entity);
        }

        return container;
    };
    return Iterators.transform(iterator, function);
}

From source file:com.abiquo.bond.api.event.VirtualMachineEvent.java

public VirtualMachineEvent(final EventDto event, final Optional<MetadataDto> optMetaData) {
    this(event);//from w  ww  .  j  a v a  2s. c  om
    MetadataDto vmdetails = optMetaData.orNull();
    if (vmdetails != null) {
        Map<String, Object> metadata = vmdetails.getMetadata();
        extractBackupData(metadata);
    }
}

From source file:org.eclipse.buildship.ui.wizard.project.ProjectCreationWizardController.java

public ProjectCreationWizardController(INewWizard projectCreationWizard) {
    // assemble configuration object that serves as the extra data model of the creation wizard
    Property<String> projectNameProperty = Property
            .create(Validators.uniqueWorkspaceProjectNameValidator(ProjectWizardMessages.Label_ProjectName));
    Property<Boolean> useDefaultLocationProperty = Property.create(Validators.<Boolean>nullValidator());
    Property<File> customLocationProperty = Property.create(Validators.validateIfConditionFalse(
            Validators.requiredDirectoryValidator(ProjectWizardMessages.Label_CustomLocation),
            useDefaultLocationProperty));
    Property<File> targetProjectDirProperty = Property.create(
            Validators.nonExistentDirectoryValidator(ProjectWizardMessages.Message_TargetProjectDirectory));

    this.configuration = new ProjectCreationConfiguration(projectNameProperty, useDefaultLocationProperty,
            customLocationProperty, targetProjectDirProperty);

    // initialize values from the persisted dialog settings
    IDialogSettings dialogSettings = projectCreationWizard.getDialogSettings();
    boolean useDefaultLocation = dialogSettings.get(SETTINGS_KEY_LOCATION_USE_DEFAULT) == null
            || dialogSettings.getBoolean(SETTINGS_KEY_LOCATION_USE_DEFAULT);
    Optional<File> customLocation = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_CUSTOM_LOCATION));

    this.configuration.setUseDefaultLocation(useDefaultLocation);
    this.configuration.setCustomLocation(customLocation.orNull());

    // store the values every time they change
    saveBooleanPropertyWhenChanged(dialogSettings, SETTINGS_KEY_LOCATION_USE_DEFAULT,
            this.configuration.getUseDefaultLocation());
    saveFilePropertyWhenChanged(dialogSettings, SETTINGS_KEY_CUSTOM_LOCATION,
            this.configuration.getCustomLocation());
}