KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > Ostermiller > util > PropertiesToken


1 /*
2  * This file is part of UberProperties
3  * Copyright (C) 2002 Stephen Ostermiller
4  * http://ostermiller.org/contact.pl?regarding=Java+Utilities
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * See COPYING.TXT for details.
17  */

18 package com.Ostermiller.util;
19
20 /**
21  * A PropertiesToken is a token that is returned by a lexer that is lexing a Java
22  * Properties file. It has several attributes describing the token:
23  * The type of token, the text of the token, the line number on which it
24  * occurred, the number of characters into the input at which it started, and
25  * similarly, the number of characters into the input at which it ended. <br>
26  *
27  * @author Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities
28  * @since ostermillerutils 1.00.00
29  */

30 class PropertiesToken {
31
32     public final static int COMMENT = 0x0;
33     public final static int END_LINE_WHITE_SPACE = 0x1;
34     public final static int WHITE_SPACE = 0x2;
35     public final static int SEPARATOR = 0x3;
36     public final static int CONTINUE_LINE = 0x4;
37     public final static int NAME = 0x5;
38     public final static int VALUE = 0x6;
39
40     private int ID;
41     private String JavaDoc contents;
42
43     /**
44      * Create a new token.
45      * The constructor is typically called by the lexer
46      *
47      * @param ID the id number of the token
48      * @param contents A string representing the text of the token
49      *
50      * @since ostermillerutils 1.00.00
51      */

52     public PropertiesToken(int ID, String JavaDoc contents){
53         this.ID = ID;
54         this.contents = contents;
55     }
56
57     /**
58      * get the ID number of this token
59      *
60      * @return the id number of the token
61      *
62      * @since ostermillerutils 1.00.00
63      */

64     public int getID(){
65         return ID;
66     }
67
68     /**
69      * get the contents of this token
70      *
71      * @return A string representing the text of the token
72      *
73      * @since ostermillerutils 1.00.00
74      */

75     public String JavaDoc getContents(){
76         return (contents);
77     }
78
79     public String JavaDoc toString(){
80             String JavaDoc idString = "";
81             switch (ID){
82                 case COMMENT: idString = "COMMENT"; break;
83                 case END_LINE_WHITE_SPACE: idString = "END_LINE_WHITE_SPACE"; break;
84                 case WHITE_SPACE: idString = "WHITE_SPACE"; break;
85                 case SEPARATOR: idString = "SEPARATOR"; break;
86                 case CONTINUE_LINE: idString = "CONTINUE_LINE"; break;
87                 case NAME: idString = "NAME"; break;
88                 case VALUE: idString = "VALUE"; break;
89             }
90             idString = StringHelper.postpad(idString, 21);
91         return idString + '"' + contents + '"';
92     }
93 }
94
Popular Tags