1 /* 2 * Copyright (c) 2025 Shenzhen Kaihong Digital. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package grammar; 17 18 import com.google.gson.Gson; 19 import com.google.gson.GsonBuilder; 20 import utils.Constants; 21 22 /** 23 * <h3>类名:该类用于xxx</h3> 24 * description grammer base object 25 * 26 * @author Administrator 27 * date 2025-02-28 28 * @version 1.0 29 * @since 2025-02-28 30 */ 31 public class GBaseObject { 32 /** 33 * 解析未知代码 34 */ 35 protected int languageType = Constants.PARSE_UNKNOWN_LANGUAGE; 36 37 /** 38 * 关键字 39 */ 40 protected String token = ""; 41 42 /** 43 * 获取 language type 44 * 45 * @return 解析语言类型 46 */ getLanguageType()47 public int getLanguageType() { 48 return languageType; 49 } 50 51 /** 52 * 设置 language type 53 * 54 * @param languageType 解析语言类型 55 */ setLanguageType(int languageType)56 public void setLanguageType(int languageType) { 57 this.languageType = languageType; 58 } 59 60 /** 61 * 获取 token 62 * 63 * @return token 关键字 64 */ getToken()65 public String getToken() { 66 return token; 67 } 68 69 /** 70 * 设置 token 71 * 72 * @param token 关键字 73 */ setToken(String token)74 public void setToken(String token) { 75 this.token = token; 76 } 77 78 /** 79 * 转JSON字符串 80 * 81 * @return json 字符串 82 */ toJsonString()83 public String toJsonString() { 84 // 创建 Gson 实例并启用格式化 85 Gson gson = new GsonBuilder().setPrettyPrinting().create(); 86 87 return gson.toJson(this); 88 } 89 } 90