1 22 package org.jboss.metadata.spi.scope; 23 24 import java.io.Serializable ; 25 import java.util.concurrent.ConcurrentHashMap ; 26 27 33 public class ScopeLevel implements Serializable , Comparable <ScopeLevel> 34 { 35 36 private static final long serialVersionUID = 9090783215048463821L; 37 38 39 private static final ConcurrentHashMap <String , Integer > levelsByName = new ConcurrentHashMap <String , Integer >(); 40 41 42 private final int level; 43 44 45 private final String name; 46 47 53 public static int getScopeLevel(String name) 54 { 55 Integer result = levelsByName.get(name); 56 if (result != null) 57 return result; 58 else 59 return 0; 60 } 61 62 68 public ScopeLevel(int level, String name) 69 { 70 if (level <= 0) 71 throw new IllegalArgumentException ("Invalid level"); 72 if (name == null) 73 throw new IllegalArgumentException ("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 getName() 86 { 87 return name; 88 } 89 90 public String 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 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 |