source: java/main/src/main/java/com/framsticks/params/PrimitiveParam.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: 2.9 KB
Line 
1package com.framsticks.params;
2
3import com.framsticks.util.FramsticksException;
4import com.framsticks.util.Misc;
5import com.framsticks.util.lang.Numbers;
6
7import javax.annotation.concurrent.Immutable;
8
9/**
10 * @author Piotr Sniegowski
11 */
12@Immutable
13public abstract class PrimitiveParam<S> extends ValueParam {
14
15        /** The minimum allowed value of parameter. */
16        protected final Object min;
17
18        /** The maximum allowed value of parameter. */
19        protected final Object max;
20
21        /** The default value of parameter. */
22        protected final Object def;
23
24        /**
25         * @param builder
26         */
27        public PrimitiveParam(ParamBuilder builder) {
28                super(builder);
29                Class<?> storageType = Misc.returnNotNull(builder.getStorageType(), Object.class);
30                min = tryCastAndReturn(builder.getMin(), storageType);
31                max = tryCastAndReturn(builder.getMax(), storageType);
32                def = tryCastAndReturn(builder.getDef(), storageType);
33        }
34
35        public void save(SinkInterface sink, Object value) {
36                sink.print(value);
37        }
38
39        protected <T> T tryCastAndReturn(Object value, Class<T> type) {
40                if (value == null) {
41                        return null;
42                }
43                try {
44                        if (type.equals(Object.class)) {
45                                return type.cast(value);
46                        }
47                        if (value instanceof String) {
48                                if (type.equals(String.class)) {
49                                        return type.cast(value);
50                                }
51                                // if (Number.class.isAssignableFrom(type)) {
52                                return Numbers.parse((String) value, type);
53                                // }
54                                // return null;
55                        } else {
56                                return type.cast(value);
57                        }
58                } catch (ClassCastException e) {
59                        throw new FramsticksException().msg("failed to cast").cause(e).arg("param", this).arg("actual", value.getClass()).arg("requested", type);
60                }
61        }
62
63        /**
64         * Gets the minimum value of parameter.
65         *
66         * @param <T> the generic getType which must be correctly specified by user
67         * @param type the getType of variable, can be checked by
68         * @return the minimum allowed value of parameter
69         * @throws ClassCastException the class cast exception, thrown when given getType is incorrect
70         */
71        public <T> T getMin(Class<T> type) {
72                return tryCastAndReturn(min, type);
73        }
74
75        /**
76         * Gets the maximum value of parameter.
77         *
78         * @param <T> the generic getType which must be correctly specified by user
79         * @param type the getType of variable, can be checked by {@link #getStorageType()}
80         * @return the maximum allowed value of parameter
81         * @throws ClassCastException the class cast exception, thrown when given getType is incorrect
82         */
83        public <T> T getMax(Class<T> type) {
84                return tryCastAndReturn(max, type);
85        }
86
87        /**
88         * Gets the default value of parameter.
89         *
90         * @param <T> the generic getType which must be correctly specified by user
91         * @param type the getType of variable, can be checked by {@link #getStorageType()}
92         * @return the default value of parameter
93         * @throws ClassCastException the class cast exception, thrown when given getType is incorrect
94         */
95        public <T> T getDef(Class<T> type) {
96                return tryCastAndReturn(def, type);
97        }
98
99}
Note: See TracBrowser for help on using the repository browser.