View Javadoc
1   /*
2    * #%L
3    * EUGene :: EUGene
4    * %%
5    * Copyright (C) 2004 - 2012 CodeLutin
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20   * #L%
21   */
22  package org.nuiton.eugene.models.object;
23  
24  import com.google.common.collect.ImmutableSet;
25  
26  import java.util.Set;
27  
28  /**
29   * Enum that represents Java possible modifiers
30   *
31   * @author Arnaud Thimel (Code Lutin)
32   * @since 2.4.3
33   */
34  public enum ObjectModelJavaModifier implements ObjectModelModifier {
35  
36      STATIC,
37      FINAL,
38      ABSTRACT,
39      TRANSIENT,
40  
41      PUBLIC,
42      PROTECTED,
43      PRIVATE,
44      PACKAGE,
45  
46      VOLATILE,
47      SYNCHRONIZED,
48      NATIVE,
49      STRICTFP;
50  
51      public static final Set<? extends ObjectModelModifier> visibilityModifiers =
52              ImmutableSet.of(PUBLIC, PROTECTED, PRIVATE, PACKAGE);
53  
54      @Override
55      public boolean isVisibility() {
56          return visibilityModifiers.contains(this);
57      }
58  
59      @Override
60      public boolean isAssociationType() {
61          return false;
62      }
63  
64      @Override
65      public String getName() {
66          return name();
67      }
68  
69      @Override
70      public String toString() {
71          String result = name().toLowerCase();
72          if (PACKAGE.equals(this)) {
73              result = "";
74          }
75          return result;
76      }
77  
78      public static ObjectModelJavaModifier fromVisibility(String name) {
79          if (name.equals(PUBLIC.toString())) {
80              return PUBLIC;
81          } else if (name.equals(PRIVATE.toString())) {
82              return PRIVATE;
83          } else if (name.equals(PROTECTED.toString())) {
84              return PROTECTED;
85          } else if (name.equals(PACKAGE.toString())) {
86              return PACKAGE;
87          } else {
88              return null;
89          }
90      }
91  
92  }