1 16 package org.apache.axis.types; 17 18 import java.util.Arrays ; 19 import java.util.HashSet ; 20 import java.util.Set ; 21 import java.util.StringTokenizer ; 22 23 28 public class NMTokens extends NCName { 29 private NMToken[] tokens; 30 31 public NMTokens() { 32 super(); 33 } 34 38 public NMTokens (String stValue) throws IllegalArgumentException { 39 setValue(stValue); 40 } 41 42 public void setValue(String stValue) { 43 StringTokenizer tokenizer = new StringTokenizer (stValue); 44 int count = tokenizer.countTokens(); 45 tokens = new NMToken[count]; 46 for(int i=0;i<count;i++){ 47 tokens[i] = new NMToken(tokenizer.nextToken()); 48 } 49 } 50 51 public String toString() { 52 StringBuffer buf = new StringBuffer (); 53 for (int i = 0; i < tokens.length; i++) { 54 NMToken token = tokens[i]; 55 if (i > 0) buf.append(" "); 56 buf.append(token.toString()); 57 } 58 return buf.toString(); 59 } 60 61 69 public boolean equals(Object object) { 70 if (object == this) { 71 return true; } 73 if (object instanceof NMTokens) { 74 NMTokens that = (NMTokens)object; 75 if (this.tokens.length == that.tokens.length) { 76 Set ourSet = new HashSet (Arrays.asList(this.tokens)); 77 Set theirSet = new HashSet (Arrays.asList(that.tokens)); 78 return ourSet.equals(theirSet); 79 } else { 80 return false; 81 } 82 } else { 83 return false; 84 } 85 } 86 87 93 public int hashCode() { 94 int hash = 0; 95 for (int i = 0; i < tokens.length; i++) { 96 hash += tokens[i].hashCode(); 97 } 98 return hash; 99 } 100 } 101 | Popular Tags |