source: java/main/src/main/java/com/framsticks/params/FramsClass.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: 4.0 KB
Line 
1package com.framsticks.params;
2
3import com.framsticks.params.annotations.FramsClassAnnotation;
4import com.framsticks.params.annotations.ParamAnnotation;
5import com.framsticks.util.lang.Containers;
6import com.framsticks.util.lang.Strings;
7// import com.framsticks.util.FramsticksException;
8
9import java.util.*;
10
11import javax.annotation.concurrent.Immutable;
12
13import org.apache.logging.log4j.Logger;
14import org.apache.logging.log4j.LogManager;
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 implements ParamCollection {
31
32        private final static Logger log = LogManager.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        protected final List<CompositeParam> compositeParamList = new ArrayList<>();
46
47        /**
48         * The param entry map <parameterId, param> (for fast accessing of parameters
49         * by their name)
50         */
51        protected Map<String, Param> paramEntryMap = new HashMap<>();
52
53
54        @ParamAnnotation(id = "props", name = "props")
55        public List<Param> getParams() {
56                return Collections.unmodifiableList(paramList);
57        }
58
59        public FramsClass(FramsClassBuilder builder) {
60
61                this.id = builder.getId();
62                this.name = Strings.toStringEmptyProof(builder.getName(), this.id);
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                        if (param instanceof CompositeParam) {
70                                compositeParamList.add((CompositeParam) param);
71                        }
72                }
73
74                log.trace("created framsclass {}", this);
75
76        }
77
78        @ParamAnnotation(id = "desc")
79        public String getDescription() {
80                return description;
81        }
82
83        public int getGroupCount() {
84                return groups.size();
85        }
86
87        public Group getGroup(int groupNumber) {
88                return Containers.getFromList(groups, groupNumber, "group", this);
89        }
90
91        // /**
92        //  * Gets the group member.
93        //  *
94        //  * @param gi
95        //  *            the offset of group
96        //  * @param pi
97        //  *            the offset of member within a group
98        //  * @return the pi-th member of group gi
99        //  */
100        // public Param getGroupMember(int gi, int pi) {
101        //      if (gi < 0 || pi < 0 || gi >= groups.size()) {
102        //              return null;
103        //      }
104        //      Group group = groups.get(gi);
105        //      return (group != null ? group.getProperty(pi) : null);
106        // }
107
108        // /**
109        //  * Gets the group name.
110        //  *
111        //  * @param gi
112        //  *            the offset of group
113        //  * @return the group name
114        //  */
115        // public String getGroupName(int gi) {
116        //      if (gi < 0 || gi >= groups.size())
117        //              return null;
118        //      return groups.get(gi).name;
119        // }
120
121        @ParamAnnotation
122        public String getId() {
123                return id;
124        }
125
126        @ParamAnnotation
127        public String getName() {
128                return name;
129        }
130
131        public String getNiceName() {
132                return name != null ? name : id;
133        }
134
135        public Param getParam(int i) {
136                if (i < 0 || i >= paramList.size()) {
137                        return null;
138                }
139                return paramList.get(i);
140        }
141
142        public Param getParam(String id) {
143                if (!paramEntryMap.containsKey(id)) {
144                        return null;
145                }
146                return paramEntryMap.get(id);
147        }
148
149        public int getParamCount() {
150                return paramList.size();
151        }
152
153        public final int getCompositeParamCount() {
154                return compositeParamList.size();
155        }
156
157        public final CompositeParam getCompositeParam(int i) {
158                return compositeParamList.get(i);
159        }
160
161        @Override
162        public String toString() {
163                return id + "(" + name + ")";
164        }
165
166        public static FramsClassBuilder build() {
167                return new FramsClassBuilder();
168        }
169
170}
Note: See TracBrowser for help on using the repository browser.