KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > metadata > spi > scope > ScopeLevel


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software 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 GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.metadata.spi.scope;
23
24 import java.io.Serializable JavaDoc;
25 import java.util.concurrent.ConcurrentHashMap JavaDoc;
26
27 /**
28  * ScopeLevel.
29  *
30  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
31  * @version $Revision: 46146 $
32  */

33 public class ScopeLevel implements Serializable JavaDoc, Comparable JavaDoc<ScopeLevel>
34 {
35    /** The serialVersionUID */
36    private static final long serialVersionUID = 9090783215048463821L;
37
38    /** The levels by name */
39    private static final ConcurrentHashMap JavaDoc<String JavaDoc, Integer JavaDoc> levelsByName = new ConcurrentHashMap JavaDoc<String JavaDoc, Integer JavaDoc>();
40    
41    /** The scope level */
42    private final int level;
43    
44    /** The scope level name */
45    private final String JavaDoc name;
46
47    /**
48     * Get the scope level for a name
49     *
50     * @param name the name
51     * @return the level or zero if no such level name
52     */

53    public static int getScopeLevel(String JavaDoc name)
54    {
55       Integer JavaDoc result = levelsByName.get(name);
56       if (result != null)
57          return result;
58       else
59          return 0;
60    }
61    
62    /**
63     * Create a new ScopeLevel.
64     *
65     * @param level the level
66     * @param name the name
67     */

68    public ScopeLevel(int level, String JavaDoc name)
69    {
70       if (level <= 0)
71          throw new IllegalArgumentException JavaDoc("Invalid level");
72       if (name == null)
73          throw new IllegalArgumentException JavaDoc("Null name");
74       
75       this.level = level;
76       this.name = name;
77       levelsByName.put(name, level);
78    }
79    
80    public int getLevel()
81    {
82       return level;
83    }
84
85    public String JavaDoc getName()
86    {
87       return name;
88    }
89
90    public String JavaDoc toString()
91    {
92       return name;
93    }
94    
95    public int compareTo(ScopeLevel o)
96    {
97       return level - o.level;
98    }
99
100    public boolean equals(Object JavaDoc object)
101    {
102       if (object == this)
103          return true;
104       if (object == null || object instanceof ScopeLevel == false)
105          return false;
106       
107       ScopeLevel other = (ScopeLevel) object;
108       return level == other.level;
109    }
110    
111    public int hashCode()
112    {
113       return level;
114    }
115 }
116
Popular Tags