Package sudoku.core

Enum Square

java.lang.Object
java.lang.Enum<Square>
sudoku.core.Square
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Square>, java.lang.constant.Constable

@Immutable
public enum Square
extends java.lang.Enum<Square>
A single square location in a ImmutableSudokuPuzzle. Note that this enum represents only a location on the board; it does not store the number written there. To get the value (written number) at a given square, use ImmutableSudokuPuzzle.getCandidates(Square).
Author:
Dennis Cosgrove (http://www.cse.wustl.edu/~cosgroved/), Finn Voichick
See Also:
Peter Norvig's board layout
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    java.lang.Enum.EnumDesc<E extends java.lang.Enum<E>>
  • Enum Constant Summary

    Enum Constants 
    Enum Constant Description
    A1  
    A2  
    A3  
    A4  
    A5  
    A6  
    A7  
    A8  
    A9  
    B1  
    B2  
    B3  
    B4  
    B5  
    B6  
    B7  
    B8  
    B9  
    C1  
    C2  
    C3  
    C4  
    C5  
    C6  
    C7  
    C8  
    C9  
    D1  
    D2  
    D3  
    D4  
    D5  
    D6  
    D7  
    D8  
    D9  
    E1  
    E2  
    E3  
    E4  
    E5  
    E6  
    E7  
    E8  
    E9  
    F1  
    F2  
    F3  
    F4  
    F5  
    F6  
    F7  
    F8  
    F9  
    G1  
    G2  
    G3  
    G4  
    G5  
    G6  
    G7  
    G8  
    G9  
    H1  
    H2  
    H3  
    H4  
    H5  
    H6  
    H7  
    H8  
    H9  
    I1  
    I2  
    I3  
    I4  
    I5  
    I6  
    I7  
    I8  
    I9  
  • Method Summary

    Modifier and Type Method Description
    int getColumn()
    Gets the zero-indexed column of this board location.
    java.util.Collection<Square> getPeers()
    Gets a collection of all of this square's peers.
    int getRow()
    Gets the zero-indexed row of this board location.
    static Square valueOf​(int row, int column)
    Gets the square with the given row and column.
    static Square valueOf​(java.lang.String name)
    Returns the enum constant of this type with the specified name.
    static Square[] values()
    Returns an array containing the constants of this enum type, in the order they are declared.

    Methods inherited from class java.lang.Enum

    clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

  • Method Details

    • values

      public static Square[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static Square valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
      java.lang.NullPointerException - if the argument is null
    • getRow

      public int getRow()
      Gets the zero-indexed row of this board location. The first row is 0, the next row is 1, and so on. So, for example, square B4 would return 1, because "B" is the second row.
      Returns:
      the row of this square
    • getColumn

      public int getColumn()
      Gets the zero-indexed column of this board location. The first column is 0, the next column is 1, and so on. So, for example, square B4 would return 3, because the fourth column becomes 3 when zero-indexed.
      Returns:
      the column of this square
    • getPeers

      public java.util.Collection<Square> getPeers()
      Gets a collection of all of this square's peers. This includes all squares in the same row as this square, in the same column as this square, and in the same box (3-by-3) as this square. In other words, this is a collection of all squares that cannot have the same value as this one.
      Returns:
      all of this square's peers
    • valueOf

      public static Square valueOf​(int row, int column)
      Gets the square with the given row and column. This square's getRow() and getColumn() methods will return the same values passed into this method. For example, if row is 1 and column is 3, this method will return square B4.
      Parameters:
      row - the row of the desired square's location
      column - the column of the desired square's location
      Returns:
      the square at the given location