001    /*
002     * Copyright (C) 2006-2007 the original author or authors.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.codehaus.gmaven.runtime.support.stubgen.model;
018    
019    import java.util.Iterator;
020    import java.util.LinkedHashSet;
021    import java.util.Set;
022    
023    /**
024     * Representation of for entity modifiers.
025     *
026     * @version $Id: ModifiersDef.java 18 2009-07-16 09:39:40Z user57 $
027     * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
028     */
029    public class ModifiersDef
030        extends Element
031    {
032        public static final String ABSTRACT = "abstract";
033    
034        public static final String PUBLIC = "public";
035    
036        public static final String PRIVATE = "private";
037    
038        public static final String PROTECTED = "protected";
039    
040        public static final String STATIC = "static";
041    
042        public static final String FINAL = "final";
043    
044        public static final String SYNCHRONIZED = "synchronized";
045    
046        public static final String TRANSIENT = "transient";
047    
048        public static final String VOLATILE = "volatile";
049    
050        public static final String NATIVE = "native";
051    
052        public static final String STRICTFP = "strictfp";
053    
054        private final Set values = new LinkedHashSet();
055    
056        public ModifiersDef add(final String modifier) {
057            assert modifier != null;
058    
059            values.add(modifier);
060    
061            return this;
062        }
063    
064        public ModifiersDef remove(final String modifier) {
065            assert modifier != null;
066    
067            values.remove(modifier);
068    
069            return this;    
070        }
071    
072        public ModifiersDef merge(final ModifiersDef modifiers) {
073            assert modifiers != null;
074    
075            Iterator iter = modifiers.getValues().iterator();
076            
077            while (iter.hasNext()) {
078                String modifier = (String)iter.next();
079                add(modifier);
080            }
081    
082            return this;
083        }
084    
085        public Set getValues() {
086            return values;
087        }
088    
089        private boolean contains(final String modifier) {
090            assert modifier != null;
091    
092            return values.contains(modifier);
093        }
094        
095        //
096        // Helpers
097        //
098    
099        public boolean isAbstract() {
100            return contains(ABSTRACT);
101        }
102    
103        public boolean isPublic() {
104            return contains(PUBLIC);
105        }
106    
107        public boolean isPrivate() {
108            return contains(PRIVATE);
109        }
110    
111        public boolean isProtected() {
112            return contains(PROTECTED);
113        }
114    
115        public boolean isStatic() {
116            return contains(STATIC);
117        }
118    
119        public boolean isFinal() {
120            return contains(FINAL);
121        }
122    
123        public boolean isSynchronized() {
124            return contains(SYNCHRONIZED);
125        }
126    
127        public boolean isTransient() {
128            return contains(TRANSIENT);
129        }
130    
131            public boolean isVolatile() {
132            return contains(VOLATILE);
133        }
134    
135            public boolean isNative() {
136            return contains(NATIVE);
137        }
138    
139            public boolean isStrictfp() {
140            return contains(STRICTFP);
141        }
142    
143        public boolean hasAccessModifiers() {
144            return
145                isPrivate() ||
146                isProtected() ||
147                isPublic();
148        }
149    }