All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yelstream.topp.standard.util.Optionals Maven / Gradle / Ivy

The newest version!
package com.yelstream.topp.standard.util;

import lombok.experimental.UtilityClass;

import java.util.Optional;

/**
 * Utility addressing instances of {@link Optional}.
 *
 * @author Morten Sabroe Mortensen
 * @version 1.0
 * @since 2024-06-23
 */
@UtilityClass
public class Optionals {
    /**
     * Indicates, if an optional is empty.
     * 

* Note that while this kind of testing is NOT the intention with a supposed-to-be fluent optional, * not all APIs are created with this in mind, are used appropriately, * leading to most defensive coding being necessary! *

*

* This represents extreme carefulness. *

* @param optional Optional. * This may be {@code null}. * @return Indicats, if empty. * @param Type of optional value. */ @SuppressWarnings("all") public static boolean isEmpty(Optional optional) { return optional==null || optional.isEmpty(); } /** * Gets the value contained in an optional *

* Note that while this kind of testing is NOT the intention with a supposed-to-be fluent optional, * not all APIs are created with this in mind, are used appropriately, * leading to most defensive coding being necessary! *

*

* This represents extreme carefulness. *

* @param optional Optional. * This may be {@code null}. * @return Value contained in optional. * This may be {@code null}. * @param Type of optional value. */ @SuppressWarnings("all") public static T get(Optional optional) { return isEmpty(optional)?null:optional.get(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy