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:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LengthConstraintEffectiveImpl.java

public LengthConstraintEffectiveImpl(final Number min, final Number max, final Optional<String> description,
        final Optional<String> reference) {
    this(min, max, description.orNull(), reference.orNull(), "length-out-of-specified-bounds",
            "The argument is out of bounds <" + min + ", " + max + ">");
}

From source file:org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl.java

public ModuleIdentifierImpl(final String name, final Optional<URI> namespace, final Optional<Date> revision) {
    this.name = checkNotNull(name);
    this.qnameModule = QNameModule.create(namespace.orNull(), revision.orNull());
}

From source file:com.google.template.soy.passes.CheckBadContextualUsagePass.java

private void checkCallNode(CallNode node, TemplateRegistry registry, SanitizedContentKind contentKind,
        SoyErrorKind errorKind) {//w  ww  . j ava 2 s.  co  m
    if (!ALLOWED_CONTEXTS.containsEntry(contentKind, node.getHtmlContext())) {
        Optional<SanitizedContentKind> calleeContentKind = registry.getCallContentKind(node);
        if (calleeContentKind.orNull() == contentKind) {
            errorReporter.report(node.getSourceLocation(), errorKind);
        }
    }
}

From source file:org.estatio.dom.communicationchannel.PhoneOrFaxNumbers.java

@Programmatic
public PhoneOrFaxNumber findByPhoneOrFaxNumber(final CommunicationChannelOwner owner,
        final String phoneNumber) {

    final Optional<PhoneOrFaxNumber> phoneNumberIfFound = findByPhoneOrFaxNumber(owner, phoneNumber,
            CommunicationChannelType.PHONE_NUMBER);
    if (phoneNumberIfFound.isPresent()) {
        return phoneNumberIfFound.get();
    }//from   w  w w. j  ava  2s .  c o  m

    final Optional<PhoneOrFaxNumber> faxNumberIfFound = findByPhoneOrFaxNumber(owner, phoneNumber,
            CommunicationChannelType.FAX_NUMBER);
    return faxNumberIfFound.orNull();
}

From source file:co.jirm.mapper.jdbc.JdbcSqlObjectQueryExecutor.java

protected void nullify(Object[] objects) {
    for (int i = 0; i < objects.length; i++) {
        Object o = objects[i];/*from w  w  w .  j ava2 s.  c om*/
        if (o instanceof Optional) {
            Optional<?> opt = (Optional<?>) o;
            objects[i] = opt.orNull();
        }
    }
}

From source file:org.auraframework.components.performance.CacheController.java

private <K, V> Object getValue(Cache<K, V> cache, String key, AtomicBoolean rv) {
    @SuppressWarnings("unchecked")
    V value = cache.getIfPresent((K) key);
    if (value != null && value instanceof Optional) {
        Optional<?> opt = (Optional<?>) value;
        rv.getAndSet(true);/*ww  w .  ja  v  a 2 s .co m*/
        return opt.orNull();
    } else {
        rv.getAndSet(value != null);
        return value;
    }
}

From source file:im.dadoo.teak.web.controller.ArchiveController.java

@RequestMapping(value = "/admin/archive/{id}/update", method = RequestMethod.POST)
public String update(HttpSession session, @PathVariable long id, @RequestParam(required = false) String title,
        @RequestParam(required = false) String author, @RequestParam(required = false) long categoryId,
        @RequestParam(required = false) String html, @RequestParam(required = false) MultipartFile thumbnail)
        throws IllegalStateException, IOException {
    Optional<ArchivePO> archiveOPO = this.defaultArchiveBO.findById(id);
    if (title != null) {
        archiveOPO.get().setTitle(title);
    }/*from w ww.  j ava 2s  .c  om*/
    if (author != null) {
        archiveOPO.get().setAuthor(author);
    }
    if (categoryId != 0) {
        archiveOPO.get().setCategoryId(categoryId);
    }
    if (html != null) {
        archiveOPO.get().setHtml(html);
    }
    if (!thumbnail.isEmpty()) {
        Optional<String> path = this.fileAO.save(thumbnail);
        archiveOPO.get().setThumbnailPath(path.orNull());
    }
    this.defaultArchiveBO.updateAllById(id, archiveOPO.get().getTitle(), archiveOPO.get().getAuthor(),
            archiveOPO.get().getHtml(), archiveOPO.get().getPublishDatetime(),
            archiveOPO.get().getThumbnailPath(), archiveOPO.get().getCategoryId());
    return "redirect:/admin/archive";
}

From source file:org.isisaddons.app.kitchensink.dom.hierarchy.HierarchyObjects.java

@Action(semantics = SemanticsOf.SAFE)
@MemberOrder(sequence = "10")
public ParentObject findParent(@ParameterLayout(named = "Title") final String title) {
    final Optional<ParentObject> parentObjectIfAny = Iterables.tryFind(parentObjects.listAll(),
            input -> container.titleOf(input).contains(title));
    return parentObjectIfAny.orNull();
}

From source file:org.estatio.dom.communicationchannel.PostalAddresses.java

@Programmatic
public PostalAddress findByAddress(final CommunicationChannelOwner owner, final String address1,
        final String postalCode, final String city, final Country country) {

    final List<CommunicationChannelOwnerLink> links = communicationChannelOwnerLinks
            .findByOwnerAndCommunicationChannelType(owner, CommunicationChannelType.POSTAL_ADDRESS);
    final Iterable<PostalAddress> postalAddresses = Iterables.transform(links,
            CommunicationChannelOwnerLink.Functions.communicationChannel(PostalAddress.class));
    final Optional<PostalAddress> postalAddressIfFound = Iterables.tryFind(postalAddresses,
            PostalAddress.Predicates.equalTo(address1, postalCode, city, country));
    return postalAddressIfFound.orNull();
}

From source file:org.eclipse.buildship.ui.launch.JavaHomeTab.java

@SuppressWarnings("Contract")
@Override/*w  w  w  .j ava  2s  .c  o m*/
public boolean isValid(ILaunchConfiguration launchConfig) {
    String javaHomeExpression = Strings.emptyToNull(this.javaHomeText.getText());

    String javaHomeResolved;
    try {
        javaHomeResolved = ExpressionUtils.decode(javaHomeExpression);
    } catch (CoreException e) {
        setErrorMessage(NLS.bind(LaunchMessages.ErrorMessage_CannotResolveExpression_0, javaHomeExpression));
        return false;
    }

    File javaHome = FileUtils.getAbsoluteFile(javaHomeResolved).orNull();
    Optional<String> error = this.javaHomeValidator.validate(javaHome);
    setErrorMessage(error.orNull());
    return !error.isPresent();
}