1 package zirc.base ; 2 3 16 23 24 public class ChanUser implements Comparable 25 { 26 27 public static final int OP = 0 ; 29 public static final int HALFOP = 1 ; 30 public static final int VOICE = 2 ; 31 public static final int NORM = 3 ; 32 33 public static final char[] RANKCHARS = 35 {'@', '%', '+', ' '} ; 36 37 private char[] userRanks = new char[4] ; 39 40 private int rank ; 41 private String user ; 42 43 public ChanUser(String _user) 44 { 45 String rang = _user.substring(0, 1) ; 46 if (rang.equals("@")) 47 { 48 user = _user.substring(1, _user.length()) ; 49 rank = 0 ; 50 } 51 else 52 { 53 if (rang.equals("%")) 54 { 55 user = _user.substring(1, _user.length()) ; 56 rank = 1 ; 57 } 58 else 59 { 60 if (rang.equals("+")) 61 { 62 user = _user.substring(1, _user.length()) ; 63 rank = 2 ; 64 } 65 else 66 { 67 user = _user ; 68 rank = 3 ; 69 } 70 } 71 } 72 } 73 74 public ChanUser(String _user, int _rank) 75 { 76 user = _user ; 77 rank = _rank ; 78 79 } 80 81 public int getRank() 82 { 83 return rank ; 84 } 85 86 public String getNameSansRank() 87 { 88 return user ; 89 } 90 91 public String getNameAvecRank() 92 { 93 return new String (RANKCHARS[rank] + user).trim() ; 94 } 95 96 public String toString() 98 { 99 return getNameAvecRank() ; 100 } 101 102 public boolean equals(Object o) 104 { 105 if (o == null) 106 { 107 return false ; 108 } 109 110 if (!(o instanceof ChanUser)) 111 { 112 return false ; 113 } 114 115 if (!(((ChanUser)(o)).getNameSansRank().equalsIgnoreCase(user))) 116 { 117 return false ; 118 } 119 120 return true ; 121 } 122 123 public void setName(String _name) 124 { 125 user = _name ; 126 } 127 128 136 public int compareTo(Object o2) 137 { 138 ChanUser u2 = (ChanUser)(o2) ; 141 142 int ret = this.getRank() - u2.getRank() ; 144 if (ret < 0) 145 { 146 return -1 ; 148 } 149 else 150 { 151 if (ret > 0) 152 { 153 return 1 ; 155 } 156 else 157 { 158 return this.getNameSansRank().compareToIgnoreCase(u2.getNameSansRank()) ; 160 } 161 } 162 } 163 164 } 165 | Popular Tags |