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", order = {"id", "name", "type", "flags", "help", "group", "extra"}) |
---|
20 | public abstract class Param { |
---|
21 | |
---|
22 | /** The parameter id. */ |
---|
23 | protected final String id; |
---|
24 | |
---|
25 | /** The parameter name. */ |
---|
26 | protected final String name; |
---|
27 | |
---|
28 | /** The help (description) concerning parameter. */ |
---|
29 | protected final String help; |
---|
30 | |
---|
31 | /** The number of group, that parameter belongs to. */ |
---|
32 | protected final Integer group; |
---|
33 | |
---|
34 | /** The getFlags stored as a bit sum. */ |
---|
35 | protected final int flags; |
---|
36 | |
---|
37 | /** The variable determining whether the parameter is an extra parameter. */ |
---|
38 | protected final int extra; |
---|
39 | |
---|
40 | public Param(ParamBuilder builder) { |
---|
41 | id = builder.getId(); |
---|
42 | name = builder.getName(); |
---|
43 | help = builder.getHelp(); |
---|
44 | group = builder.getGroup(); |
---|
45 | flags = builder.getFlags(); |
---|
46 | extra = builder.getExtra(); |
---|
47 | } |
---|
48 | |
---|
49 | @ParamAnnotation |
---|
50 | public String getId() { |
---|
51 | return id; |
---|
52 | } |
---|
53 | |
---|
54 | @ParamAnnotation |
---|
55 | public String getName() { |
---|
56 | return name; |
---|
57 | } |
---|
58 | |
---|
59 | @ParamAnnotation |
---|
60 | public String getHelp() { |
---|
61 | return help; |
---|
62 | } |
---|
63 | |
---|
64 | @ParamAnnotation |
---|
65 | public Integer getGroup() { |
---|
66 | return group; |
---|
67 | } |
---|
68 | |
---|
69 | @ParamAnnotation(def = "0") |
---|
70 | public Integer getFlags() { |
---|
71 | return flags; |
---|
72 | } |
---|
73 | |
---|
74 | @ParamAnnotation(id = "type") |
---|
75 | public abstract String getFramsTypeName(); |
---|
76 | |
---|
77 | @ParamAnnotation |
---|
78 | public Integer getExtra() { |
---|
79 | return extra; |
---|
80 | } |
---|
81 | |
---|
82 | @Override |
---|
83 | public String toString() { |
---|
84 | return getId() + ":" + this.getClass().getSimpleName(); |
---|
85 | } |
---|
86 | |
---|
87 | public boolean hasFlag(int flag) { |
---|
88 | return (flags & flag) != 0; |
---|
89 | } |
---|
90 | |
---|
91 | public static ParamBuilder build() { |
---|
92 | return new ParamBuilder(); |
---|
93 | } |
---|
94 | |
---|
95 | public static ParamBuilder build(FramsClassBuilder builder) { |
---|
96 | return new ParamBuilder(builder); |
---|
97 | } |
---|
98 | |
---|
99 | } |
---|