source: java/main/src/main/java/com/framsticks/params/FramsClass.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.7 KB
Line 
1package com.framsticks.params;
2
3import com.framsticks.params.annotations.FramsClassAnnotation;
4import com.framsticks.params.annotations.ParamAnnotation;
5import com.framsticks.util.FramsticksException;
6import com.framsticks.util.lang.Containers;
7// import com.framsticks.util.FramsticksException;
8
9import java.util.*;
10
11import javax.annotation.Nonnull;
12import javax.annotation.concurrent.Immutable;
13
14import org.apache.log4j.Logger;
15
16/**
17 * The class FramsClass represents the class / schema of connected parameters
18 * (such as parameters within the class). It differs from C++ version by storing
19 * information about the class that parameters belong to.
20 *
21 * Based loosely on c++ class Param located in cpp/gdk/param.*
22 *
23 * @author Jarek Szymczak <name.surname@gmail.com>, Mateusz Jarus (please
24 *         replace name and surname with my personal data)
25 *
26 * @author Piotr Sniegowski
27 */
28@Immutable
29@FramsClassAnnotation(id = "class", name = "class")
30public class FramsClass {
31
32        private final static Logger log = Logger.getLogger(FramsClass.class);
33
34        protected final String id;
35
36        protected final String name;
37
38        protected final String description;
39
40        protected final List<Group> groups;
41
42        /** The param list (for accessing parameters by offset in O(1) time. */
43        protected final List<Param> paramList;
44
45        /**
46         * The param entry map <parameterId, param> (for fast accessing of parameters
47         * by their name)
48         */
49        protected Map<String, Param> paramEntryMap = new LinkedHashMap<String, Param>();
50
51        // /** The param getId map (for fast lookup of offset based on name */
52        // protected Map<String, Integer> paramIdMap = new HashMap<String, Integer>();
53
54        @ParamAnnotation(id = "props", name = "props")
55        public List<Param> getParamEntries() {
56                return Collections.unmodifiableList(paramList);
57        }
58
59        public FramsClass(FramsClassBuilder builder) {
60
61                this.id = builder.getId();
62                this.name = builder.getName();
63                this.description = builder.getDescription();
64                this.groups = Containers.build(builder.groupBuilders);
65                this.paramList = builder.params;
66
67                for (Param param : paramList) {
68                        paramEntryMap.put(param.getId(), param);
69                }
70
71                log.trace("created framsclass " + this);
72
73        }
74
75        @ParamAnnotation(id = "desc")
76        public String getDescription() {
77                return description;
78        }
79
80        public int getGroupCount() {
81                return groups.size();
82        }
83
84        public Group getGroup(int groupNumber) {
85                return Containers.getFromList(groups, groupNumber, "group", this);
86        }
87
88        // /**
89        //  * Gets the group member.
90        //  *
91        //  * @param gi
92        //  *            the offset of group
93        //  * @param pi
94        //  *            the offset of member within a group
95        //  * @return the pi-th member of group gi
96        //  */
97        // public Param getGroupMember(int gi, int pi) {
98        //      if (gi < 0 || pi < 0 || gi >= groups.size()) {
99        //              return null;
100        //      }
101        //      Group group = groups.get(gi);
102        //      return (group != null ? group.getProperty(pi) : null);
103        // }
104
105        // /**
106        //  * Gets the group name.
107        //  *
108        //  * @param gi
109        //  *            the offset of group
110        //  * @return the group name
111        //  */
112        // public String getGroupName(int gi) {
113        //      if (gi < 0 || gi >= groups.size())
114        //              return null;
115        //      return groups.get(gi).name;
116        // }
117
118        @ParamAnnotation
119        public String getId() {
120                return id;
121        }
122
123        @ParamAnnotation
124        public String getName() {
125                return name;
126        }
127
128        public String getNiceName() {
129                return name != null ? name : id;
130        }
131
132        public <T extends Param> T castedParam(@Nonnull final Param param, @Nonnull final Class<T> type, Object name) {
133                if (param == null) {
134                        // return null;
135                        throw new FramsticksException().msg("param is missing").arg("name", name).arg("in", this);
136                }
137                if (!type.isInstance(param)) {
138                        // return null;
139                        throw new FramsticksException().msg("wrong type of param").arg("actual", param.getClass()).arg("requested", type).arg("in", this);
140                }
141                return type.cast(param);
142        }
143
144        /**
145         * Gets the param entry.
146         *
147         * @param i
148         *            the offset of parameter
149         * @return the param entry
150         */
151        public <T extends Param> T getParamEntry(final int i, @Nonnull final Class<T> type) {
152                return castedParam(getParam(i), type, i);
153        }
154
155        /**
156         * Gets the param entry.
157         *
158         * @param id
159         *            the getId of parameter
160         * @return the param entry
161         */
162        public <T extends Param> T getParamEntry(@Nonnull final String id, @Nonnull final Class<T> type) {
163                return castedParam(getParam(id), type, id);
164        }
165
166        public Param getParam(int i) {
167                if (i < 0 || i >= paramList.size()) {
168                        return null;
169                }
170                return paramList.get(i);
171        }
172
173        public Param getParam(String id) {
174                if (!paramEntryMap.containsKey(id)) {
175                        return null;
176                }
177                return paramEntryMap.get(id);
178        }
179
180        public int getParamCount() {
181                return paramList.size();
182        }
183
184        @Override
185        public String toString() {
186                return id + "(" + name + ")";
187        }
188
189        public static FramsClassBuilder build() {
190                return new FramsClassBuilder();
191        }
192}
Note: See TracBrowser for help on using the repository browser.