1 19 package org.netbeans.tax; 20 21 27 public final class TreeName { 28 29 33 final private String prefix; 34 35 39 final private String name; 40 41 42 46 final private String rawName; 47 48 49 53 56 public TreeName (String prefix, String name) throws InvalidArgumentException { 57 checkPrefix (prefix); 58 checkName (name); 59 60 this.prefix = prefix; 61 this.name = name; 62 this.rawName = getQualifiedName (prefix, name);; 63 } 64 65 68 public TreeName (String rawName) throws InvalidArgumentException { 69 checkRawName (rawName); 70 71 this.prefix = getPrefix (rawName); 72 this.name = getName (rawName); 73 this.rawName = rawName; 74 } 75 76 83 84 88 90 private static String getPrefix (String rawName) { 91 int i = rawName.indexOf (":"); 93 if (i < 0) { 94 return ""; } else { 96 return rawName.substring (0, i); 97 } 98 } 99 100 102 private static String getName (String rawName) { 103 int i = rawName.indexOf (":"); 105 if (i < 0) { 106 return rawName; 107 } else { 108 return rawName.substring (i + 1); 109 } 110 } 111 112 114 private static String getQualifiedName (String prefix, String name) { 115 if ( "".equals (prefix) ) { return name; 117 } else { 118 return (prefix + ":" + name); } 120 121 } 122 123 125 public String getPrefix () { 126 return prefix; 127 } 128 129 131 private void checkPrefix (String prefix) throws InvalidArgumentException { 132 if ( prefix == null ) { 133 throw createInvalidNullArgumentException (); 134 } 135 } 136 137 139 public String getName () { 140 return name; 141 } 142 143 145 private void checkName (String name) throws InvalidArgumentException { 146 if ( name == null ) { 147 throw createInvalidNullArgumentException (); 148 } 149 } 150 151 154 public String getQualifiedName () { 155 return rawName; 156 } 157 158 160 private void checkRawName (String rawName) throws InvalidArgumentException { 161 if ( rawName == null ) { 162 throw createInvalidNullArgumentException (); 163 } 164 } 165 166 168 private InvalidArgumentException createInvalidNullArgumentException () { 169 return new InvalidArgumentException 170 (Util.THIS.getString ("EXC_invalid_null_value"), 171 new NullPointerException ()); 172 } 173 174 176 public boolean equals (Object obj) { 177 if ( obj instanceof TreeName ) { 178 return rawName.equals (((TreeName)obj).rawName); 179 } 180 return false; 181 } 182 183 185 public int hashCode () { 186 return rawName.hashCode (); 187 } 188 189 191 public String toString () { 192 return rawName; 193 } 194 195 } 196 | Popular Tags |