Types: checkstyle and comments 06/306/2
Clément DAVID [Wed, 28 Apr 2010 15:46:28 +0000 (17:46 +0200)]
Pass the checkstyle metrics and comments
Pass findbugs (use Long.valuesOf instead of a new call)

Change-Id: Id862d08539ea389f0b7ea03ced45f418075b850d

scilab/modules/types/src/java/org/scilab/modules/types/scilabTypes/ScilabBoolean.java
scilab/modules/types/src/java/org/scilab/modules/types/scilabTypes/ScilabDouble.java
scilab/modules/types/src/java/org/scilab/modules/types/scilabTypes/ScilabInteger.java
scilab/modules/types/src/java/org/scilab/modules/types/scilabTypes/ScilabList.java
scilab/modules/types/src/java/org/scilab/modules/types/scilabTypes/ScilabMList.java
scilab/modules/types/src/java/org/scilab/modules/types/scilabTypes/ScilabString.java
scilab/modules/types/src/java/org/scilab/modules/types/scilabTypes/ScilabTList.java
scilab/modules/types/src/java/org/scilab/modules/types/scilabTypes/ScilabType.java

index 33d7cb9..96ee9b9 100644 (file)
@@ -1,6 +1,7 @@
 /*
  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  *  Copyright (C) 2009-2009 - DIGITEO - Bruno JOFRET
+ *  Copyright (C) 2010-2010 - DIGITEO - Clément DAVID
  * 
  *  This file must be used under the terms of the CeCILL.
  *  This source file is licensed as described in the file COPYING, which
@@ -93,7 +94,7 @@ public class ScilabBoolean implements ScilabType {
      *
      * @return true if empty
         */
