Class Cell

  • All Implemented Interfaces:
    Comparable<Cell>

    public class Cell
    extends Object
    implements Comparable<Cell>
    Helper class to store a single unit of data. Used to create arrays of data to process. Holds either a Double or a String, never both. Also implements the Comparable interface to allow comparing to a different Cell.
    • Field Detail

      • num

        public final Double num
        Numerical value of the Cell. Mutually exclusive with str.
      • str

        public final String str
        Text value of the Cell. Mutually exclusive with num.
    • Constructor Detail

      • Cell

        public Cell​(Double num)
        Constructor for making a Cell holding numerical data.
        Parameters:
        num - a Double to be stored in the Cell
      • Cell

        public Cell​(Integer num)
        Alternative constructor for storing integer data
        Parameters:
        num - an Integer to be converted and stored in the Cell
      • Cell

        public Cell​(String str)
        A constructor for making a Cell storing text data.
        Parameters:
        str - a String to be stored in the Cell
    • Method Detail

      • getNum

        public Double getNum()
      • getStr

        public String getStr()
      • toString

        public String toString()
        An override toString() method for printing the Cell's value.
        Overrides:
        toString in class Object
        Returns:
        a string containing the value of num converted to text or str, whichever is not null.
      • compareTo

        public int compareTo​(@NonNull
                             Cell c)
        An override method to compare this Cell to another.
        Specified by:
        compareTo in interface Comparable<Cell>
        Parameters:
        c - the object to be compared.
        Returns:
        a positive value if this Cell is greater than supplied, negative one if lesser and 0 otherwise.
      • equals

        public boolean equals​(Object o)
        An override for the default equals() method. Allows checking whether two cells are the same.
        Overrides:
        equals in class Object
        Parameters:
        o - the reference object with which to compare.
        Returns:
        true if both objects are of type Cell, and both of their num and str values are the same, otherwise false.