source: java/main/src/main/java/com/framsticks/params/UniqueListAccess.java @ 90

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

HIGHLIGHTS:

CHANGELOG:
Make ProcedureParam? hold only ValueParams?.

Use id instead of names when naming gui components internally.

Basic procedure calling in GUI.

The actual procedure call is currently only backed
by the ObjectInstance?.

Add UnimplementedException?.

Improve naming of various gui elements.

Allow easy navigating in FEST Swing testing.

Add optional explicit order attribute to FramsClassAnnotation?.

That's because java reflection does return declared members
in any specific order. That ordering is needed only for
classes that have no representation in framsticks and need
a deterministic ordering of params.

Add ControlOwner? interface.

Add test for procedure calling in Browser.

First version of ParamAnnotation? for procedures.

Development of ProcedureParam?.

Add draft version of ProcedureParam? implementation in ReflectionAccess?.

Allow viewing FramsClasses? in gui Browser.

Extract ResourceBuilder? from ModelBuilder?.

Remove internalId from Param.

It was currently completely not utilised. Whether it is still needed
after introduction of ParamAnnotation? is arguable.

Add remaining param attributes to ParamAnnotation?.

Change AutoBuilder? semantics.

AutoBuilder? returns list of objects that are to be appended
with methods @AutoAppendAnnotation?.

This allows to omit explicit addition of ModelPackage? to instance
if the instance uses ModelBuilder? (registration of ModelPackage? comes
from schema).

Fix params ordering problem in auto created FramsClasses?.

Improve ObjectInstance?.

Several fixes to ModelBuilder?.

Improve test for ObjectInstance? in Browser.

Make initialization of robot static.

With robot recreated for second browser test, the test hanged
deep in AWT.

Add base convenience base test for Browser tests.

More tests to ObjectInstance?.

Rename Dispatcher.invokeLater() to dispatch().

Add assertDispatch.

It allows assertions in other threads, than TestNGInvoker.
Assertions are gathered after each method invocation and rethrown.

Use timeOut annotation attribute for tests involving some waiting.

Remove firstTask method (merge with joinableStart).

Clean up leftovers.

Remove unused FavouritesXMLFactory (the reading part is already
completely done with generic XmlLoader?, and writing part will be done
based on the same approach if needed).
Move UserFavourite? to the com.framsticks.gui.configuration package.

Remove GenotypeBrowser? as to specific.

This functionality will be available in ObjectInstance?.

Add interface ParamsPackage?.

Package containing registration of Java classes meant to use with
ReflectionAccess? may be in Instance using configuration.

Minor changes.

Make Group immutable.

Add AutoBuilder? interface extending Builder - only those would
be used to automatically build from XML.

Fix groups in FramsClass?.

Minor naming cleanup in Registry.

Add ModelComponent? interface.

All class creating the Model are implementing that interface.

Extract Model.build into ModelBuilder?.

ModelBuilder? will be compatible with other builders
and allow using it from configuration.

Fix NeuroConnection?.

Add synchronous get operation for dispatchers.

Rename JoinableMonitor? to Monitor.

Add ObjectInstance?.

This class is mainly for demonstration
and testing purposes.

Improve FramsServer? runner.

  • improve ExternalProcess? runner,
  • runner can kill the server but also react properly, when the server exists on it's own,
  • set default path to search for framsticks server installation,
  • add LoggingOutputListener?.
