001: /*
002: * Copyright (C) 2002-2007 Stephen Ostermiller
003: * http://ostermiller.org/contact.pl?regarding=Java+Utilities
004: *
005: * This program is free software; you can redistribute it and/or modify
006: * it under the terms of the GNU General Public License as published by
007: * the Free Software Foundation; either version 2 of the License, or
008: * (at your option) any later version.
009: *
010: * This program is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU General Public License for more details.
014: *
015: * See COPYING.TXT for details.
016: */
017: package com.Ostermiller.util;
018:
019: /**
020: * A PropertiesToken is a token that is returned by a lexer that is lexing a Java
021: * Properties file. It has several attributes describing the token:
022: * The type of token, the text of the token, the line number on which it
023: * occurred, the number of characters into the input at which it started, and
024: * similarly, the number of characters into the input at which it ended. <br>
025: *
026: * @author Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities
027: * @since ostermillerutils 1.00.00
028: */
029: class PropertiesToken {
030:
031: /** comment -- 0 */
032: public final static int COMMENT = 0x0;
033:
034: /** end of line white space -- 1 */
035: public final static int END_LINE_WHITE_SPACE = 0x1;
036:
037: /** white space -- 2 */
038: public final static int WHITE_SPACE = 0x2;
039:
040: /** separator -- 3 */
041: public final static int SEPARATOR = 0x3;
042:
043: /** continue line -- 4 */
044: public final static int CONTINUE_LINE = 0x4;
045:
046: /** name -- 5 */
047: public final static int NAME = 0x5;
048:
049: /** value -- 6 */
050: public final static int VALUE = 0x6;
051:
052: private int ID;
053: private String contents;
054:
055: /**
056: * Create a new token.
057: * The constructor is typically called by the lexer
058: *
059: * @param ID the id number of the token
060: * @param contents A string representing the text of the token
061: *
062: * @since ostermillerutils 1.00.00
063: */
064: public PropertiesToken(int ID, String contents) {
065: this .ID = ID;
066: this .contents = contents;
067: }
068:
069: /**
070: * get the ID number of this token
071: *
072: * @return the id number of the token
073: *
074: * @since ostermillerutils 1.00.00
075: */
076: public int getID() {
077: return ID;
078: }
079:
080: /**
081: * get the contents of this token
082: *
083: * @return A string representing the text of the token
084: *
085: * @since ostermillerutils 1.00.00
086: */
087: public String getContents() {
088: return (contents);
089: }
090:
091: /**
092: * String representation appropriate for debugging.
093: *
094: * @return String representation
095: *
096: * @since ostermillerutils 1.00.00
097: */
098: @Override
099: public String toString() {
100: String idString = "";
101: switch (ID) {
102: case COMMENT:
103: idString = "COMMENT";
104: break;
105: case END_LINE_WHITE_SPACE:
106: idString = "END_LINE_WHITE_SPACE";
107: break;
108: case WHITE_SPACE:
109: idString = "WHITE_SPACE";
110: break;
111: case SEPARATOR:
112: idString = "SEPARATOR";
113: break;
114: case CONTINUE_LINE:
115: idString = "CONTINUE_LINE";
116: break;
117: case NAME:
118: idString = "NAME";
119: break;
120: case VALUE:
121: idString = "VALUE";
122: break;
123: }
124: idString = StringHelper.postpad(idString, 21);
125: return idString + '"' + contents + '"';
126: }
127: }
|