Documentation of 'edu.princeton.cs.algs4.Date' Java class
Date
edu.princeton.cs.algs4

Class Date

  • All Implemented Interfaces:
    java.lang.Comparable<Date>


    public class Date
    extends java.lang.Object
    implements java.lang.Comparable<Date>
    The Date class is an immutable data type to encapsulate a date (day, month, and year).

    For additional documentation, see Section 1.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • Constructor Summary

      Constructors 
      Constructor and Description
      Date(int month, int day, int year)
      Initializes a new date from the month, day, and year.
      Date(java.lang.String date)
      Initializes new date specified as a string in form MM/DD/YYYY.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      int compareTo(Date that)
      Compares two dates chronologically.
      int day()
      Returns the day.
      boolean equals(java.lang.Object other)
      Compares this date to the specified date.
      int hashCode()
      Returns an integer hash code for this date.
      boolean isAfter(Date that)
      Compares two dates chronologically.
      boolean isBefore(Date that)
      Compares two dates chronologically.
      static void main(java.lang.String[] args)
      Unit tests the Date data type.
      int month()
      Return the month.
      Date next()
      Returns the next date in the calendar.
      java.lang.String toString()
      Returns a string representation of this date.
      int year()
      Returns the year.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Date

        public Date(int month,
                    int day,
                    int year)
        Initializes a new date from the month, day, and year.
        Parameters:
        month - the month (between 1 and 12)
        day - the day (between 1 and 28-31, depending on the month)
        year - the year
        Throws:
        java.lang.IllegalArgumentException - if this date is invalid
      • Date

        public Date(java.lang.String date)
        Initializes new date specified as a string in form MM/DD/YYYY.
        Parameters:
        date - the string representation of this date
        Throws:
        java.lang.IllegalArgumentException - if this date is invalid
    • Method Detail

      • month

        public int month()
        Return the month.
        Returns:
        the month (an integer between 1 and 12)
      • day

        public int day()
        Returns the day.
        Returns:
        the day (an integer between 1 and 31)
      • year

        public int year()
        Returns the year.
        Returns:
        the year
      • next

        public Date next()
        Returns the next date in the calendar.
        Returns:
        a date that represents the next day after this day
      • isAfter

        public boolean isAfter(Date that)
        Compares two dates chronologically.
        Parameters:
        that - the other date
        Returns:
        true if this date is after that date; false otherwise
      • isBefore

        public boolean isBefore(Date that)
        Compares two dates chronologically.
        Parameters:
        that - the other date
        Returns:
        true if this date is before that date; false otherwise
      • compareTo

        public int compareTo(Date that)
        Compares two dates chronologically.
        Specified by:
        compareTo in interface java.lang.Comparable<Date>
        Returns:
        the value 0 if the argument date is equal to this date; a negative integer if this date is chronologically less than the argument date; and a positive ineger if this date is chronologically after the argument date
      • toString

        public java.lang.String toString()
        Returns a string representation of this date.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the string representation in the format MM/DD/YYYY
      • equals

        public boolean equals(java.lang.Object other)
        Compares this date to the specified date.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        other - the other date
        Returns:
        true if this date equals other; false otherwise
      • hashCode

        public int hashCode()
        Returns an integer hash code for this date.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        an integer hash code for this date
      • main

        public static void main(java.lang.String[] args)
        Unit tests the Date data type.
        Parameters:
        args - the command-line arguments

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.