source: java/main/src/main/java/com/framsticks/params/ArrayListAccess.java @ 101

Last change on this file since 101 was 101, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • improve tree side notes
  • improve GUI layout
  • add foldable list of occured events to EventControl?
  • improve automatic type conversion in proxy listeners
  • implement several Access functionalities as algorithms independent of Access type
  • introduce draft base classes for distributed experiments
  • automatically register dependant Java classes to FramsClass? registry
  • add testing prime experiment and configuration
  • simplify and improve task dispatching

CHANGELOG:
Improve task dispatching in RemoteTree?.

GUI no longer hangs on connection problems.

Make all dispatchers joinables.

Refactorize Thread dispatcher.

Remove Task and PeriodicTask?.

Use Java utilities in those situations.

Reworking tasks dispatching.

Fix bug in EventControl? listener dispatching.

Minor improvements.

Add testing configuration for ExternalProcess? in GUI.

More improvement to prime.

Support for USERREADONLY in GUI.

Add that flag to various params in Java classes.

Remove redundant register clauses from several FramsClassAnnotations?.

Automatically gather and register dependant classes.

Add configuration for prime.

Improve Simulator class.

Add prime.xml configuration.

Introduce draft Experiment and Simulator classes.

Add prime experiment tests.

Enclose typical map with listeners into SimpleUniqueList?.

Needfile works in GUI.

Improve needfile handling in Browser.

More improvement with NeedFile?.

Implementing needfile.

Update test.

Rename ChangeEvent? to TestChangeEvent?.

Automatic argument type search in RemoteTree? listeners.

MultiParamLoader? uses AccessProvider?. By default old implementation
enclosed in AccessStash? or Registry.

Minor changes.

Rename SourceInterface? to Source.

Also improve toString of File and ListSource?.

Remove unused SimpleSource? class.

Add clearing in HistoryControl?.

Show entries in table at EventControl?.

Improve EventControl?.

Add listeners registration to EventControl?.

Add foldable table to HistoryControl?.

Add control row to Procedure and Event controls.

Improve layout of controls.

Another minor change to gui layout.

Minor improvement in the SliderControl?.

Minor changes.

Move ReflectionAccess?.Backend to separate file.

It was to cluttered.

Cleanup in ReflectionAccess?.

Move setMin, setMax, setDef to AccessOperations?.

Extract loading operation into AccessOperations?.

Append Framsticks to name of UnsupportedOperationException?.

The java.lang.UnsupportedOperationException? was shadowing this class.

Rename params.Util to params.ParamsUtil?.

Several improvements.

Minor changes.

Implement revert functionality.

Improve local changes management.

Minor improvement.

Remove methods rendered superfluous after SideNoteKey? improvement.

Improve SideNoteKey?.

It is now generic type, so explicit type specification at
call site is no more needed.

Introduce SideNoteKey? interface.

Only Objects implementing that key may be used as side note keys.

Minor improvements.

Use strings instead of ValueControls? in several gui mappings.

File size: 3.5 KB
Line 
1package com.framsticks.params;
2
3import com.framsticks.params.types.ArrayListParam;
4import com.framsticks.util.UnimplementedException;
5import com.framsticks.util.lang.Numbers;
6
7import java.util.ArrayList;
8import java.util.Iterator;
9import java.util.List;
10import java.util.ListIterator;
11import static com.framsticks.params.SetStateFlags.*;
12
13/**
14 * @author Piotr Sniegowski
15 */
16public class ArrayListAccess extends ListAccess {
17
18        List<Object> list;
19
20
21        public ArrayListAccess(Access elementAccess) {
22                super(elementAccess);
23        }
24
25        @Override
26        public ArrayListAccess cloneAccess() {
27                return new ArrayListAccess(elementAccess.cloneAccess());
28        }
29
30        @Override
31        public List<?> createAccessee() {
32                return new ArrayList<Object>();
33        }
34
35        @Override
36        public CompositeParam getParam(int i) {
37                if ((i < 0) ||  (i >= list.size())) {
38                        return null;
39                }
40                return paramBuilder.id(Integer.toString(i)).finish(CompositeParam.class);
41        }
42
43        @Override
44        public CompositeParam getParam(String id) {
45                Integer i = Numbers.parse(id, Integer.class);
46                return (i == null ? null : getParam(i));
47        }
48
49        @Override
50        public String getId() {
51                return "l " + elementAccess.getId();
52        }
53
54        @Override
55        public int getParamCount() {
56                return list.size();
57        }
58
59        @Override
60        public <T> T get(int i, Class<T> type) {
61                if ((i < 0) ||  (i >= list.size())) {
62                        return null;
63                }
64                return type.cast(list.get(i));
65        }
66
67        @Override
68        public <T> T get(String id, Class<T> type) {
69                return get(Integer.parseInt(id), type);
70        }
71
72        @Override
73        public <T> T get(ValueParam param, Class<T> type) {
74                return get(param.getId(), type);
75        }
76
77        @Override
78        public <T> int set(int i, T value) {
79                if (value != null) {
80                        while (i >= list.size()) {
81                                list.add(null);
82                        }
83                        list.set(i, value);
84                        return 0;
85                }
86                if (i >= list.size()) {
87                        return PSET_HITMAX;
88                }
89                list.remove(i);
90                // for (int j = i + 1; j < list.size(); ++j) {
91                //      if (list.get(j) != null) {
92                //              list.set(i, null);
93                //              return 0;
94                //      }
95                // }
96                // while (list.size() > i) {
97                //      list.remove(i);
98                // }
99                return 0;
100        }
101
102        @Override
103        public <T> int set(String id, T value) {
104                return set(Integer.parseInt(id), value);
105        }
106
107        @Override
108        public <T> int set(ValueParam param, T value) {
109                return set(param.getId(), value);
110        }
111
112        @Override
113        public void clearValues() {
114                list.clear();
115        }
116
117        /** covariant */
118        @Override
119        public List<Object> getSelected() {
120                return list;
121        }
122
123        @SuppressWarnings("unchecked")
124        @Override
125        public ArrayListAccess select(Object object) {
126                list = ParamsUtil.selectObjectForAccess(this, object, List.class);
127                return this;
128        }
129
130
131        @Override
132        public Iterable<Param> getParams() {
133                return new Iterable<Param>() {
134
135                        @Override
136                        public Iterator<Param> iterator() {
137                                return new Iterator<Param>() {
138
139                                        protected ListIterator<Object> internal = list.listIterator();
140
141                                        @Override
142                                        public boolean hasNext() {
143                                                return internal.hasNext();
144                                        }
145
146                                        @Override
147                                        public Param next() {
148                                                Param param = paramBuilder.id(Integer.toString(internal.nextIndex())).finish(CompositeParam.class);
149                                                internal.next();
150                                                return param;
151                                        }
152
153                                        @Override
154                                        public void remove() {
155                                                throw new UnimplementedException().msg("remove element from list").arg("list", ArrayListAccess.this);
156
157                                        }
158                                };
159                        }
160                };
161        }
162
163        @Override
164        public int getCompositeParamCount() {
165                return list.size();
166        }
167
168        @Override
169        public CompositeParam getCompositeParam(int number) {
170                return getParam(number);
171        }
172
173        @Override
174        public ParamBuilder buildParam(ParamBuilder builder) {
175                return builder.name(containedTypeName + " list").type(ArrayListParam.class).containedTypeName(containedTypeName);
176        }
177
178}
Note: See TracBrowser for help on using the repository browser.