Coverage Report - eu.simuline.octave.type.OctaveSparseBoolean
 
Classes in this File Line Coverage Branch Coverage Complexity
OctaveSparseBoolean
79%
39/49
50%
9/18
2.333
 
 1  
 /*
 2  
  * Copyright 2007, 2008, 2009 Ange Optimization ApS
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package eu.simuline.octave.type;
 17  
 
 18  
 import java.util.Arrays;
 19  
 
 20  
 /**
 21  
  * Represents a Boolean matrix and is appropriate for sparse matrices. 
 22  
  *
 23  
  * @see OctaveBoolean
 24  
  */
 25  0
 public final class OctaveSparseBoolean implements OctaveObject {
 26  
 
 27  
     private static final int PRIME = 31;
 28  
 
 29  
     private final int rows;
 30  
 
 31  
     private final int columns;
 32  
 
 33  
     // number of non-zero, i.e. of non-false, i.e. of true. 
 34  
     // meant number of entries with value true. 
 35  
     // seems to be rowIndices.length which equals columnIndices.length. 
 36  
     private int nnz;
 37  
 
 38  
     private final int[] rowIndexes;
 39  
 
 40  
     private final int[] columnIndexes;
 41  
 
 42  
     private final boolean[] data;
 43  
 
 44  
     private OctaveSparseBoolean(final int rows,
 45  
                                 final int columns,
 46  
                                 final int nnz,
 47  
                                 final int[] rowIndexes,
 48  
                                 final int[] columnIndexes,
 49  20
                                 final boolean[] data) {
 50  20
         this.rows = rows;
 51  20
         this.columns = columns;
 52  20
         this.nnz = nnz;
 53  20
         this.rowIndexes = rowIndexes;
 54  20
         this.columnIndexes = columnIndexes;
 55  20
         this.data = data;
 56  20
     }
 57  
 
 58  
     /**
 59  
      * @param rows
 60  
      * @param columns
 61  
      * @param nnz
 62  
      */
 63  
     public OctaveSparseBoolean(final int rows,
 64  
                                final int columns,
 65  
                                final int nnz) {
 66  
         // ****         nnz=0
 67  20
         this(rows, columns, 0, new int[nnz], new int[nnz], new boolean[nnz]);
 68  20
     }
 69  
 
 70  
     @Override
 71  
     public OctaveSparseBoolean shallowCopy() {
 72  0
         return new OctaveSparseBoolean(this.rows,
 73  
                                        this.columns,
 74  
                                        this.nnz,
 75  
                                        this.rowIndexes,
 76  
                                        this.columnIndexes,
 77  
                                        this.data);
 78  
     }
 79  
 
 80  
     /**
 81  
      * @param value
 82  
      * @param row
 83  
      * @param column
 84  
      */
 85  
     @SuppressWarnings("checkstyle:nowhitespaceafter")
 86  
     public void set(final boolean value, final int row, final int column) {
 87  16
         this.data         [nnz] = value;
 88  16
         this.rowIndexes   [nnz] = row;
 89  16
         this.columnIndexes[nnz] = column;
 90  16
         ++this.nnz;
 91  16
     }
 92  
 
 93  
     /**
 94  
      * @return the rows
 95  
      */
 96  
     public int getRows() {
 97  12
         return this.rows;
 98  
     }
 99  
 
 100  
     /**
 101  
      * @return the columns
 102  
      */
 103  
     public int getColumns() {
 104  12
         return this.columns;
 105  
     }
 106  
 
 107  
     /**
 108  
      * @return the nnz
 109  
      */
 110  
     public int getNnz() {
 111  12
         return this.nnz;
 112  
     }
 113  
 
 114  
     /**
 115  
      * @return the rowIndexes
 116  
      */
 117  
     @edu.umd.cs.findbugs.annotations.SuppressWarnings
 118  
     (value = "EI_EXPOSE_REP", 
 119  
      justification = "Not woth fixing: class has to be rewritten anyway. ")
 120  
     public int[] getRowIndexes() {
 121  12
         return this.rowIndexes;
 122  
     }
 123  
 
 124  
     /**
 125  
      * @return the columnIndexes
 126  
      */
 127  
     @edu.umd.cs.findbugs.annotations.SuppressWarnings
 128  
     (value = "EI_EXPOSE_REP", 
 129  
      justification = "Not woth fixing: class has to be rewritten anyway. ")
 130  
     public int[] getColumnIndexes() {
 131  12
         return this.columnIndexes;
 132  
     }
 133  
 
 134  
     /**
 135  
      * @return the data
 136  
      */
 137  
     @edu.umd.cs.findbugs.annotations.SuppressWarnings
 138  
     (value = "EI_EXPOSE_REP", 
 139  
      justification = "Not woth fixing: class has to be rewritten anyway. ")
 140  
     public boolean[] getData() {
 141  12
         return this.data;
 142  
     }
 143  
 
 144  
     @Override
 145  
     public int hashCode() {
 146  6
         int result = 1;
 147  6
         result = PRIME * result + Arrays.hashCode(columnIndexes);
 148  6
         result = PRIME * result + columns;
 149  6
         result = PRIME * result + Arrays.hashCode(data);
 150  6
         result = PRIME * result + nnz;
 151  6
         result = PRIME * result + Arrays.hashCode(rowIndexes);
 152  6
         result = PRIME * result + rows;
 153  6
         return result;
 154  
     }
 155  
 
 156  
     @Override
 157  
     @SuppressWarnings("PMD.NPathComplexity")
 158  
     public boolean equals(final Object obj) {
 159  2
         if (this == obj) {
 160  0
             return true;
 161  
         }
 162  2
         if (obj == null) {
 163  0
             return false;
 164  
         }
 165  2
         if (getClass() != obj.getClass()) {
 166  0
             return false;
 167  
         }
 168  2
         final OctaveSparseBoolean other = (OctaveSparseBoolean) obj;
 169  2
         if (!Arrays.equals(this.columnIndexes, other.columnIndexes)) {
 170  0
             return false;
 171  
         }
 172  2
         if (this.columns != other.columns) {
 173  0
             return false;
 174  
         }
 175  2
         if (!Arrays.equals(this.data, other.data)) {
 176  0
             return false;
 177  
         }
 178  2
         if (this.nnz != other.nnz) {
 179  0
             return false;
 180  
         }
 181  2
         if (!Arrays.equals(this.rowIndexes, other.rowIndexes)) {
 182  0
             return false;
 183  
         }
 184  2
         return this.rows == other.rows;
 185  
         // if (rows != other.rows) {
 186  
         //     return false;
 187  
         // }
 188  
         // return true;
 189  
     }
 190  
 
 191  
 }