View Javadoc

1   /*
2    * @(#)$Id: DoubleVector.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author       :   Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose      : 	Implements a vector of double values and provides
7    *                  some basic functionality.
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date             Who         Reason
14   *
15   * Dec 26, 2006     ukurmann    Initial Release
16   * Mar 22, 2007     bsigner     Cleanup
17   *
18   * -----------------------------------------------------------------------
19   *
20   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
21   *
22   * This software is the proprietary information of ETH Zurich.
23   * Use is subject to license terms.
24   * 
25   */
26  
27  
28  package org.ximtec.igesture.util;
29  
30  import java.util.ArrayList;
31  
32  import org.sigtec.util.Constant;
33  
34  
35  /**
36   * Implements a vector of double values and provides some basic functionality.
37   * 
38   * @version 1.0, Dec 2006
39   * @author Ueli Kurmann, igesture@uelikurmann.ch
40   * @author Beat Signer, signer@inf.ethz.ch
41   */
42  public class DoubleVector extends ArrayList<Double> {
43  
44     /**
45      * Constructs a new double vector.
46      * 
47      * @param size the initial size of the double vector.
48      */
49     public DoubleVector(int size) {
50        super(size);
51  
52        for (int i = 0; i < size; i++) {
53           add(i, 0d);
54        }
55  
56     }
57  
58  
59     /**
60      * Returns a double array of the vector's content.
61      * 
62      * @return a double array of the vector's content.
63      */
64     public double[] toDoubleArray() {
65        final double[] result = new double[size()];
66  
67        for (int i = 0; i < size(); i++) {
68           result[i] = get(i);
69        }
70  
71        return result;
72     } // toDoubleArray
73  
74  
75     @Override
76     public String toString() {
77        final StringBuilder sb = new StringBuilder();
78  
79        for (final double d : this) {
80  
81           if (String.valueOf(d).length() > 6) {
82              sb.append(String.valueOf(d).substring(0, 6) + Constant.BLANK);
83           }
84           else {
85              sb.append((String.valueOf(d) + "     ").substring(0, 6)
86                    + Constant.BLANK);
87           }
88  
89        }
90  
91        return Constant.OPEN_ANGULAR_BRACKET + sb.toString().trim()
92              + Constant.CLOSE_ANGULAR_BRACKET;
93     } // toString
94  
95  }