1 | package com.framsticks.params; |
---|
2 | |
---|
3 | |
---|
4 | import javax.annotation.concurrent.Immutable; |
---|
5 | |
---|
6 | import com.framsticks.params.annotations.FramsClassAnnotation; |
---|
7 | import 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") |
---|
20 | public 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 | } |
---|