Path: blob/master/src/jdk.jcmd/share/classes/sun/tools/jstat/Token.java
41159 views
/*1* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.tools.jstat;2627import java.io.StreamTokenizer;2829/**30* A class for encapsulating tokens returned from StreamTokenizer primarily31* for output formatting purposes.32*33* @author Brian Doherty34* @since 1.535*/36public class Token {37public String sval;38public double nval;39public int ttype;4041public Token(int ttype, String sval, double nval) {42this.ttype = ttype;43this.sval = sval;44this.nval = nval;45}4647public Token(int ttype, String sval) {48this(ttype, sval, 0);49}5051public Token(int ttype) {52this(ttype, null, 0);53}5455public String toMessage() {56switch(ttype) {57case StreamTokenizer.TT_EOL:58return "\"EOL\"";59case StreamTokenizer.TT_EOF:60return "\"EOF\"";61case StreamTokenizer.TT_NUMBER:62return "NUMBER";63case StreamTokenizer.TT_WORD:64if (sval == null) {65return "IDENTIFIER";66} else {67return "IDENTIFIER " + sval;68}69default:70if (ttype == (int)'"') {71String msg = "QUOTED STRING";72if (sval != null)73msg = msg + " \"" + sval + "\"";74return msg;75} else {76return "CHARACTER \'" + (char)ttype + "\'";77}78}79}8081public String toString() {82StringBuilder sb = new StringBuilder();83switch(ttype) {84case StreamTokenizer.TT_EOL:85sb.append("ttype=TT_EOL");86break;87case StreamTokenizer.TT_EOF:88sb.append("ttype=TT_EOF");89break;90case StreamTokenizer.TT_NUMBER:91sb.append("ttype=TT_NUM,").append("nval="+nval);92break;93case StreamTokenizer.TT_WORD:94if (sval == null) {95sb.append("ttype=TT_WORD:IDENTIFIER");96} else {97sb.append("ttype=TT_WORD:").append("sval="+sval);98}99break;100default:101if (ttype == (int)'"') {102sb.append("ttype=TT_STRING:").append("sval="+sval);103} else {104sb.append("ttype=TT_CHAR:").append((char)ttype);105}106break;107}108return sb.toString();109}110}111112113