source: java/main/src/main/java/com/framsticks/params/FramsClass.java @ 100

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

HIGHLIGHTS:

  • add <include/> to configuration
  • add side notes to tree
    • used to store arbitrary information alongside the tree structure
  • migrate to log4j2
    • supports lazy string evaluation of passed arguments
  • improve GUI tree
    • it stays in synchronization with actual state (even in high load test scenario)
  • improve panel management in GUI
  • make loading objects in GUI more lazy
  • offload parsing to connection receiver thread
    • info parsing
    • first step of objects parsing
  • fix connection parsing bug (eof in long values)
  • support zero-arguments procedure in table view

CHANGELOG:
Implement procedure calls from table view.

Refactorization around procedures in tables.

Add table editor for buttons.

Render buttons in the the list view.

Further improve Columns.

Add Column class for TableModel?.

Accept also non-arguments ProcedureParams? in tableView.

Increase maximal TextAreaControl? size.

Add tooltip to ProcedureControl?.

Fix bug of interpreting eofs in long values by connection reader.

Further rework connection parsing.

Simplify client connection processing.

Test ListChange? modification.

Test ListChange? events with java server.

Add TestChild?.

Fix bug with fast deregistering when connecting to running server.

Another minor refactorization in TreeOperations?.

Fix bug in SimpleAbstractAccess? loading routine.

Another minor improvement.

Minor change.

Make reading of List objects two-phase.

Another minor change.

Dispatch parsing into receiver thread.

Another step.

Enclose passing value in ObjectParam? case in closure.

Minor step.

Minor change on way to offload parsing.

Temporarily comment out single ValueParam? get.

It will be generalized to multi ValueParam?.

Process info in receiver thread.

Add DispatchingExceptionHandler?.

Make waits in browser test longer.

Use FETCHED_MARK.

It is honored in GUI, where it used to decide whether to get values

after user action.

It is set in standard algorithm for processing fetched values.

Add remove operation to side notes.

Make loading more lazy.

Improve loading policy.

On node choose load itself, on node expansion, load children.

Minor improvement.

Fix bug with panel interleaving.

Minor improvements.

Improve panel management.

More cleaning around panels.

Reorganize panels.

Further improve tree.

Fix bug in TreeModel?.

Remove children from TreeNode?.

Implement TreeNode? hashCode and equals.

Make TreeNode? delegate equals and hashcode to internal reference.

Move listeners from TreeNode? to side notes.

Store path.textual as a side note.

Side note params instead of accesses for objects.

More refactorizations.

In TreeNode? bindAccess based on side notes.

Minor step.

Hide createAccess.

Rename AccessInterface? to Access.

Minor changes.

Several improvements in high load scenarios.

Change semantics of ArrayListAccess?.set(index, null);

It now removes the element, making list shorter
(it was set to null before).

Add path remove handler.

Handle exceptions in Connection.

Update .gitignore

Configure logging to file.

Move registration to TreeModel?.

Further refactorization.

Minor refactorization.

Minor improvements.

Use specialized event also for Modify action of ListChange?.

Use remove events.

Use the insertion events for tree.

Further improve tree refreshing.

Further improve reacting on events in GUI.

Fix problem with not adding objects on addition list change.

Migrate to log4j lazy String construction interface.

Migrate imports to log4j2.

Drop dependency on adapter to version 1.2.

Switch log4j implementation to log4j2.

Add dirty mark to the NodeAtFrame?.

Make selecting in AccessInterfaces? type safe.

Ignore containers size settings in Model and Genotype.

Use tree side notes to remember local changes and panels.

Add sideNotes to tree.

They will be used to store various accompanying information
right in the tree.

Use ReferenceIdentityMap? from apache in TreeNode?.

It suits the need perfectly (weak semantics on both key and value).

Make ArrayListParam? do not react size changes.

Guard in TableModel? before not yet loaded objects.

Add <include/> clause and AutoInjector?.

Extract common columns configuration to separate xml,
that can be included by other configurations.

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