    001    /**
    002     *
    003     */
    004    package calhoun.util;
    005
    006    import java.io.Serializable;
    007    import java.util.Arrays;
    008
    009    public class DenseBooleanMatrix2D implements Serializable {
    010            private static final long serialVersionUID = 8033567052720988542L;
    011            boolean[] array;
    012            int length;
    013
    014            public DenseBooleanMatrix2D(int x, int y) {
    015                    array = new boolean[x*y];
    016                    length = y;
    017            }
    018
    019            public boolean getQuick(int x, int y) {
    020                    return array[x*length+y];
    021            }
    022
    023            public void setQuick(int x, int y, boolean val) {
    024                    array[x*length+y] = val;
    025            }
    026
    027            public void assign(boolean val) {
    028                    for(int i = 0; i<array.length; ++i) {
    029                            array[i]= val;
    030                    }
    031            }
    032
    033            @Override
    034            public String toString() {
    035                    StringBuffer b = new StringBuffer();
    036                    b.append('\n');
    037                    for(int i = 0; i<array.length/length;++i) {
    038                            int row = i*length;
    039                            for(int j = 0; j<length; ++j) {
    040                                    b.append(array[row+j]).append("   ");
    041                            }
    042                            b.append('\n');
    043                    }
    044                    return b.toString();
    045            }
    046
    047            @Override
    048            public boolean equals(Object rhs) {
    049                    DenseBooleanMatrix2D matrix = (DenseBooleanMatrix2D ) rhs;
    050
    051                    return Arrays.equals(array, matrix.array);
    052            }
    053    }