Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerArrayData.java @ 2535:d0a9acddbea2
Added an int data item used in int array data and added getter that returns
values as colon separated string to all data types.
flys-client/trunk@4445 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 21 May 2012 08:48:16 +0000 |
parents | e53d773e6992 |
children |
comparison
equal
deleted
inserted
replaced
2534:05143379059e | 2535:d0a9acddbea2 |
---|---|
7 | 7 |
8 | 8 |
9 protected String label; | 9 protected String label; |
10 protected String description; | 10 protected String description; |
11 | 11 |
12 protected int[] values; | 12 protected IntDataItem[] values; |
13 | 13 |
14 | 14 |
15 public IntegerArrayData() { | 15 public IntegerArrayData() { |
16 } | 16 } |
17 | 17 |
18 | 18 |
19 public IntegerArrayData(String label, String description, int[] values) { | 19 public IntegerArrayData( |
20 String label, | |
21 String description, | |
22 IntDataItem[] values | |
23 ) { | |
20 this.label = label; | 24 this.label = label; |
21 this.description = description; | 25 this.description = description; |
22 this.values = values; | 26 this.values = values; |
23 } | 27 } |
24 | 28 |
58 * values separated by a ';'. | 62 * values separated by a ';'. |
59 * | 63 * |
60 * @return the DataItem. | 64 * @return the DataItem. |
61 */ | 65 */ |
62 public DataItem[] getItems() { | 66 public DataItem[] getItems() { |
63 if (values == null || values.length == 0) { | 67 return values; |
64 return new DataItem[0]; | |
65 } | |
66 | |
67 StringBuilder sb = new StringBuilder(); | |
68 boolean first = true; | |
69 | |
70 for (int value: values) { | |
71 if (first) { | |
72 sb.append(String.valueOf(value)); | |
73 } | |
74 else { | |
75 sb.append(";" + String.valueOf(value)); | |
76 } | |
77 } | |
78 | |
79 String value = sb.toString(); | |
80 DataItem item = new DefaultDataItem(value, value, value); | |
81 | |
82 return new DataItem[] { item }; | |
83 } | 68 } |
84 | 69 |
85 | 70 |
86 /** | 71 /** |
87 * Returns the values as array. | 72 * Returns the values as array. |
88 * | 73 * |
89 * @return the values as array. | 74 * @return the values as array. |
90 */ | 75 */ |
91 public int[] getValues() { | 76 public int[] getValues() { |
92 return values; | 77 int[] data = new int[values.length]; |
78 for (int i = 0; i < values.length; i++) { | |
79 data[i] = values[i].getValue(); | |
80 } | |
81 return data; | |
93 } | 82 } |
94 | 83 |
84 | |
85 /** | |
86 * Returns the values as colon separated string. | |
87 * | |
88 * @return colon separated string. | |
89 */ | |
90 public String getStringValue() { | |
91 String data = ""; | |
92 boolean first = true; | |
93 for (int i = 0; i < values.length; i++) { | |
94 if (!first) { | |
95 data += ";"; | |
96 } | |
97 data += values[i].getStringValue(); | |
98 first = false; | |
99 } | |
100 return data; | |
101 } | |
95 | 102 |
96 /** | 103 /** |
97 * @return always null. | 104 * @return always null. |
98 */ | 105 */ |
99 public DataItem getDefault() { | 106 public DataItem getDefault() { |