BitMatrix.java
Go to the documentation of this file.
00001 /*
00002  * Copyright Dept. of Mathematics & Computer Science Univ. Paris-Descartes
00003  *
00004  * This software is governed by the CeCILL  license under French law and
00005  * abiding by the rules of distribution of free software.  You can  use,
00006  * modify and/ or redistribute the software under the terms of the CeCILL
00007  * license as circulated by CEA, CNRS and INRIA at the following URL
00008  * "http://www.cecill.info".
00009  *
00010  * As a counterpart to the access to the source code and  rights to copy,
00011  * modify and redistribute granted by the license, users are provided only
00012  * with a limited warranty  and the software's author,  the holder of the
00013  * economic rights,  and the successive licensors  have only  limited
00014  * liability.
00015  *
00016  * In this respect, the user's attention is drawn to the risks associated
00017  * with loading,  using,  modifying and/or developing or reproducing the
00018  * software by the user in light of its specific status of free software,
00019  * that may mean  that it is complicated to manipulate,  and  that  also
00020  * therefore means  that it is reserved for developers  and  experienced
00021  * professionals having in-depth computer knowledge. Users are therefore
00022  * encouraged to load and test the software's suitability as regards their
00023  * requirements in conditions enabling the security of their systems and/or
00024  * data to be ensured and,  more generally, to use and operate it in the
00025  * same conditions as regards security.
00026  *
00027  * The fact that you are presently reading this means that you have had
00028  * knowledge of the CeCILL license and that you accept its terms.
00029  */
00030 
00031 //package pddl4j.graphplan;
00032 
00033 import java.io.Serializable;
00034 import java.util.Arrays;
00035 import java.util.BitSet;
00036 
00043 final class BitMatrix implements Cloneable, Serializable {
00044     
00048     private static final long serialVersionUID = 2831903376066135583L;
00049     
00053     private int rows;
00054     
00058     private int columns;
00059     
00063     private BitSet[] bitsets;
00064     
00071     public BitMatrix(final int rows, final int columns) {
00072         this.rows = rows;
00073         this.columns = columns;
00074         this.bitsets = new BitSet[this.rows];
00075         for (int i = 0; i < this.rows; i++) {
00076             this.bitsets[i] = new BitSet(this.columns);
00077         }
00078     }
00079     
00085     public BitMatrix(int size) {
00086         this(size, size);
00087     }
00088     
00095     public void set(int i, int j) {
00096         this.bitsets[i].set(j);
00097     }
00098     
00105     public void clear(int i, int j) {
00106         this.bitsets[i].clear(j);
00107     }
00108     
00115     public BitSet getRow(int i) {
00116         return this.bitsets[i];
00117     }
00118     
00125     public BitSet getColumn(int j) {
00126         BitSet column = new BitSet(this.rows);
00127         for (int i = 0; i < this.rows; i++) {
00128             column.set(i, this.bitsets[i].get(j));
00129         }
00130         return column;
00131     }
00132     
00140     public boolean get(int i, int j) {
00141         return this.bitsets[i].get(j);
00142     }
00143     
00150     public int cardinality() {
00151         int cardinality = 0;
00152         for (int i = 0; i < this.rows; i++) {
00153             cardinality += this.bitsets[i].cardinality();
00154         }
00155         return cardinality;
00156     }
00157     
00163     public int columns() {
00164         return this.columns;
00165     }
00166     
00172     public int rows() {
00173         return this.rows;
00174     }
00175     
00182     public Object clone() {
00183         try {
00184             final BitMatrix clone = (BitMatrix) super.clone();
00185             System.arraycopy(this.bitsets, 0, clone.bitsets, 0, this.bitsets.length);
00186             return clone;
00187         } catch (CloneNotSupportedException e) {
00188           throw new InternalError();
00189         }
00190     }
00191     
00200     public boolean equals(Object obj) {
00201         if (obj != null && obj instanceof BitMatrix) {
00202             BitMatrix other = (BitMatrix) obj;
00203             return Arrays.equals(this.bitsets, other.bitsets);
00204         }
00205         return false;
00206     }
00207     
00214     public int hashCode() {
00215         return Arrays.hashCode(this.bitsets);
00216     }
00217     
00223     public String toString() {
00224         return Arrays.toString(this.bitsets);
00225     }
00226 }


tug_ist_diagnosis_repair
Author(s): Safdar Zaman
autogenerated on Mon Jan 6 2014 11:51:12