Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/objectmodel/com/ibm/j9tools/om/FlagDefinition.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2007, 2019 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.Collections;
25
import java.util.HashMap;
26
import java.util.Map;
27
import java.util.Set;
28
import java.util.StringTokenizer;
29
import java.util.TreeMap;
30
31
/**
32
* Describes flag details but not a Flag state. Its principal use is to provide means
33
* of defining Flag Requirements and Precludes chains. It will also verbosely describe the
34
* function of any given Flag along with reprecisions involved in modifying or removing
35
* that Flag.
36
*
37
* @author Maciek Klimkowski
38
* @author Gabriel Castro
39
* @author Han Xu
40
*/
41
public class FlagDefinition extends OMObject implements Comparable<FlagDefinition> {
42
protected boolean complete = false;
43
44
/**
45
* An unique flag identifier.
46
*/
47
protected String id;
48
49
/**
50
* A free text field that describes the purpose of the flag, and specifically
51
* indicates what will happen if the flag is activated. This field is intended
52
* to help end users configure the virtual machine, so please be as verbose as
53
* necessary when describing the impact of enabling the flag.
54
*/
55
protected String description;
56
57
/**
58
* A free text field that describes what will happen if the flag is removed.
59
* This field is intended to help end users configure the virtual machine,
60
* so please be as verbose as necessary when describing the impact of removing
61
* the flag.
62
*/
63
protected String ifRemoved;
64
65
/**
66
* A set of requires flags.
67
* Represents a depends-on linkage between flags. Indicates that the flag requires
68
* that another flag be enabled. The flag which is dependent upon is identified
69
* by name using the flag attribute.
70
*/
71
protected Map<String, FlagDefinition> requires = new TreeMap<String, FlagDefinition>();
72
73
/**
74
* A set of elements which identify flags that are incompatible with the
75
* containing flag definition.
76
* Represents an either-or linkage between flags. Indicates that the flag
77
* cannot function properly in the presence of another enabled flag. The incompatible
78
* flags is identified by name using the flag attribute.
79
*/
80
protected Map<String, FlagDefinition> precludes = new TreeMap<String, FlagDefinition>();
81
82
/**
83
* Default FlagDefinition constructor
84
*/
85
public FlagDefinition() {
86
}
87
88
/**
89
* Default FlagDefinition constructor
90
*
91
* @param id Flag id
92
* @param description Flag free text description
93
* @param ifRemoved Flag free text description of flag removal repercussions
94
*/
95
public FlagDefinition(String id, String description, String ifRemoved) {
96
this.id = id;
97
98
this.description = description;
99
this.ifRemoved = ifRemoved;
100
}
101
102
public String getId() {
103
return id;
104
}
105
106
public void setId(String id) {
107
this.id = id;
108
}
109
110
public String getDescription() {
111
return description;
112
}
113
114
public void setDescription(String description) {
115
this.description = description;
116
}
117
118
public String getIfRemoved() {
119
return ifRemoved;
120
}
121
122
public void setIfRemoved(String ifRemoved) {
123
this.ifRemoved = ifRemoved;
124
}
125
126
/**
127
* Add a single requires flag to this flags required flags list
128
*
129
* @param requiredFlag the required flag
130
*/
131
public void addRequires(FlagDefinition requiredFlag) {
132
requires.put(requiredFlag.getId(), requiredFlag);
133
}
134
135
public Map<String, FlagDefinition> getLocalRequires() {
136
return Collections.unmodifiableMap(requires);
137
}
138
139
public Map<String, FlagDefinition> getRequires() {
140
Map<String, FlagDefinition> allRequires = new HashMap<String, FlagDefinition>();
141
addAllRequires(allRequires, this);
142
143
return Collections.unmodifiableMap(allRequires);
144
}
145
146
private void addAllRequires(Map<String, FlagDefinition> allRequires, FlagDefinition definition) {
147
for (FlagDefinition require : definition.getLocalRequires().values()) {
148
if (!allRequires.containsKey(require.getId()) && !require.equals(definition)) {
149
allRequires.put(require.getId(), require);
150
addAllRequires(allRequires, require);
151
}
152
}
153
}
154
155
public void setRequires(Set<FlagDefinition> requires) {
156
this.requires.clear();
157
158
for (FlagDefinition flagDefinition : requires) {
159
this.requires.put(flagDefinition.getId(), flagDefinition);
160
}
161
}
162
163
public void removeRequires(String requireFlagId) {
164
requires.remove(requireFlagId);
165
}
166
167
/**
168
* Add a single precludes flag to this flags precluded flags list
169
*
170
* @param precludeFlag the precluded flag
171
*/
172
public void addPrecludes(FlagDefinition precludeFlag) {
173
precludes.put(precludeFlag.getId(), precludeFlag);
174
}
175
176
public Map<String, FlagDefinition> getLocalPrecludes() {
177
return Collections.unmodifiableMap(precludes);
178
}
179
180
public Map<String, FlagDefinition> getPrecludes() {
181
Map<String, FlagDefinition> allPrecludes = new HashMap<String, FlagDefinition>();
182
allPrecludes.putAll(precludes);
183
184
for (FlagDefinition requirement : getRequires().values()) {
185
allPrecludes.putAll(requirement.getLocalPrecludes());
186
}
187
188
return Collections.unmodifiableMap(allPrecludes);
189
}
190
191
public void setPrecludes(Set<FlagDefinition> precludes) {
192
this.precludes.clear();
193
194
for (FlagDefinition flagDefinition : precludes) {
195
this.precludes.put(flagDefinition.getId(), flagDefinition);
196
}
197
}
198
199
public void removePrecludes(String precludeFlagId) {
200
precludes.remove(precludeFlagId);
201
}
202
203
/**
204
* Retrieves the category (i.e. prefix) of the flag definition.
205
*
206
* @return the category name
207
*/
208
public String getCategory() {
209
StringTokenizer st = new StringTokenizer(id, "_"); //$NON-NLS-1$
210
211
return (st.countTokens() == 1) ? "default" : st.nextToken(); //$NON-NLS-1$
212
}
213
214
/**
215
* Retrieves the component (ie. the postfix) of a flag definition.
216
*
217
* @return the component name
218
*/
219
public String getComponent() {
220
StringTokenizer st = new StringTokenizer(id, "_"); //$NON-NLS-1$
221
222
return (st.countTokens() == 1) ? st.nextToken() : id.substring(getCategory().length() + 1);
223
}
224
225
/**
226
* Defines this flag definition as fully parsed.
227
*
228
* @param complete <code>true</code> if definition fully parse, <code>false</code> otherwise
229
*/
230
public void setComplete(boolean complete) {
231
this.complete = complete;
232
}
233
234
/**
235
* Determines if this flag definition has been fully parsed.
236
*
237
* @return <code>true</code> if definition fully parse, <code>false</code> otherwise
238
*/
239
public boolean isComplete() {
240
return complete;
241
}
242
243
/**
244
* @see java.lang.Comparable#compareTo(java.lang.Object)
245
*/
246
public int compareTo(FlagDefinition flagDef) {
247
return getComponent().compareTo(flagDef.getComponent());
248
}
249
250
/**
251
* @see java.lang.Object#equals(java.lang.Object)
252
*/
253
@Override
254
public boolean equals(Object o) {
255
if (o instanceof FlagDefinition) {
256
FlagDefinition def = (FlagDefinition) o;
257
258
return (id.equalsIgnoreCase(def.id) && description.equals(def.description) && requires.equals(def.requires) && precludes.equals(def.precludes));
259
}
260
return false;
261
}
262
263
}
264
265