1 19 20 package org.netbeans.modules.xml.xdm.nodes; 21 22 26 public class Token { 27 28 Token(String val, TokenType type) { 29 value = val; 30 this.type = type; 31 } 32 33 public String getValue() { 34 return value; 35 } 36 37 public TokenType getType() { 38 return type; 39 } 40 41 @Override 42 public int hashCode() { 43 return getValue().hashCode(); 44 } 45 46 @Override 47 public boolean equals(Object obj) { 48 if (!(obj instanceof Token)) return false; 49 Token token = (Token)obj; 50 return((token.getValue().equals(getValue())) && 51 (token.getType().equals(getType()))); 52 } 53 54 @Override 55 public String toString() { 56 return getType() + " '" + value + "'"; 57 } 58 59 public static Token create(String value, TokenType type) { 60 Token t = null; 61 switch(type) { 62 case TOKEN_ATTR_EQUAL: { 63 t = EQUALS_TOKEN; 64 break; 65 } case TOKEN_ELEMENT_END_TAG: { 66 t = value.length() == 1 ? CLOSE_ELEMENT:SELF_CLOSE_ELEMENT; 67 break; 68 } 69 default: { 70 t = new Token(value,type); 71 } 72 } 73 assert t != null; 74 return t; 75 } 76 77 private static final Token EQUALS_TOKEN = 78 new Token("=", TokenType.TOKEN_ATTR_EQUAL); 80 private static final Token CLOSE_ELEMENT = 81 new Token(">", TokenType.TOKEN_ELEMENT_END_TAG); 83 private static final Token SELF_CLOSE_ELEMENT = 84 new Token("/>", TokenType.TOKEN_ELEMENT_END_TAG); 86 public static final Token CDATA_START = 87 new Token("<![CDATA[", TokenType.TOKEN_CDATA_VAL); 89 public static final Token CDATA_END = 90 new Token("]]>", TokenType.TOKEN_CDATA_VAL); 92 public static final Token COMMENT_START = 93 new Token("<!--", TokenType.TOKEN_CDATA_VAL); 95 public static final Token COMMENT_END = 96 new Token("-->", TokenType.TOKEN_CDATA_VAL); 98 private final String value; 99 private final TokenType type; 100 } 101 | Popular Tags |