Java LocalTime isLocalTimeInRange(LocalTime value, LocalTime optionalMinimum, LocalTime optionalMaximum, boolean inclusiveOfEndpoints)

Here you can find the source of isLocalTimeInRange(LocalTime value, LocalTime optionalMinimum, LocalTime optionalMaximum, boolean inclusiveOfEndpoints)

Description

isLocalTimeInRange, This returns true if the specified value is inside of the specified range.

License

Open Source License

Declaration

public static boolean isLocalTimeInRange(LocalTime value, LocalTime optionalMinimum, LocalTime optionalMaximum,
        boolean inclusiveOfEndpoints) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.time.*;

public class Main {
    /**// w w w  .j ava 2s.c  o  m
     * isLocalTimeInRange, This returns true if the specified value is inside of the specified
     * range. This returns false if the specified value is outside of the specified range. If the
     * specified value is null, then this will return false.
     *
     * If optionalMinimum is null, then it will be set to LocalTime.MIN. If optionalMaximum is null,
     * then it will be set to LocalTime.MAX.
     *
     * If inclusiveOfEndpoints is true, then values that equal the minimum or maximum will return
     * true. Otherwise, values that equal the minimum or maximum will return false.
     */
    public static boolean isLocalTimeInRange(LocalTime value, LocalTime optionalMinimum, LocalTime optionalMaximum,
            boolean inclusiveOfEndpoints) {
        // If either bounding time does does not already exist, then set it to the maximum range.
        LocalTime minimum = (optionalMinimum == null) ? LocalTime.MIN : optionalMinimum;
        LocalTime maximum = (optionalMaximum == null) ? LocalTime.MAX : optionalMaximum;
        // Null is never considered to be inside of a range.
        if (value == null) {
            return false;
        }
        // Return false if the range does not contain any times.
        if (maximum.isBefore(minimum) || maximum.equals(minimum)) {
            return false;
        }
        if (inclusiveOfEndpoints) {
            return ((value.isAfter(minimum) || value.equals(minimum))
                    && (value.isBefore(maximum) || value.equals(maximum)));
        } else {
            return (value.isAfter(minimum) && value.isBefore(maximum));
        }
    }
}

Related

  1. currentTimeIsBetween(LocalTime from, LocalTime to)
  2. deserializeLocalTime(String date)
  3. fastTimeWrite(LocalTime localTime)
  4. getTimeDiff(LocalTime start, LocalTime end)
  5. isBetween(LocalTime lt, LocalTime startTime, LocalTime endTime)
  6. parseLocalTime(String string)
  7. repDiff(LocalTime start, LocalTime end, byte type)
  8. reportTimeDiff(LocalTime start, LocalTime end)
  9. toLocalTime(Date date)