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

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

HIGHLIGHTS:

  • import refactorization: move Tree, Path, etc.

from core to structure package

  • initial serialization implementation
  • improve PrimeExperiment? test
  • many organizational changes and convenience improvements

CHANGELOG:
Make registry in AbstractTree? final.

Move most classes from core to structure package.

Minor changes.

Switch names of Future and FutureHandler?.

Rename ExceptionResultHandler? to ExceptionHandler?.

Rename ExceptionHandler? to ExceptionDispatcherHandler?.

Fix bug in ParamCandidate? cache.

Add missing synchronization to the BufferedDispatcher?.

Develop @Serialized support.

Rework serialization further.

Add serialization/deserialization interface to ValueParam?.

Move getStorageType and isNumeric from Param down to params hierarchy.

Minor changes.

Improve param type induction.

Add TestSerializedClass? for testing new serialization.

Add info files gor GenePool? and Population.

Add standard.expt exemplary netfile.

Add type name field to PropertiesObject?.

Use PropertiesObject? for PropertiesAccess? instead of ordinary map.

Hide getFramsClass is several more places.

More unification accross FramsClass?, Access and Path.

Add ParamCollection?.

Simplify interface for getting params from FramsClass?, Access
or Path.

Make Access.call() interface variadic.

Add arguments(args) convenience wrapper around new Object[] {args}.

Upgrade to apache.commons.lang version 3.1

Minor improvement with Response constructors.

Develop proper result printing in ClientAtServer?.

Add experimentNetsave to PrimeExperiment?.

File size: 3.5 KB
RevLine 
[77]1package com.framsticks.params;
2
[99]3import com.framsticks.params.types.ArrayListParam;
[98]4import com.framsticks.util.UnimplementedException;
[84]5import com.framsticks.util.lang.Numbers;
[77]6
7import java.util.ArrayList;
[98]8import java.util.Iterator;
[77]9import java.util.List;
[98]10import java.util.ListIterator;
[100]11import static com.framsticks.params.SetStateFlags.*;
[77]12
13/**
14 * @author Piotr Sniegowski
15 */
16public class ArrayListAccess extends ListAccess {
17
[84]18        List<Object> list;
[77]19
[99]20
[100]21        public ArrayListAccess(Access elementAccess) {
[84]22                super(elementAccess);
23        }
[77]24
[84]25        @Override
[101]26        public ArrayListAccess cloneAccess() {
[84]27                return new ArrayListAccess(elementAccess.cloneAccess());
28        }
[77]29
[84]30        @Override
31        public List<?> createAccessee() {
32                return new ArrayList<Object>();
33        }
[77]34
[84]35        @Override
[98]36        public CompositeParam getParam(int i) {
37                if ((i < 0) ||  (i >= list.size())) {
38                        return null;
39                }
[99]40                return paramBuilder.id(Integer.toString(i)).finish(CompositeParam.class);
[84]41        }
[77]42
[84]43        @Override
[98]44        public CompositeParam getParam(String id) {
[84]45                Integer i = Numbers.parse(id, Integer.class);
46                return (i == null ? null : getParam(i));
47        }
[77]48
[84]49        @Override
[105]50        public String getTypeId() {
51                return "l " + elementAccess.getTypeId();
[84]52        }
[77]53
[84]54        @Override
55        public int getParamCount() {
56                return list.size();
57        }
[77]58
[84]59        @Override
60        public <T> T get(int i, Class<T> type) {
[98]61                if ((i < 0) ||  (i >= list.size())) {
62                        return null;
[84]63                }
[98]64                return type.cast(list.get(i));
[84]65        }
[77]66
[84]67        @Override
68        public <T> T get(String id, Class<T> type) {
69                return get(Integer.parseInt(id), type);
70        }
[77]71
[84]72        @Override
73        public <T> T get(ValueParam param, Class<T> type) {
74                return get(param.getId(), type);
75        }
[77]76
[84]77        @Override
78        public <T> int set(int i, T value) {
[100]79                if (value != null) {
80                        while (i >= list.size()) {
81                                list.add(null);
82                        }
83                        list.set(i, value);
84                        return 0;
[84]85                }
[100]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                // }
[84]99                return 0;
100        }
[77]101
[84]102        @Override
103        public <T> int set(String id, T value) {
104                return set(Integer.parseInt(id), value);
105        }
[77]106
[84]107        @Override
108        public <T> int set(ValueParam param, T value) {
109                return set(param.getId(), value);
110        }
[77]111
[84]112        @Override
113        public void clearValues() {
114                list.clear();
115        }
[77]116
[84]117        /** covariant */
118        @Override
119        public List<Object> getSelected() {
120                return list;
121        }
[77]122
[84]123        @SuppressWarnings("unchecked")
124        @Override
125        public ArrayListAccess select(Object object) {
[101]126                list = ParamsUtil.selectObjectForAccess(this, object, List.class);
[84]127                return this;
128        }
[77]129
130
[84]131        @Override
[98]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() {
[99]148                                                Param param = paramBuilder.id(Integer.toString(internal.nextIndex())).finish(CompositeParam.class);
[98]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                };
[84]161        }
[77]162
[98]163        @Override
164        public int getCompositeParamCount() {
165                return list.size();
166        }
[77]167
[98]168        @Override
169        public CompositeParam getCompositeParam(int number) {
170                return getParam(number);
171        }
172
[99]173        @Override
174        public ParamBuilder buildParam(ParamBuilder builder) {
175                return builder.name(containedTypeName + " list").type(ArrayListParam.class).containedTypeName(containedTypeName);
176        }
[98]177
[77]178}
Note: See TracBrowser for help on using the repository browser.