Path: blob/master/sourcetools/objectmodel/com/ibm/j9tools/om/Flag.java
6004 views
/*******************************************************************************1* Copyright (c) 2007, 2011 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/21package com.ibm.j9tools.om;2223import java.util.Map;24import java.util.Set;2526/**27* A container class used to keep track of a single Flag and its state28*29* @author Maciek Klimkowski30* @author Gabriel Castro31* @author Han Xu32*/33public class Flag extends FlagDefinition {34private Boolean state;35private FlagDefinition flagDefinition;3637/**38* Creates a flag with the given ID and a default state of <code>false</code>.39*40* @param id the ID of this flag41*/42public Flag(String id) {43this(id, false);44}4546/**47* Creates a flag with the given ID and state48*49* @param id the ID of this flag50* @param state the state of this flag51*/52public Flag(String id, Boolean state) {53this.id = id;54this.state = state;55}5657/**58* Creates a flag from the given {@link FlagDefinition} with a default state59* of <code>false</code>. The flag ID will be the same as the given {@link FlagDefinition}.60*61* @param flagDef the parent flag definition62*/63public Flag(FlagDefinition flagDef) {64this(flagDef, false);65}6667/**68* Creates a flag from the given {@link FlagDefinition} with the given state.69* The flag ID will be the same as the given {@link FlagDefinition}.70*71* @param flagDef the parent flag definition72* @param state the state of this flag73*/74public Flag(FlagDefinition flagDef, boolean state) {75this(flagDef.getId(), state);76this.setDefinition(flagDef);77}7879/**80* Sets the {@link FlagDefinitions} associated with this flag.81*82* @param flagDef the flag definition for this flag83*/84public void setDefinition(FlagDefinition flagDef) {85this.flagDefinition = flagDef;86this.complete = true;87}8889/**90* Removes the {@link FlagDefinition} associated with this flag.91*/92public void removeDefinition() {93this.flagDefinition = null;94complete = false;95}9697/**98* Retrieves the state of this flag.99*100* @return <code>true</code> if this flag is enabled, <code>false</code> otherwise101*/102public Boolean getState() {103return state;104}105106/**107* @see com.ibm.j9tools.om.FlagDefinition#getDescription()108*/109@Override110public String getDescription() {111return (complete) ? flagDefinition.getDescription() : super.getDescription();112}113114/**115* @see com.ibm.j9tools.om.FlagDefinition#getIfRemoved()116*/117@Override118public String getIfRemoved() {119return (complete) ? flagDefinition.getIfRemoved() : super.getIfRemoved();120}121122/**123* @see com.ibm.j9tools.om.FlagDefinition#getPrecludes()124*/125@Override126public Map<String, FlagDefinition> getPrecludes() {127return (complete) ? flagDefinition.getPrecludes() : super.getPrecludes();128}129130@Override131public Map<String, FlagDefinition> getLocalPrecludes() {132return (complete) ? flagDefinition.getLocalPrecludes() : super.getLocalPrecludes();133}134135/**136* @see com.ibm.j9tools.om.FlagDefinition#getRequires()137*/138@Override139public Map<String, FlagDefinition> getRequires() {140return (complete) ? flagDefinition.getRequires() : super.getRequires();141}142143@Override144public Map<String, FlagDefinition> getLocalRequires() {145return (complete) ? flagDefinition.getLocalRequires() : super.getLocalRequires();146}147148/**149* @see com.ibm.j9tools.om.FlagDefinition#setPrecludes(java.util.Set)150*/151@Override152public void setPrecludes(Set<FlagDefinition> precludes) {153// Not allowed for Flag154}155156/**157* @see com.ibm.j9tools.om.FlagDefinition#addPrecludes(com.ibm.j9tools.om.FlagDefinition)158*/159@Override160public void addPrecludes(FlagDefinition precludeFlag) {161// Not allowed for Flag162}163164/**165* @see com.ibm.j9tools.om.FlagDefinition#removePrecludes(java.lang.String)166*/167@Override168public void removePrecludes(String precludeFlagId) {169// Not allowed for Flag170}171172/**173* @see com.ibm.j9tools.om.FlagDefinition#setRequires(java.util.Set)174*/175@Override176public void setRequires(Set<FlagDefinition> requires) {177// Not allowed for Flag178}179180/**181* @see com.ibm.j9tools.om.FlagDefinition#addRequires(com.ibm.j9tools.om.FlagDefinition)182*/183@Override184public void addRequires(FlagDefinition requiredFlag) {185// Not allowed for Flag186}187188/**189* @see com.ibm.j9tools.om.FlagDefinition#removeRequires(java.lang.String)190*/191@Override192public void removeRequires(String requireFlagId) {193// Not allowed for Flag194}195196/**197* @see com.ibm.j9tools.om.FlagDefinition#setDescription(java.lang.String)198*/199@Override200public void setDescription(String description) {201// Not allowed for Flag202}203204/**205* @see com.ibm.j9tools.om.FlagDefinition#setIfRemoved(java.lang.String)206*/207@Override208public void setIfRemoved(String ifRemoved) {209// Not allowed for Flag210}211212/**213* Sets the state of this flag.214*215* @param state the flag state216*/217public void setState(Boolean state) {218this.state = state;219}220221/**222* @see com.ibm.j9tools.om.FlagDefinition#equals(java.lang.Object)223*/224@Override225public boolean equals(Object o) {226return (o instanceof Flag) ? (id.equalsIgnoreCase(((Flag) o).id) && state.equals(((Flag) o).state)) : false;227}228229}230231232