1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.css.parser;
  27 
  28 
  29 final class Token {
  30 
  31     final static int EOF = -1;
  32     final static int INVALID = 0;
  33     final static int SKIP = 1;
  34 
  35     final static Token EOF_TOKEN = new Token(EOF, "EOF");
  36     final static Token INVALID_TOKEN = new Token(INVALID, "INVALID");
  37     final static Token SKIP_TOKEN = new Token(SKIP, "SKIP");
  38 
  39     Token(int type, String text, int line, int offset) {
  40         this.type = type;
  41         this.text = text;
  42         this.line = line;
  43         this.offset = offset;        
  44     }
  45     
  46     Token(int type, String text) {
  47         this(type, text, -1, -1);
  48     }
  49 
  50     Token(int type) {
  51         this(type, null);
  52     }
  53 
  54     private Token() {
  55         this(0, "INVALID");
  56     }
  57 
  58     String getText() {
  59         return text;
  60     }
  61 
  62     int getType() {
  63         return type;
  64     }
  65 
  66     int getLine() {
  67         return line;
  68     }
  69 
  70     void setLine(int line) {
  71         this.line = line;
  72     }
  73 
  74     int getOffset() {
  75         return offset;
  76     }
  77 
  78     void setOffset(int offset) {
  79         this.offset = offset;
  80     }
  81 
  82     @Override public String toString() {
  83         final StringBuilder buf = new StringBuilder();
  84         buf.append('[').append(line).append(',').append(offset).append(']')
  85            .append(',').append(text).append(",<").append(type).append('>');
  86         return buf.toString();
  87     }
  88 
  89     @Override
  90     public boolean equals(Object obj) {
  91         if (this == obj) return true;
  92         if (obj == null ||
  93             getClass() != obj.getClass()) {
  94             return false;
  95         }
  96         final Token other = (Token) obj;
  97         if (this.type != other.type) {
  98             return false;
  99         }
 100         if ((this.text == null) ? (other.text != null) : !this.text.equals(other.text)) {
 101             return false;
 102         }
 103         return true;
 104     }
 105 
 106     @Override
 107     public int hashCode() {
 108         int hash = 7;
 109         hash = 67 * hash + this.type;
 110         hash = 67 * hash + (this.text != null ? this.text.hashCode() : 0);
 111         return hash;
 112     }
 113 
 114 
 115     private final String text;
 116     private int offset;
 117     private int line;
 118     private final int type;
 119 
 120 
 121 }