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

com.jongsoft.lang.time.Range Maven / Gradle / Ivy

The newest version!
package com.jongsoft.lang.time;

import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalField;
import java.util.stream.Stream;

/**
 * A temporal range to contain a from until temporal entities. Where the from is inclusive and the until is exclusive.
 *
 * @since 1.1.0
 * @param  the temporal type
 */
public interface Range {

    /**
     * The from part for this temporal range.
     *
     * @return the inclusive from part
     */
    T from();

    /**
     * Get a part of the from temporal of this range.
     *
     * @param part  the temporal field part to get
     * @return      the temporal field value
     */
    default int fromPart(TemporalField part) {
        return from().get(part);
    }

    /**
     * The until part for this temporal range.
     *
     * @return the exclusive until part
     */
    T until();

    /**
     * Get a part of the until temporal of this range.
     *
     * @param part  the temporal field part to get
     * @return      the temporal field value
     */
    default int untilPart(TemporalField part) {
        return until().get(part);
    }

    /**
     * Slice the temporal range into smaller sections, where each slice is at least the indicated ChronoUnit in size.
     *
     * @param slicing   the slicing range
     * @return          the sliced ranges
     */
    Stream> slice(ChronoUnit slicing);

    /**
     * Returns the range exactly before this range. If the range was created using a ChronoUnit then the window will shift
     * exactly one ChronoUnit back. If it was created using a from and until it will shift exactly the same size back.
     *
     * @since 1.1.1
     * @return the previous window
     */
    Range previous();

    /**
     * Returns the range exactly after this range. If the range was created using a ChronoUnit then the window will shift
     * exactly one ChronoUnit forward. If it was created using a from and until it will shift exactly the same size forward.
     *
     * @since 1.1.1
     * @return the next window
     */
    Range next();

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy