Class SimpleMatrix

java.lang.Object
overit.geocall.util.SimpleMatrix
All Implemented Interfaces:
Serializable, Matrix

public class SimpleMatrix extends Object implements Matrix, Serializable
Auxiliary class that implements the interface Matrix and must be used to create and manage a matrix. The class exposes two constructors, one to create an empty matrix and one to create a matrix and fill it. It is possible to invert the columns with the rows and obtain or set a single element of the matrix.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    SimpleMatrix(int w, int h)
    Create an empty matrix of width 'w' (and then 'w' columns) and height 'h' (and then 'h' rows).
    SimpleMatrix(int w, int h, Object[] oo)
    Create and fill a matrix of width 'w' (and then 'w' columns) and height 'h' (and then 'h' rows).
    The array must contain the elements to be inserted into the matrix and is read this way: the first 'w' elements (and then from index '0' to 'w-1' of the array) are the elements to insert in the first row.
  • Method Summary

    Modifier and Type
    Method
    Description
    get(int x, int y)
    Gets the element presents in the matrix in row 'x' and in column 'y'.
    int
    Gets the height of the matrix.
    int
    Gets the width of the matrix.
    void
    Inverts the columns of the matrix with the rows and viceversa.
    void
    set(int x, int y, Object o)
    Sets the element in the matrix to row 'x' and in column 'y'.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • _inverted

      protected boolean _inverted
  • Constructor Details

    • SimpleMatrix

      public SimpleMatrix(int w, int h)
      Create an empty matrix of width 'w' (and then 'w' columns) and height 'h' (and then 'h' rows).
      Parameters:
      w - width of the matrix (or number of columns).
      h - height of the matrix (or number of rows).
    • SimpleMatrix

      public SimpleMatrix(int w, int h, Object[] oo)
      Create and fill a matrix of width 'w' (and then 'w' columns) and height 'h' (and then 'h' rows).
      The array must contain the elements to be inserted into the matrix and is read this way: the first 'w' elements (and then from index '0' to 'w-1' of the array) are the elements to insert in the first row. The second 'w' elements (and then from index 'w' to '2w-1' of the array) are the elements to insert in the second row and so on.
      Parameters:
      w - width of the matrix (or number of columns).
      h - height of the matrix (or number of rows).
      oo - The array contains the elements to insert into the matrix.
  • Method Details

    • get

      public Object get(int x, int y)
      Gets the element presents in the matrix in row 'x' and in column 'y'. The indeces start from '0'
      Specified by:
      get in interface Matrix
      Parameters:
      x - The horizontal position of the cell from which extract the object
      y - The vertical position of the cell from which extract the object
      Returns:
      The element present in the corresponding cell.
    • set

      public void set(int x, int y, Object o)
      Sets the element in the matrix to row 'x' and in column 'y'.
      Specified by:
      set in interface Matrix
      Parameters:
      x - The horizontal position of the cell
      y - The vertical position of the cell
      o - The object to set
    • getWidth

      public int getWidth()
      Gets the width of the matrix.
      Specified by:
      getWidth in interface Matrix
      Returns:
      The number of columns of the matrix.
    • getHeight

      public int getHeight()
      Gets the height of the matrix.
      Specified by:
      getHeight in interface Matrix
      Returns:
      The number of rows of the matrix.
    • invert

      public void invert()
      Inverts the columns of the matrix with the rows and viceversa.
    • toString

      public String toString()
      Overrides:
      toString in class Object