1 6 package fr.jayasoft.ivy; 7 8 9 13 public class ModuleId { 14 static final String ENCODE_SEPARATOR = ":#@#:"; 15 private String _organisation; 16 private String _name; 17 private int _hash; 18 19 public ModuleId(String organisation, String name) { 20 if (name == null) { 21 throw new IllegalArgumentException ("null name not allowed"); 22 } 23 _organisation = organisation; 24 _name = name; 25 _hash = _hashCode(); } 27 28 public String getName() { 29 return _name; 30 } 31 public String getOrganisation() { 32 return _organisation; 33 } 34 35 public boolean equals(Object obj) { 36 if (! (obj instanceof ModuleId)) { 37 return false; 38 } 39 ModuleId other = (ModuleId)obj; 40 return other._organisation.equals(_organisation) && other._name.equals(_name); 41 } 42 public int hashCode() { 43 return _hash; 44 } 45 public int _hashCode() { 46 int hash = 31; 47 hash = hash * 13 + _organisation.hashCode(); 48 hash = hash * 13 + _name.hashCode(); 49 return hash; 50 } 51 public String toString() { 52 return "[ "+_organisation+" | "+_name+" ]"; 53 } 54 55 public String encodeToString() { 56 return getOrganisation() + ENCODE_SEPARATOR + getName(); 57 } 58 public static ModuleId decode(String encoded) { 59 String [] parts = encoded.split(ENCODE_SEPARATOR); 60 if (parts.length != 2) { 61 throw new IllegalArgumentException ("badly encoded module id: '"+encoded+"'"); 62 } 63 return new ModuleId(parts[0], parts[1]); 64 } 65 } 66 | Popular Tags |