Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/objectmodel/com/ibm/j9tools/om/Flag.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2007, 2011 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
package com.ibm.j9tools.om;
23
24
import java.util.Map;
25
import java.util.Set;
26
27
/**
28
* A container class used to keep track of a single Flag and its state
29
*
30
* @author Maciek Klimkowski
31
* @author Gabriel Castro
32
* @author Han Xu
33
*/
34
public class Flag extends FlagDefinition {
35
private Boolean state;
36
private FlagDefinition flagDefinition;
37
38
/**
39
* Creates a flag with the given ID and a default state of <code>false</code>.
40
*
41
* @param id the ID of this flag
42
*/
43
public Flag(String id) {
44
this(id, false);
45
}
46
47
/**
48
* Creates a flag with the given ID and state
49
*
50
* @param id the ID of this flag
51
* @param state the state of this flag
52
*/
53
public Flag(String id, Boolean state) {
54
this.id = id;
55
this.state = state;
56
}
57
58
/**
59
* Creates a flag from the given {@link FlagDefinition} with a default state
60
* of <code>false</code>. The flag ID will be the same as the given {@link FlagDefinition}.
61
*
62
* @param flagDef the parent flag definition
63
*/
64
public Flag(FlagDefinition flagDef) {
65
this(flagDef, false);
66
}
67
68
/**
69
* Creates a flag from the given {@link FlagDefinition} with the given state.
70
* The flag ID will be the same as the given {@link FlagDefinition}.
71
*
72
* @param flagDef the parent flag definition
73
* @param state the state of this flag
74
*/
75
public Flag(FlagDefinition flagDef, boolean state) {
76
this(flagDef.getId(), state);
77
this.setDefinition(flagDef);
78
}
79
80
/**
81
* Sets the {@link FlagDefinitions} associated with this flag.
82
*
83
* @param flagDef the flag definition for this flag
84
*/
85
public void setDefinition(FlagDefinition flagDef) {
86
this.flagDefinition = flagDef;
87
this.complete = true;
88
}
89
90
/**
91
* Removes the {@link FlagDefinition} associated with this flag.
92
*/
93
public void removeDefinition() {
94
this.flagDefinition = null;
95
complete = false;
96
}
97
98
/**
99
* Retrieves the state of this flag.
100
*
101
* @return <code>true</code> if this flag is enabled, <code>false</code> otherwise
102
*/
103
public Boolean getState() {
104
return state;
105
}
106
107
/**
108
* @see com.ibm.j9tools.om.FlagDefinition#getDescription()
109
*/
110
@Override
111
public String getDescription() {
112
return (complete) ? flagDefinition.getDescription() : super.getDescription();
113
}
114
115
/**
116
* @see com.ibm.j9tools.om.FlagDefinition#getIfRemoved()
117
*/
118
@Override
119
public String getIfRemoved() {
120
return (complete) ? flagDefinition.getIfRemoved() : super.getIfRemoved();
121
}
122
123
/**
124
* @see com.ibm.j9tools.om.FlagDefinition#getPrecludes()
125
*/
126
@Override
127
public Map<String, FlagDefinition> getPrecludes() {
128
return (complete) ? flagDefinition.getPrecludes() : super.getPrecludes();
129
}
130
131
@Override
132
public Map<String, FlagDefinition> getLocalPrecludes() {
133
return (complete) ? flagDefinition.getLocalPrecludes() : super.getLocalPrecludes();
134
}
135
136
/**
137
* @see com.ibm.j9tools.om.FlagDefinition#getRequires()
138
*/
139
@Override
140
public Map<String, FlagDefinition> getRequires() {
141
return (complete) ? flagDefinition.getRequires() : super.getRequires();
142
}
143
144
@Override
145
public Map<String, FlagDefinition> getLocalRequires() {
146
return (complete) ? flagDefinition.getLocalRequires() : super.getLocalRequires();
147
}
148
149
/**
150
* @see com.ibm.j9tools.om.FlagDefinition#setPrecludes(java.util.Set)
151
*/
152
@Override
153
public void setPrecludes(Set<FlagDefinition> precludes) {
154
// Not allowed for Flag
155
}
156
157
/**
158
* @see com.ibm.j9tools.om.FlagDefinition#addPrecludes(com.ibm.j9tools.om.FlagDefinition)
159
*/
160
@Override
161
public void addPrecludes(FlagDefinition precludeFlag) {
162
// Not allowed for Flag
163
}
164
165
/**
166
* @see com.ibm.j9tools.om.FlagDefinition#removePrecludes(java.lang.String)
167
*/
168
@Override
169
public void removePrecludes(String precludeFlagId) {
170
// Not allowed for Flag
171
}
172
173
/**
174
* @see com.ibm.j9tools.om.FlagDefinition#setRequires(java.util.Set)
175
*/
176
@Override
177
public void setRequires(Set<FlagDefinition> requires) {
178
// Not allowed for Flag
179
}
180
181
/**
182
* @see com.ibm.j9tools.om.FlagDefinition#addRequires(com.ibm.j9tools.om.FlagDefinition)
183
*/
184
@Override
185
public void addRequires(FlagDefinition requiredFlag) {
186
// Not allowed for Flag
187
}
188
189
/**
190
* @see com.ibm.j9tools.om.FlagDefinition#removeRequires(java.lang.String)
191
*/
192
@Override
193
public void removeRequires(String requireFlagId) {
194
// Not allowed for Flag
195
}
196
197
/**
198
* @see com.ibm.j9tools.om.FlagDefinition#setDescription(java.lang.String)
199
*/
200
@Override
201
public void setDescription(String description) {
202
// Not allowed for Flag
203
}
204
205
/**
206
* @see com.ibm.j9tools.om.FlagDefinition#setIfRemoved(java.lang.String)
207
*/
208
@Override
209
public void setIfRemoved(String ifRemoved) {
210
// Not allowed for Flag
211
}
212
213
/**
214
* Sets the state of this flag.
215
*
216
* @param state the flag state
217
*/
218
public void setState(Boolean state) {
219
this.state = state;
220
}
221
222
/**
223
* @see com.ibm.j9tools.om.FlagDefinition#equals(java.lang.Object)
224
*/
225
@Override
226
public boolean equals(Object o) {
227
return (o instanceof Flag) ? (id.equalsIgnoreCase(((Flag) o).id) && state.equals(((Flag) o).state)) : false;
228
}
229
230
}
231
232