-    public boolean isEmpty(){
+    public boolean isEmpty() {
        return (data == null);
     }
     
@@ -104,18 +105,19 @@ public class ScilabBoolean implements ScilabType {
      * @return the pretty print
         */
        public String toString() {
-               StringBuffer result = new StringBuffer();
+               StringBuilder result = new StringBuilder();
+               
                if (isEmpty()) {
                        result.append("[]");
                        return result.toString();
                }
 
                result.append("[");
-               for (int i = 0 ; i < getHeight() ; ++i) {
-                       for (int j = 0 ; j < getWidth() ; ++j) {
-                               if (getData()[i][j] == true){
+               for (int i = 0; i < getHeight(); ++i) {
+                       for (int j = 0; j < getWidth(); ++j) {
+                               if (getData()[i][j]) {
                                        result.append("%t");
-                               }else{
+                               } else {
                                        result.append("%f");
                                }
                                if (j != getWidth() - 1) {
index ef80e2f..a1d82ca 100644 (file)
@@ -1,6 +1,7 @@
 /*
  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  *  Copyright (C) 2009-2009 - DIGITEO - Bruno JOFRET
+ *  Copyright (C) 2010-2010 - DIGITEO - Clément DAVID
  * 
  *  This file must be used under the terms of the CeCILL.
  *  This source file is licensed as described in the file COPYING, which
@@ -21,17 +22,30 @@ public class ScilabDouble implements ScilabType {
        private double[][] realPart;
        private double[][] imaginaryPart;
 
+       /**
+        * Default constructor
+        */
        public ScilabDouble() {
                realPart = null;
                imaginaryPart = null;
        }
 
+       /**
+        * Constructor with a unique value.
+        * @param data the unique value
+        */
        public ScilabDouble(double data) {
                realPart = new double[1][1];
                realPart[0][0] = data;
                imaginaryPart = null;
        }
 
+       /**
+        * Constructor with a unique complex value.
+        * 
+        * @param realData the real part
+        * @param imagData the complex part 
+        */
        public ScilabDouble(double realData, double imagData) {
                realPart = new double[1][1];
                realPart[0][0] = realData;
@@ -39,40 +53,85 @@ public class ScilabDouble implements ScilabType {
                imaginaryPart[0][0] = imagData;
        }
 
+       /**
+        * Constructor with a matrix of real data.
+        * 
+        * @param data the data
+        */
        public ScilabDouble(double[][] data) {
                realPart = data;
                imaginaryPart = null;
        }
 
+       /**
+        * Constructor with a matrix of complex numbers 
+        * 
+        * @param realData the real part of the data
+        * @param imagData the imaginary part of the data
+        */
        public ScilabDouble(double[][] realData, double[][] imagData) {
                realPart = realData;
                imaginaryPart = imagData;
        }
 
+       /**
+        * Check the emptiness of the associated data.
+        * @return true, if the associated data array is empty. 
+        */
        public boolean isEmpty() {
                return (realPart == null && imaginaryPart == null);
        }
 
+       /**
+        * Check if the current data doesn't have an imaginary part.
+        * 
+        * @return true, if the data are real only.
+        */
        public boolean isReal() {
                return (imaginaryPart == null);
        }
 
+       /**
+        * Get the real part of the data.
+        * 
+        * @return the real part.
+        */
        public double[][] getRealPart() {
                return realPart;
        }
 
+       /**
+        * Set the real part of the data.
+        * 
+        * @param realPart the real part.
+        */
        public void setRealPart(double[][] realPart) {
                this.realPart = realPart;
        }
 
+       /**
+        * Get the imaginary part of the data.
+        * 
+        * @return the imaginary part.
+        */
        public double[][] getImaginaryPart() {
                return imaginaryPart;
        }
 
+       /**
+        * Set the imaginary part of the data.
+        * 
+        * @param imaginaryPart the imaginary part.
+        */
        public void setImaginaryPart(double[][] imaginaryPart) {
                this.imaginaryPart = imaginaryPart;
        }
 
+       /**
+        * @return the height of the data matrix
+        * @see org.scilab.modules.types.scilabTypes.ScilabType#getHeight()
+        */
+       @Override
        public int getHeight() {
                if (isEmpty()) {
                        return 0;
@@ -80,29 +139,39 @@ public class ScilabDouble implements ScilabType {
                return realPart.length;
        }
 
+       /**
+        * @return the width of the data matrix
+        * @see org.scilab.modules.types.scilabTypes.ScilabType#getWidth()
+        */
+       @Override
        public int getWidth() {
-               if (isEmpty()|| realPart.length  == 0 ) {
+               if (isEmpty() || realPart.length  == 0) {
                        return 0;
                }
                
                return realPart[0].length;
        }
 
+       /**
+        * @return a Scilab-like String representation of the data.
+        * @see java.lang.Object#toString()
+        */
+       @Override
        public String toString() {
-               StringBuffer result = new StringBuffer();
+               StringBuilder result = new StringBuilder();
+               
                if (isEmpty()) {
                        result.append("[]");
                        return result.toString();
                }
 
                result.append("[");
-               for (int i = 0 ; i < getHeight() ; ++i) {
-                       for (int j = 0 ; j < getWidth() ; ++j) {
-                               if(isReal()) {
+               for (int i = 0; i < getHeight(); ++i) {
+                       for (int j = 0; j < getWidth(); ++j) {
+                               if (isReal()) {
                                        result.append(getRealPart()[i][j]);
-                               }
-                               else {
-                                       result.append(getRealPart()[i][j]+" + "+getImaginaryPart()[i][j]+" %i");
+                               } else {
+                                       result.append(getRealPart()[i][j] + " + " + getImaginaryPart()[i][j] + " %i");
                                }
                                if (j != getWidth() - 1) {
                                        result.append(", ");
@@ -113,6 +182,7 @@ public class ScilabDouble implements ScilabType {
                        }
                }
                result.append("]");
+               
                return result.toString();
        }
 
index 9f406ca..483ede8 100644 (file)
@@ -21,113 +21,201 @@ public class ScilabInteger implements ScilabType {
        private IntegerType prec;
        private boolean bUnsigned;
 
-       public enum IntegerType{
+       /**
+        * The different size of the integer type.
+        */
+       public enum IntegerType {
                /** Integer of size 8 */
                TYPE8,
                /** Integer of size 16 */
-                       TYPE16,
+               TYPE16,
                /** Integer of size 32 */
-                       TYPE32,
+               TYPE32,
                /** Integer of size 64 */
-                       TYPE64
-                       }
+               TYPE64
+       }
        
+       /**
+        * Default constructor
+        */
        public ScilabInteger() {
                data = null;
        }
 
+       /**
+        * Constructor with values
+        * 
+        * @param data the values
+        * @param bUnsigned true, if the values are unsigned; false if they are signed.
+        */
        public ScilabInteger(byte[][] data, boolean bUnsigned) {
                this.setData(data, bUnsigned);
        }
 
+       /**
+        * Constructor with values
+        * 
+        * @param data the values
+        * @param bUnsigned true, if the values are unsigned; false if they are signed.
+        */
        public ScilabInteger(short[][] data, boolean bUnsigned) {
                this.setData(data, bUnsigned);
        }
 
+       /**
+        * Constructor with values
+        * 
+        * @param data the values
+        * @param bUnsigned true, if the values are unsigned; false if they are signed.
+        */
        public ScilabInteger(int[][] data, boolean bUnsigned) {
                this.setData(data, bUnsigned);
        }
 
+       /**
+        * Constructor with values
+        * 
+        * @param data the values
+        * @param bUnsigned true, if the values are unsigned; false if they are signed.
+        */
        public ScilabInteger(long[][] data, boolean bUnsigned) {
                this.setData(data, bUnsigned);
        }
 
+       /**
+        * Constructor with single signed value
+        * 
+        * @param value the unique value
+        */
        public ScilabInteger(byte value) {
                this.data = new Long[1][1];
-               this.data[0][0] = new Long(value);
+               this.data[0][0] = Long.valueOf(value);
        }
 
+       /**
+        * Constructor with single signed value
+        * 
+        * @param value the unique value
+        */
        public ScilabInteger(short value) {
                this.data = new Long[1][1];
-               this.data[0][0] = new Long(value);
+               this.data[0][0] = Long.valueOf(value);
        }
 
+       /**
+        * Constructor with single signed value
+        * 
+        * @param value the unique value
+        */
        public ScilabInteger(int value) {
                this.data = new Long[1][1];
-               this.data[0][0] = new Long(value);
+               this.data[0][0] = Long.valueOf(value);
        }
 
+       /**
+        * Constructor with single signed value
+        * 
+        * @param value the unique value
+        */
        public ScilabInteger(long value) {
                this.data = new Long[1][1];
-               this.data[0][0] = new Long(value);
+               this.data[0][0] = Long.valueOf(value);
        }
 
+       /**
+        * Set the current values 
+        * 
+        * @param data the values to set
+        * @param bUnsigned true, if these values are unsigned; false otherwise.
+        */
        public void setData(byte[][] data, boolean bUnsigned) {
                this.data = new Long[data.length][data[0].length];
                prec = IntegerType.TYPE8;
                this.bUnsigned = bUnsigned; 
-               for(int i = 0 ; i < data.length ; i++) {
-                       for(int j = 0 ; j < data[0].length ; j++) {
-                               this.data[i][j] = new Long(data[i][j]);
+               for (int i = 0; i < data.length; i++) {
+                       for (int j = 0; j < data[0].length; j++) {
+                               this.data[i][j] = Long.valueOf(data[i][j]);
                        }
                }
        }
 
+       /**
+        * Set the current values 
+        * 
+        * @param data the values to set
+        * @param bUnsigned true, if these values are unsigned; false otherwise.
+        */
        public void setData(short[][] data, boolean bUnsigned) {
                this.data = new Long[data.length][data[0].length];
                prec = IntegerType.TYPE16;
                this.bUnsigned = bUnsigned; 
-               for(int i = 0 ; i < data.length ; i++) {
-                       for(int j = 0 ; j < data[0].length ; j++) {
-                               this.data[i][j] = new Long(data[i][j]);
+               for (int i = 0; i < data.length; i++) {
+                       for (int j = 0; j < data[0].length; j++) {
+                               this.data[i][j] = Long.valueOf(data[i][j]);
                        }
                }
        }
 
+       /**
+        * Set the current values 
+        * 
+        * @param data the values to set
+        * @param bUnsigned true, if these values are unsigned; false otherwise.
+        */
        public void setData(int[][] data, boolean bUnsigned) {
                this.data = new Long[data.length][data[0].length];
                prec = IntegerType.TYPE32;
                this.bUnsigned = bUnsigned; 
-               for(int i = 0 ; i < data.length ; i++) {
-                       for(int j = 0 ; j < data[0].length ; j++) {
-                               this.data[i][j] = new Long(data[i][j]);
+               for (int i = 0; i < data.length; i++) {
+                       for (int j = 0; j < data[0].length; j++) {
+                               this.data[i][j] = Long.valueOf(data[i][j]);
                        }
                }
        }
 
+       /**
+        * Set the current values 
+        * 
+        * @param data the values to set
+        * @param bUnsigned true, if these values are unsigned; false otherwise.
+        */
        public void setData(long[][] data, boolean bUnsigned) {
                this.data = new Long[data.length][data[0].length];
                prec = IntegerType.TYPE64;
                this.bUnsigned = bUnsigned; 
-               for(int i = 0 ; i < data.length ; i++) {
-                       for(int j = 0 ; j < data[0].length ; j++) {
-                               this.data[i][j] = new Long(data[i][j]);
+               for (int i = 0; i < data.length; i++) {
+                       for (int j = 0; j < data[0].length; j++) {
+                               this.data[i][j] = Long.valueOf(data[i][j]);
                        }
                }
        }
 
+       /**
+        * @return the values
+        */
        public Long[][] getData() {
                return data;
        }
        
+       /**
+        * @return the precision of the values
+        */
        public IntegerType getPrec() {
                return prec;
        }
 
+       /**
+        * @return true, if the values are signed, false otherwise.
+        */
        public boolean isUnsigned() {
                return bUnsigned;
        }
 
+       /**
+        * @return the height of the value matrix
+        * @see org.scilab.modules.types.scilabTypes.ScilabType#getHeight()
+        */
+       @Override
        public int getHeight() {
                if (data == null) {
                        return 0;
@@ -135,6 +223,11 @@ public class ScilabInteger implements ScilabType {
                return data.length;
        }
 
+       /**
+        * @return the width of the value matrix
+        * @see org.scilab.modules.types.scilabTypes.ScilabType#getWidth()
+        */
+       @Override
        public int getWidth() {
                if (data == null) {
                        return 0;
@@ -145,12 +238,20 @@ public class ScilabInteger implements ScilabType {
        // int32(X), int8(x) , int16([x,x,x;x,x,x])
        //       uint32(X), uint8(x) , uint16([x,x,x;x,x,x])
        
-    public boolean isEmpty(){
+       /**
+        * @return true, if there is no values; false otherwise.
+        */
+    public boolean isEmpty() {
        return (data == null);
     }
        
+    /**
+     * @return the pretty-printed values 
+     * @see java.lang.Object#toString()
+     */
+    @Override
        public String toString() {
-               StringBuffer result = new StringBuffer();
+       StringBuilder result = new StringBuilder();
                
                
                if (isEmpty()) {
@@ -158,23 +259,47 @@ public class ScilabInteger implements ScilabType {
                        return result.toString();
                }
                
-               if (isUnsigned() ){
+               if (isUnsigned()) {
                        result.append("u");
                }
                result.append("int");
-               if (getPrec() == IntegerType.TYPE8){
+               
+               switch (getPrec()) {
+               case TYPE8:
                        result.append("8");
-               } else if (getPrec() == IntegerType.TYPE16){
-                       result.append("16");            
-               } else if (getPrec() == IntegerType.TYPE32){
+                       break;
+
+               case TYPE16:
+                       result.append("16");
+                       break;
+                       
+               case TYPE32:
                        result.append("32");
-               } else if (getPrec() == IntegerType.TYPE64){
+                       break;
+                       
+               case TYPE64:
                        result.append("64");
+                       break;
+                       
+               default:
+                       break;
                }
 
                result.append("(");
-               for (int i = 0 ; i < getHeight() ; ++i) {
-                       for (int j = 0 ; j < getWidth() ; ++j) {
+               appendData(result);
+               result.append(")");
+       
+               return result.toString();
+       }
+
+       /**
+        * Put each value on the buffer.
+        * 
+        * @param result the current buffer
+        */
+       private void appendData(StringBuilder result) {
+               for (int i = 0; i < getHeight(); ++i) {
+                       for (int j = 0; j < getWidth(); ++j) {
 
                                result.append(getData()[i][j]);
                                
@@ -187,9 +312,6 @@ public class ScilabInteger implements ScilabType {
                                result.append(" ; ");
                        }
                }
-               result.append(")");
-       
-               return result.toString();
        }
        
 }
index f92845b..6b0f6e9 100644 (file)
@@ -38,6 +38,10 @@ public class ScilabList extends ArrayList<ScilabType> implements ScilabType {
                super(c);
        }
        
+       /**
+        * @return 1 when there is data on the list, 0 otherwise.
+        * @see org.scilab.modules.types.scilabTypes.ScilabType#getHeight()
+        */
     public int getHeight() {
                if (isEmpty()) {
                        return 0;
@@ -45,6 +49,10 @@ public class ScilabList extends ArrayList<ScilabType> implements ScilabType {
                return 1;
     }
 
+    /**
+     * @return 1 when there is data on the list, 0 otherwise.
+     * @see org.scilab.modules.types.scilabTypes.ScilabType#getWidth()
+     */
     public int getWidth() {
                if (isEmpty()) {
                        return 0;
@@ -52,7 +60,10 @@ public class ScilabList extends ArrayList<ScilabType> implements ScilabType {
                return size();
     }
 
-
+    /**
+     * @return the pretty-printed data 
+     * @see java.util.AbstractCollection#toString()
+     */
     public String toString() {
 
                StringBuffer result = new StringBuffer();
@@ -62,7 +73,7 @@ public class ScilabList extends ArrayList<ScilabType> implements ScilabType {
                }
 
                result.append("list(");
-               for (int i = 0 ; i < size() ; i++){
+               for (int i = 0; i < size(); i++) {
                        result.append(get(i).toString());
                        if (i != size() - 1) {
                                result.append(",\n");
index 22f255a..879d4d8 100644 (file)
@@ -62,6 +62,10 @@ public class ScilabMList extends ArrayList<ScilabType> implements ScilabType {
        addAll(c);
     }
     
+    /**
+     * @return 1 when there is data on the list, 0 otherwise.
+     * @see org.scilab.modules.types.scilabTypes.ScilabType#getHeight()
+     */
        public int getHeight() {
                if (isEmpty()) {
                        return 0;
@@ -69,6 +73,10 @@ public class ScilabMList extends ArrayList<ScilabType> implements ScilabType {
                return 1;
        }
 
+       /**
+     * @return 1 when there is data on the list, 0 otherwise.
+        * @see org.scilab.modules.types.scilabTypes.ScilabType#getWidth()
+        */
        public int getWidth() {
                if (isEmpty()) {
                        return 0;
@@ -76,7 +84,10 @@ public class ScilabMList extends ArrayList<ScilabType> implements ScilabType {
                return size();
        }
        
-
+    /**
+     * @return the pretty-printed data 
+     * @see java.util.AbstractCollection#toString()
+     */
        public String toString() {
                
                StringBuffer result = new StringBuffer();
@@ -86,7 +97,7 @@ public class ScilabMList extends ArrayList<ScilabType> implements ScilabType {
                }
 
                result.append("mlist");
-               for (int i = 0 ; i < size() ; i++){
+               for (int i = 0; i < size(); i++) {
                        result.append(get(i).toString());
                        if (i != size() - 1) {
                                result.append(", ");
index 4c01a0a..e93a031 100644 (file)
@@ -19,42 +19,72 @@ public class ScilabString implements ScilabType {
 
        private String[][] data;
 
+       /**
+        * Default constructor
+        */
     public ScilabString() {
                data = null;
     }
     
+    /**
+     * Constructor with data.
+     * 
+     * @param data the associated data.
+     */
     public ScilabString(String[][] data) {
                this.data = data;
     }
     
+    /**
+     * Constructor with vector data.
+     * 
+     * @param data the column vector data 
+     */
     public ScilabString(String[] data) {
-               if(data == null || data.length == 0) {
+               if (data == null || data.length == 0) {
                        this.data = new String[1][1];
                        this.data[0][0] = "";
                } else {
                        this.data = new String[1][data.length];
-                       for (int i = 0 ; i < data.length ; i++){
-                               this.data[0][i] = data[i] ;
+                       for (int i = 0; i < data.length; i++) {
+                               this.data[0][i] = data[i];
                        }
                }
     }
     
+    /**
+     * Constructor with a unique value
+     * 
+     * @param string the value
+     */
     public ScilabString(String string) {
-               if(string == null) {
-                       System.err.println("string == null");
+               if (string == null) {
+                       throw new IllegalArgumentException("string == null");
                }
                this.data = new String[1][1];
                this.data[0][0] = string;
     }
 
+    /**
+     * Set the values.
+     * 
+     * @param data the values
+     */
     public void setData(String[][] data) {
                this.data = data;
     }
 
+    /**
+     * @return the associated values
+     */
     public String[][] getData() {
                return data;
     }
     
+       /**
+        * @return the height of the data matrix
+        * @see org.scilab.modules.types.scilabTypes.ScilabType#getHeight()
+        */
     public int getHeight() {
                if (data == null) {
                        return 0;
@@ -62,6 +92,10 @@ public class ScilabString implements ScilabType {
                return data.length;
        }
 
+       /**
+        * @return the width of the data matrix
+        * @see org.scilab.modules.types.scilabTypes.ScilabType#getWidth()
+        */
        public int getWidth() {
                if (data == null) {
                        return 0;
@@ -69,10 +103,18 @@ public class ScilabString implements ScilabType {
                return data[0].length;
        }
     
-    public boolean isEmpty(){
+       /**
+        * Check the emptiness of the associated data.
+        * @return true, if the associated data array is empty. 
+        */
+    public boolean isEmpty() {
        return (data == null);
     }
-
+    
+       /**
+        * @return a Scilab-like String representation of the data.
+        * @see java.lang.Object#toString()
+        */
        public String toString() {
                StringBuffer result = new StringBuffer();
                if (isEmpty()) {
@@ -81,8 +123,8 @@ public class ScilabString implements ScilabType {
                }
 
                result.append("[");
-               for (int i = 0 ; i < getHeight() ; ++i) {
-                       for (int j = 0 ; j < getWidth() ; ++j) {
+               for (int i = 0; i < getHeight(); ++i) {
+                       for (int j = 0; j < getWidth(); ++j) {
 
                                result.append('"');
                                result.append(getData()[i][j]);
index 5a1a20c..deebea9 100644 (file)
@@ -62,6 +62,10 @@ public class ScilabTList extends ArrayList<ScilabType> implements ScilabType {
        addAll(c);
     }
     
+    /**
+     * @return 1 when there is data on the list, 0 otherwise.
+     * @see org.scilab.modules.types.scilabTypes.ScilabType#getHeight()
+     */
        public int getHeight() {
                if (isEmpty()) {
                        return 0;
@@ -69,6 +73,10 @@ public class ScilabTList extends ArrayList<ScilabType> implements ScilabType {
                return 1;
        }
 
+       /**
+     * @return 1 when there is data on the list, 0 otherwise.
+        * @see org.scilab.modules.types.scilabTypes.ScilabType#getWidth()
+        */
        public int getWidth() {
                if (isEmpty()) {
                        return 0;
@@ -76,7 +84,10 @@ public class ScilabTList extends ArrayList<ScilabType> implements ScilabType {
                return size();
        }
        
-
+       /**
+        * @return the pretty-printed data
+        * @see java.util.AbstractCollection#toString()
+        */
        public String toString() {
                
                StringBuffer result = new StringBuffer();
@@ -86,7 +97,7 @@ public class ScilabTList extends ArrayList<ScilabType> implements ScilabType {
                }
 
                result.append("tlist(");
-               for (int i = 0 ; i < size() ; i++){
+               for (int i = 0; i < size(); i++) {
                        result.append(get(i).toString());
                        if (i != size() - 1) {
                                result.append(", ");
index 9abd5da..2db531a 100644 (file)
@@ -24,19 +24,26 @@ public interface ScilabType extends Serializable, Cloneable {
      *
      * @return the width
         */
-       public int getWidth();
+       int getWidth();
        
     /**
      * Return the height (number of elements) of the stored data
      *
      * @return the height
         */
-       public int getHeight();
+       int getHeight();
+       
+       /**
+        * Check if the current instance is empty.
+        * 
+        * @return true, the there is no data; false otherwise.
+        */
+       boolean isEmpty();
        
     /**
      * Display the data
      *
      * @return the pretty print
         */
-       public String toString();
+       String toString();
 }