gt:         if (!isEditable(x, y)) return;
context: /* Grid created on 30.01.2006 */
  package com.devng.starsudoku;
  
  import com.devng.starsudoku.io.SerGrid;
  
  import java.util.ArrayList;
  
  public class SudokuGrid {
  
      public static final int MASK_X = 0xF0000000;
      public static final int MASK_Y = 0x0F000000;
      public static final int MASK_PUZZLE_VAL = 0x000000F0;
      public static final int MASK_GRID_VAL = 0x0000000F;
      public static final int MASK_NOTES = 0x0001FF00;
      public static final int MASK_IS_DEFAULT = 0x00100000;
      public static final int MASK_IS_EDITABLE = 0x00200000;
  
      private static final int HEX1FF = 0x1ff;
  
      private int[][] grid;
  
      private ArrayList<SudokuObserver> observers;
      private boolean hasChanged;
  
      private int[] vertical;
      private int[] horizontal;
      private int[] square;
  
      public SudokuGrid() {
          grid = new int[9][9];
          int val = 0;
  
          for (int i = 0; i < 9; i++) {
              for (int j = 0; j < 9; j++) {
                  val = j << 28; //X
                  val += i << 24; //Y
                  val += MASK_IS_EDITABLE; //IS EDITABLE
                  grid[j][i] = val;
              }
          }
  
          observers = new ArrayList<>(4);
          hasChanged = false;
  
          vertical = new int[9];
          horizontal = new int[9];
          square = new int[9];
      }
  
      public int getRealGridVal(int x, int y) {
          if ((y < 0) || (y > 8) || (x < 0) || (x > 8)) {
              throw new IllegalArgumentException("Invalid cell address.");
          }
  
          return grid[x][y];
      }
  
      public static int getX(int cell) {
          return (cell & SudokuGrid.MASK_X) >>> 28;
      }
  
      public static int getY(int cell) {
          return (cell & SudokuGrid.MASK_Y) >>> 24;
      }
  
      public int getGridVal(int x, int y) {
          if ((y < 0) || (y > 8) || (x < 0) || (x > 8)) {
              throw new IllegalArgumentException("Invalid cell address.");
          }
  
          return grid[x][y] & MASK_GRID_VAL;
      }
  
      public static int getGridVal(int SudokuRealGridVal) {
  
          return (SudokuRealGridVal & MASK_GRID_VAL);
      }
  
      public int getPuzzleVal(int x, int y) {
          if ((y < 0) || (y > 8) || (x < 0) || (x > 8)) {
              throw new IllegalArgumentException("Invalid cell address.");
          }
  
          return ((grid[x][y] & MASK_PUZZLE_VAL) >>> 4);
      }
  
      public static int getPuzzleVal(int SudokuRealGridVal) {
  
          return ((SudokuRealGridVal & MASK_PUZZLE_VAL) >>> 4);
      }
  
      /**
       * @return gridVal if isDefault = true else puzzleVal
       */
      public int getVal(int x, int y) {
          if (isDefault(x, y)) {
              return getGridVal(x, y);
          } else {
              return getPuzzleVal(x, y);
          }
      }
  
      public static boolean getNote(int realGridVal, int note) {
          note = realGridVal & (1 << (note - 1 + 8));
          if (note != 0) {
              return true;
          }
          return false;
      }
  
      public boolean isDefault(int x, int y) {
          if ((y < 0) || (y > 8) || (x < 0) || (x > 8)) {
              throw new IllegalArgumentException("Invalid cell address.");
          }
  
          if ((grid[x][y] & MASK_IS_DEFAULT) == MASK_IS_DEFAULT) {
              return true;
          }
          return false;
      }
  
      public static boolean isDefault(int realGridVal) {
          if ((realGridVal & MASK_IS_DEFAULT) == MASK_IS_DEFAULT) {
              return true;
          }
          return false;
      }
  
      public boolean isEditable(int x, int y) {
          if ((y < 0) || (y > 8) || (x < 0) || (x > 8)) {
              throw new IllegalArgumentException("Invalid cell address.");
          }
  
          if ((grid[x][y] & MASK_IS_EDITABLE) == MASK_IS_EDITABLE) {
              return true;
          }
          return false;
      }
  
      public static boolean isEditable(int realGridVal) {
          if ((realGridVal & MASK_IS_EDITABLE) == MASK_IS_EDITABLE) {
              return true;
          }
          return false;
      }
  
      //OBSERVERS SET CHANGE METHODS BEGIN:
      public void setRealGridVal(int realGridVal) {
          int x = SudokuGrid.getX(realGridVal);
          int y = SudokuGrid.getY(realGridVal);
          grid[x][y] = realGridVal;
          setChanged();
          notifyObservers(realGridVal);
      }
  
      public void setGridVal(int x, int y, int val) {
          if (!isEditable(x, y)) return;
          if (val < 0 || val > 9) {
              throw new IllegalArgumentException("Cell value is illegal.");
          }
  
          grid[x][y] &= ~MASK_GRID_VAL;
          grid[x][y] |= val;
  
          setChanged();
          notifyObservers(grid[x][y]);
      }
  
      public void setPuzzleVal(int x, int y, int val) {
          if (!isEditable(x, y)) return;
          if (val < 0 || val > 9) {
              throw new IllegalArgumentException("Cell value is illegal.");
          }
  
          if (getPuzzleVal(x, y) == val) {
              grid[x][y] &= ~MASK_PUZZLE_VAL;
          } else {
              grid[x][y] &= ~MASK_PUZZLE_VAL;
              grid[x][y] |= (val << 4);
          }
  
          setChanged();
          notifyObservers(grid[x][y]);
      }
  
      public void setDefault(int x, int y, boolean b) {
          if (!isEditable(x, y)) return;
  
          if (b) {
              grid[x][y] |= MASK_IS_DEFAULT;
          } else {
              grid[x][y] &= ~MASK_IS_DEFAULT;
          }
          setChanged();
          notifyObservers(grid[x][y]);
      }
  
      public void setEditable(int x, int y, boolean b) {
          if (b) {
              grid[x][y] |= MASK_IS_EDITABLE;
          } else {
              grid[x][y] &= ~MASK_IS_EDITABLE;
          }
          setChanged();
          notifyObservers(grid[x][y]);
      }
  
      public void setNote(int x, int y, int note) {
          if (!isEditable(x, y)) return;
          if (note < 1 || note > 9) {
              throw new IllegalArgumentException("Illegal Note. Note must be form 1 to 9 (inclusive).");
          }
          grid[x][y] ^= (1 << (note - 1 + 8));
  
          setChanged();
          notifyObservers(grid[x][y]);
      }
  
      public void deleteNote(int x, int y, int note) {
          if (!isEditable(x, y)) return;
          if (note < 1 || note > 9) {
              throw new IllegalArgumentException("Illegal note position. Note position must be form 1 to 9 (inclusive).");
          }
          grid[x][y] &= ~(1 << (note - 1 + 8));
  
          setChanged();
          notifyObservers(grid[x][y]);
      }
  
      public void deleteAllNotes(int x, int y) {
  