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

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

HIGHLIGHTS:

  • FramsClass? and contained Param are now immutable classes (like String),

which allows to refer to them concurrently without synchronization
(which for example in turn simplifies GUI management)

  • also make Path immutable (which was earlier only assumed)
  • add global cache for FramsClasses? created solely and automatically

on base of Java classes.

representations basing on given FramsClass?

  • above changes greatly improved GUI responsivness during browsing
  • furtherly improve Param class hierarchy
  • allow to inject actions on state changes into MultiParamLoader?
  • add more tests

CHANGELOG:

Add StatusListener? to MultiParamLoader?.

Minor refactorization in MultiParamLoader?.

First step with auto append.

Add SchemaTest?.

Improve Registry.

Clean up in Registry.

Work out Registry.

Use annotations for Param.

Fix ListChange?.

Improve fluent interface of the FramsClassBuilder?.

Done caching of ReflectionAccess?.Backend

Fix hashCode of Pair.

A step on a way to cache ReflectionAccess?.Backend

Make SimpleAbstractAccess?.framsClass a final field.

Add static cache for FramsClasses? based on java.

Only classes created strictly and automatically
based on java classes are using this cache.

Make all Params immutable.

Many improvement to make Param immutable.

Make PrimitiveParam? generic type.

Several changes to make Param immutable.

Make FramsClass? immutable.

Another improvement to Path immutability.

Several improvements to Path.

Improve PathTest?.

Configurarable MutabilityDetector?.

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