source: java/main/src/main/java/com/framsticks/params/SimpleAbstractAccess.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
3
4import static com.framsticks.util.lang.Containers.filterInstanceof;
5
6
7import com.framsticks.params.types.ObjectParam;
8import com.framsticks.util.FramsticksException;
9
10/**
11 * The Class SimpleAbstractAccess implements all the methods of Access
12 * which actions can be implemented with usage of {@link Access} methods
13 * or concern schema, which is stored in {@link #framsClass}
14 *
15 * Based on c++ class SimpleAbstractParam located in: cpp/gdk/param.*
16 *
17 * @author Jarek Szymczak <name.surname@gmail.com>, Mateusz Jarus (please
18 *         replace name and surname with my personal data)
19 *
20 * @author Piotr Sniegowski
21 */
22public abstract class SimpleAbstractAccess implements ObjectAccess {
23
24        protected final FramsClass framsClass;
25
26        /**
27         * @param framsClass
28         */
29        public SimpleAbstractAccess(FramsClass framsClass) {
30                this.framsClass = framsClass;
31        }
32
33        @Override
34        public final FramsClass getFramsClass() {
35                return framsClass;
36        }
37
38        @Override
39        public String getId() {
40                return framsClass.getId();
41        }
42
43        @Override
44        public int getParamCount() {
45                return framsClass.getParamCount();
46        }
47
48        @Override
49        public Param getParam(int i) {
50                return framsClass.getParam(i);
51        }
52
53        @Override
54        public Param getParam(String id) {
55                return framsClass.getParam(id);
56        }
57
58        // @Override
59        // public Param getGroupMember(int gi, int n) {
60        //      return framsClass.getGroupMember(gi, n);
61        // }
62
63        @Override
64        public <T> T get(int i, Class<T> type) {
65                return get(framsClass.getParamEntry(i, ValueParam.class), type);
66        }
67
68        @Override
69        public <T> T get(String id, Class<T> type) {
70                return get(framsClass.getParamEntry(id, ValueParam.class), type);
71        }
72
73        @Override
74        public <T> int set(int i, T value) {
75                return set(framsClass.getParamEntry(i, ValueParam.class), value);
76        }
77
78        @Override
79        public <T> int set(String id, T value) {
80                return set(framsClass.getParamEntry(id, ValueParam.class), value);
81        }
82
83        @Override
84        public <T> int set(ValueParam param, T value) {
85
86                //String id = param.getEffectiveId();
87                try {
88                        Object oldValue = get(param, param.getStorageType());
89                        ReassignResult<?> result = param.reassign(value, oldValue);
90                        Object casted = result.getValue();
91                        if (casted != null && !casted.equals(oldValue)) {
92                                internalSet(param, casted);
93                        }
94                        return result.getFlags();
95                } catch (CastFailure e) {
96                        throw new FramsticksException()
97                                .msg("casting failure while set")
98                                .arg("param", param)
99                                .arg("value", value)
100                                .arg("value's type", (value == null ? "<null>" : value.getClass().getCanonicalName()))
101                                .arg("in", this).cause(e);
102                }
103        }
104
105        @Override
106        public void save(SinkInterface sink) {
107                assert framsClass != null;
108                sink.print(framsClass.getId()).print(":").breakLine();
109                for (PrimitiveParam<?> p : filterInstanceof(framsClass.getParamEntries(), PrimitiveParam.class)) {
110                        Object value = get(p, Object.class);
111                        if ((value == null) || value.equals(p.getDef(Object.class))) {
112                                continue;
113                        }
114                        sink.print(p.getId()).print(":");
115                        p.save(sink, value);
116                        sink.breakLine();
117                }
118                sink.breakLine();
119        }
120
121        protected abstract <T> void internalSet(ValueParam param, T value);
122
123        @Override
124        public Iterable<Param> getParams() {
125                return framsClass.getParamEntries();
126        }
127
128        @Override
129        public int getCompositeParamCount() {
130                return framsClass.getCompositeParamCount();
131        }
132
133        @Override
134        public CompositeParam getCompositeParam(int number) {
135                return framsClass.getCompositeParam(number);
136        }
137
138        @Override
139        public ParamBuilder buildParam(ParamBuilder builder) {
140                return builder.name(getId()).type(ObjectParam.class).containedTypeName(getId());
141        }
142
143}
Note: See TracBrowser for help on using the repository browser.