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

com.fizzed.crux.util.MoreComparable Maven / Gradle / Ivy

There is a newer version: 1.0.48
Show newest version
/*
 * Copyright 2019 Fizzed, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.fizzed.crux.util;

/**
 * Extends a Comparable to provide greater than and less than methods.
 * 
 * @author jjlauer
 * @param  
 */
public interface MoreComparable extends Comparable {
 
    /**
     * Whether this value is greater than other
     * value.
     * @param other The other value to compare against
     * @return True if this value is greater than other
     *      value
     */
    default public boolean gt(T other) {
        return this.compareTo(other) > 0;
    }
 
    /**
     * Whether this value is greater than or equal to other
     * value.
     * @param other The other value to compare against
     * @return True if this value is greater than or equal to other
     *      value
     */
    default public boolean gte(T other) {
        return this.compareTo(other) >= 0;
    }
 
    /**
     * Whether this value is less than other
     * value.
     * @param other The other value to compare against
     * @return True if this value is less than other
     *      value
     */
    default public boolean lt(T other) {
        return this.compareTo(other) < 0;
    }
 
    /**
     * Whether this value is less than or equal to other
     * value.
     * @param other The other value to compare against
     * @return True if this value is less than or equal to other
     *      value
     */
    default public boolean lte(T other) {
        return this.compareTo(other) <= 0;
    }
 
    /**
     * The minimum value between this or the other value.
     * @param other The other value to compare against
     * @return Will return this value if less than or equal to
     *      the other value, otherwise will return other.
     */
    default public T min(T other) {
        if (this.lte(other)) {
            return (T)this;
        } else {
            return other;
        }
    }
 
    /**
     * The maximum value between this or the other value.
     * @param other The other value to compare against
     * @return Will return this value if greater than or equal to
     *      the other value, otherwise will return other.
     */
    default public T max(T other) {
        if (this.gte(other)) {
            return (T)this;
        } else {
            return other;
        }
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy