1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.om.page.impl;
18
19 import java.util.AbstractList;
20
21 /***
22 * FragmentPreferenceValueList
23 *
24 * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
25 * @version $Id$
26 */
27 class FragmentPreferenceValueList extends AbstractList
28 {
29 private FragmentPreferenceImpl preference;
30
31 FragmentPreferenceValueList(FragmentPreferenceImpl preference)
32 {
33 super();
34 this.preference = preference;
35 }
36
37 /***
38 * wrapValueStringForAdd
39 *
40 * Wraps and validates preference value string
41 * to be added to this list.
42 *
43 * @param value preference value string to add
44 * @return list element to add
45 */
46 private FragmentPreferenceValue wrapValueStringForAdd(String value)
47 {
48
49 if (value == null)
50 {
51 throw new NullPointerException("Unable to add null to list.");
52 }
53
54 FragmentPreferenceValue preferenceValue = new FragmentPreferenceValue();
55 preferenceValue.setValue(value);
56 return preferenceValue;
57 }
58
59
60
61
62 public void add(int index, Object element)
63 {
64
65
66 if ((index < 0) || (index > preference.accessValues().size()))
67 {
68 throw new IndexOutOfBoundsException("Unable to add to list at index: " + index);
69 }
70
71 FragmentPreferenceValue preferenceValue = wrapValueStringForAdd((String)element);
72
73 preference.accessValues().add(index, preferenceValue);
74
75 if (index > 0)
76 {
77 preferenceValue.setValueOrder(((FragmentPreferenceValue)preference.accessValues().get(index-1)).getValueOrder() + 1);
78 }
79 else
80 {
81 preferenceValue.setValueOrder(0);
82 }
83
84 for (int i = index, limit = preference.accessValues().size() - 1; (i < limit); i++)
85 {
86 FragmentPreferenceValue nextPreferenceValue = (FragmentPreferenceValue)preference.accessValues().get(i + 1);
87 if (nextPreferenceValue.getValueOrder() <= preferenceValue.getValueOrder())
88 {
89
90 nextPreferenceValue.setValueOrder(preferenceValue.getValueOrder() + 1);
91 preferenceValue = nextPreferenceValue;
92 }
93 else
94 {
95
96 break;
97 }
98 }
99 }
100
101
102
103
104 public Object get(int index)
105 {
106
107
108 return ((FragmentPreferenceValue)preference.accessValues().get(index)).getValue();
109 }
110
111
112
113
114 public Object remove(int index)
115 {
116
117 return preference.accessValues().remove(index);
118 }
119
120
121
122
123 public Object set(int index, Object element)
124 {
125
126
127 FragmentPreferenceValue newPreferenceValue = wrapValueStringForAdd((String)element);
128
129 FragmentPreferenceValue preferenceValue = (FragmentPreferenceValue)preference.accessValues().set(index, newPreferenceValue);
130
131 newPreferenceValue.setValueOrder(preferenceValue.getValueOrder());
132
133 return preferenceValue.getValue();
134 }
135
136
137
138
139 public int size()
140 {
141
142 return preference.accessValues().size();
143 }
144 }