source: java/main/src/main/java/com/framsticks/params/Param.java @ 86

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

HIGHLIGHTS:

  • use java annotations to mark classes and fields to be used when:
    • using java classes with ReflectionAccess? to represent remote objects with FramsClass? description found by "info ..." requests
    • to build up FramsClass? representation of objects not present at remote server
  • allow using primitive types (instead of wraping counterparts) in reflected classes
  • rework FramsClass? creation process (add FramsClassBuilder?)
  • add more tests

CHANGELOG:
Prepare model.World class.

Minor change.

Use primitive types for Genotype and Creature classes.

Use primitive types in model.Neuro* classes.

Use primitive types in model.Joint* classes.

Use primitive types in model.Part* classes.

Fix primitive values.

Extract FramsClassBuilder?.

Add tests of Model classes.

More fixes.

Refactorize out ParamCandidate?.

Several fixes.

Fix all regressions after introducing annotations.

Use annotations throughout the project.

Add exception classes.

Improve creation of FramsClass?.

More changes.

Many changes regarding annotations.

Annotate classes in com.framsticks.model package.

Remove manual FramsClass? constructor.

Construct FramsClass? for Creature. Add test.

Add default values to the ParamAnnotation?.

Add ParamBuilderTest? and ParamAnnotation?.

Add FramsClassAnnotation?.

File size: 2.5 KB
Line 
1package com.framsticks.params;
2
3
4import com.framsticks.params.types.DecimalParam;
5import com.framsticks.params.types.StringParam;
6
7/**
8 * Based on c++ struct ParamEntry located in cpp/gdk/param.h
9 * Here  it is a root of Param hierarchy.
10 *
11 * @author Jarek Szymczak <name.surname@gmail.com>, Mateusz Jarus
12 * (please replace name and surname with my personal data)
13 *
14 * @author Piotr Śniegowski
15 */
16public abstract class Param {
17
18        /** The parameter id. */
19        protected String id;
20
21        /**
22         * The parameter internal id. It's set by a user to use user's own getId in
23         * code
24         */
25        protected String internalId;
26
27        /** The parameter name. */
28        protected String name;
29
30        /** The help (description) concerning parameter. */
31        protected String help;
32
33        /** The number of group, that parameter belongs to. */
34        protected Integer group;
35
36        /** The getFlags stored as a bit sum. */
37        protected Integer flags;
38
39        /** The variable determining whether the parameter is an extra parameter. */
40        protected Integer extra;
41
42
43        public Param() {
44
45        }
46
47        public String getId() {
48                return id;
49        }
50
51        public String getInternalId() {
52                return internalId;
53        }
54
55        public String getName() {
56                return name;
57        }
58
59        public String getHelp() {
60                return help;
61        }
62
63        public Integer getGroup() {
64                return group;
65        }
66
67        public Integer getFlags() {
68                return flags;
69        }
70
71        public abstract String getFramsTypeName();
72
73
74        public String getEffectiveId() {
75                return (internalId != null) ? internalId : id;
76        }
77
78
79        public Integer getExtra() {
80                return extra;
81        }
82
83        public void setInternalId(String internalId) {
84                this.internalId = internalId;
85        }
86
87        @Override
88        public String toString() {
89                return getId() + ":" + this.getClass().getSimpleName();
90        }
91
92        public boolean isNumeric() {
93                return false;
94        }
95
96        public abstract Class<?> getStorageType();
97
98        public boolean hasFlag(int flag) {
99                return flags != null && (flags & flag) != 0;
100        }
101
102        public boolean isUserHidden() {
103                return (flags & Flags.USERHIDDEN) != 0;
104        }
105
106        public static FramsClass getFramsClass() {
107                return new FramsClass("prop", "prop", null)
108                        .append(Param.build().id("name").name("Name").type(StringParam.class).finish())
109                        .append(Param.build().id("id").name("Id").type(StringParam.class).finish())
110                        .append(Param.build().id("type").name("Type").type(StringParam.class).finish())
111                        .append(Param.build().id("help").name("Help").type(StringParam.class).finish())
112                        .append(Param.build().id("flags").name("Flags").type(DecimalParam.class).finish());
113        }
114
115        public static ParamBuilder build() {
116                return new ParamBuilder();
117        }
118
119}
Note: See TracBrowser for help on using the repository browser.