1 /*
2 * @(#)$Id: BigDecimalVector.java 689 2009-07-22 00:10:27Z bsigner $
3 *
4 * Author : Ueli Kurmann, ueli.kurmann@bbv.ch
5 *
6 * Purpose : Implements a vector of BigDecimal values and provides
7 * some basic functionality.
8 *
9 * -----------------------------------------------------------------------
10 *
11 * Revision Information:
12 *
13 * Date Who Reason
14 *
15 * Oct 10, 2008 ukurmann Initial Release
16 *
17 * -----------------------------------------------------------------------
18 *
19 * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20 *
21 * This software is the proprietary information of ETH Zurich.
22 * Use is subject to license terms.
23 *
24 */
25
26
27 package org.ximtec.igesture.util;
28
29 import java.math.BigDecimal;
30 import java.util.ArrayList;
31
32 import org.sigtec.util.Constant;
33
34
35 /**
36 * Implements a vector of BigDecimal values and provides some basic functionality.
37 *
38 * @version 1.0, Oct 2008
39 * @author Ueli Kurmann, ueli.kurmann@bbv.ch
40 * @author Beat Signer, signer@inf.ethz.ch
41 */
42 public class BigDecimalVector extends ArrayList<BigDecimal> {
43
44 /**
45 * Constructs a new double vector.
46 *
47 * @param size the initial size of the double vector.
48 */
49 public BigDecimalVector(int size) {
50 super(size);
51
52 for (int i = 0; i < size; i++) {
53 add(i, new BigDecimal(0));
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 BigDecimal[] toBigDecimalArray() {
65 final BigDecimal[] result = new BigDecimal[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 BigDecimal 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 }