File size: 4.1 KB
Line 
1package com.framsticks.params;
2
3import com.framsticks.util.lang.Casting;
4import com.framsticks.util.lang.Numbers;
5import org.apache.log4j.Logger;
6
7import java.util.*;
8
9/**
10 * @author Piotr Sniegowski
11 */
12public class UniqueListAccess extends ListAccess {
13
14        private static final Logger log = Logger.getLogger(UniqueListAccess.class.getName());
15
16        Map<String, Object> map;
17
18        final String uidName;
19
20        public UniqueListAccess(AccessInterface elementAccess, String uidName) {
21                super(elementAccess);
22                this.uidName = uidName;
23        }
24
25        @Override
26        public Map<String, Object> createAccessee() {
27                return new HashMap<String, Object>();
28        }
29
30        @Override
31        public Param getParam(int i) {
32                log.error("accesing unique list through index");
33                assert false;
34                return null;
35                //log.error("accesing unique list through index");
36                //return null;
37                //return Param.build().setId(Integer.toString(i)).setName(elementAccess.getId()).type("o " + elementAccess.getId()).build();
38        }
39
40        @Override
41        public Param getParam(String id) {
42                Integer i = Numbers.parse(id, Integer.class);
43                if (i != null) {
44                        return getParam(i);
45                }
46                //TODO list access here
47                return Param.build().id(id).forAccess(elementAccess).finish();
48        }
49
50        @Override
51        public String getId() {
52                return "l " + elementAccess.getId() + " " + uidName;
53        }
54
55        @Override
56        public int getParamCount() {
57                return map.size();
58        }
59
60        @Override
61        public <T> T get(int i, Class<T> type) {
62                log.error("accesing unique list through index");
63                assert false;
64                return null;
65                //Object[] values = map.values().toArray();
66                //return Casting.tryCast(i < values.length ? values[i] : null, type);
67        }
68
69        @Override
70        public <T> T get(String id, Class<T> type) {
71                Integer i = Numbers.parse(id, Integer.class);
72                if (i != null) {
73                        return get(i, type);
74                }
75                return Casting.tryCast(type, map.containsKey(id) ? map.get(id) : null);
76        }
77
78        @Override
79        public <T> T get(ValueParam param, Class<T> type) {
80                return get(param.getId(), type);
81        }
82
83        public String getUidOf(Object value) {
84                Object tmp = elementAccess.getSelected();
85                elementAccess.select(value);
86                String uid = elementAccess.get(uidName, String.class);
87                elementAccess.select(tmp);
88                if (uid == null) {
89                        return null;
90                }
91                return uid;
92        }
93
94        protected int setByUid(Object object, String uid) {
95                if (uid == null) {
96                        uid = getUidOf(object);
97                        if (uid == null) {
98                                log.error("failed to set - missing uid");
99                                return 0;
100                        }
101                }
102                if (object == null) {
103                        map.remove(uid);
104                } else {
105                        map.put(uid, object);
106                }
107                return 0;
108        }
109
110        @Override
111        public <T> int set(int i, T value) {
112                log.error("accesing unique list through index");
113                //return setByUid(value, null);
114                return 0;
115        }
116
117        @Override
118        public <T> int set(String id, T value) {
119                Integer i = Numbers.parse(id, Integer.class);
120                if (i != null) {
121                        return set(i, value);
122                }
123                if (value == null) {
124                        return setByUid(null, id);
125                }
126                String uid = getUidOf(value);
127                if (uid != null && id != null) {
128                        if (!id.equals(uid)) {
129                                log.error("uid mismatch with set key");
130                                return 0;
131                        }
132                        setByUid(value, uid);
133                        return 0;
134                }
135                if (uid != null) {
136                        setByUid(value, uid);
137                        return 0;
138                }
139                if (id != null) {
140                        setByUid(value, id);
141                        return 0;
142                }
143                log.error("missing both uid and id - failed to set");
144                return 0;
145        }
146
147        @Override
148        public <T> int set(ValueParam param, T value) {
149                return set(param.getId(), value);
150        }
151
152        @Override
153        public void clearValues() {
154                map.clear();
155        }
156
157        @SuppressWarnings("unchecked")
158        @Override
159        public UniqueListAccess select(Object object) {
160                assert (object instanceof Map);
161                map = (Map<String, Object>) object;
162                return this;
163        }
164
165        @Override
166        public Object getSelected() {
167                return map;
168        }
169
170        @Override
171        public UniqueListAccess cloneAccess() {
172                return new UniqueListAccess(elementAccess.cloneAccess(), uidName);
173        }
174
175        @Override
176        public String computeIdentifierFor(Object selected) {
177                String uid = getUidOf(selected);
178                if (uid == null) {
179                        log.error("missing uid field");
180                        return null;
181                }
182                return uid;
183        }
184
185        @Override
186        public Collection<Param> getParams() {
187                List<Param> result = new LinkedList<Param>();
188                if (map == null) {
189                        return result;
190                }
191                for (String k : map.keySet()) {
192                        result.add(getParam(k));
193                }
194                return result;
195        }
196}
Note: See TracBrowser for help on using the repository browser.