package edu.rice.hj.example.cnc.util; /** * @author Shams Imam (shams@rice.edu) */ public interface BlockIndices { double get(int i, int j); double delta(BlockIndices other); public static final class DefaultBlockIndices implements BlockIndices { public double get(final int i, final int j) { return 0; } public double delta(final BlockIndices other) { if (other instanceof DefaultBlockIndices) { return 0; } return other.delta(this); } } public static final class DataBlockIndices implements BlockIndices { public final double[][] block; public final int startRow; public final int endRow; public final int startCol; public final int endCol; public DataBlockIndices( final double[][] block, final int startRow, final int endRow, final int startCol, final int endCol) { this.block = block; this.startRow = startRow; this.endRow = endRow; this.startCol = startCol; this.endCol = endCol; } public double get(final int i, final int j) { return block[i - startRow][j - startCol]; } public double delta(final BlockIndices other) { double localDelta = 0; for (int i = startRow; i < endRow; i++) { for (int j = startCol; j < endCol; j++) { final double delta = Math.abs(get(i, j) - other.get(i, j)); localDelta = Math.max(localDelta, delta); } } return localDelta; } } }