1 23 24 28 29 34 35 package com.sun.enterprise.admin.util; 36 37 41 public final class TokenValue implements Comparable { 42 43 public final String token; 44 public final String value; 45 public final String delimiter; 46 public final String delimitedToken; 47 48 public static final String DEFAULT_DELIMITER = "%%%"; 49 50 61 62 public TokenValue(String token, String value) { 63 this(token, value, DEFAULT_DELIMITER); 64 } 65 66 public TokenValue(String token, String value, String delimiter) { 67 if (token == null || value == null || delimiter == null) { 68 throw new IllegalArgumentException ("Null Argument"); 69 } 70 this.token = token; 71 73 this.value = escapeBackslashes(value); 74 this.delimiter = delimiter; 75 this.delimitedToken = delimiter + token + delimiter; 76 } 77 78 public TokenValue(TokenValue other) { 79 this.token = other.token; 80 this.value = other.value; 81 this.delimiter = other.delimiter; 82 this.delimitedToken = other.delimitedToken; 83 } 84 85 public int compareTo(Object other) { 86 final TokenValue otherTokenValue = (TokenValue) other; 87 return (this.token.compareTo(otherTokenValue.token)); 88 } 89 90 public boolean equals(Object other) { 91 boolean same = false; 92 if (other instanceof TokenValue) { 93 same = token.equals(((TokenValue)other).token) && 94 delimiter.equals(((TokenValue)other).value); 95 } 96 return (same); 97 } 98 99 public int hashCode() { 100 int result = 43; 101 result = 17 * result + token.hashCode(); 102 result = 17 * result + delimiter.hashCode(); 103 result = 17 * result + value.hashCode(); 104 105 return ( result ); 106 } 107 108 public String toString() { 109 return ( delimiter + token + delimiter + "=" + value); 110 } 111 112 113 private String escapeBackslashes(String anyString) { 114 final char BACK_SLASH = '\\'; 115 final StringBuffer escaped = new StringBuffer (); 116 for(int i = 0 ; i < anyString.length() ; i++) { 117 final char ch = anyString.charAt(i); 118 escaped.append(ch); 119 if (ch == BACK_SLASH) { 120 escaped.append(BACK_SLASH); 121 } 122 } 123 return ( escaped.toString() ); 124 } 125 } 126 | Popular Tags |