/QingTingFanBianYi/src/com/alibaba/fastjson/JSONObject.java

https://gitlab.com/qt-prometheus/qt-prometheus · Java · 360 lines · 308 code · 48 blank · 4 comment · 53 complexity · 53cfaae99ea0e3751a7e7bf5f86b3e2c MD5 · raw file

  1. package com.alibaba.fastjson;
  2. import com.alibaba.fastjson.annotation.JSONField;
  3. import com.alibaba.fastjson.parser.ParserConfig;
  4. import com.alibaba.fastjson.util.TypeUtils;
  5. import java.io.Serializable;
  6. import java.lang.reflect.InvocationHandler;
  7. import java.lang.reflect.Method;
  8. import java.math.BigDecimal;
  9. import java.math.BigInteger;
  10. import java.sql.Timestamp;
  11. import java.util.Collection;
  12. import java.util.HashMap;
  13. import java.util.LinkedHashMap;
  14. import java.util.Map;
  15. import java.util.Map.Entry;
  16. import java.util.Set;
  17. public class JSONObject extends JSON
  18. implements Map<String, Object>, JSONAware, Cloneable, Serializable, InvocationHandler
  19. {
  20. private static final int DEFAULT_INITIAL_CAPACITY = 16;
  21. private static final long serialVersionUID = 1L;
  22. private final Map<String, Object> map;
  23. public JSONObject()
  24. {
  25. this(16, false);
  26. }
  27. public JSONObject(int paramInt)
  28. {
  29. this(paramInt, false);
  30. }
  31. public JSONObject(int paramInt, boolean paramBoolean)
  32. {
  33. if (paramBoolean)
  34. {
  35. this.map = new LinkedHashMap(paramInt);
  36. return;
  37. }
  38. this.map = new HashMap(paramInt);
  39. }
  40. public JSONObject(Map<String, Object> paramMap)
  41. {
  42. this.map = paramMap;
  43. }
  44. public JSONObject(boolean paramBoolean)
  45. {
  46. this(16, paramBoolean);
  47. }
  48. public void clear()
  49. {
  50. this.map.clear();
  51. }
  52. public Object clone()
  53. {
  54. return new JSONObject(new HashMap(this.map));
  55. }
  56. public boolean containsKey(Object paramObject)
  57. {
  58. return this.map.containsKey(paramObject);
  59. }
  60. public boolean containsValue(Object paramObject)
  61. {
  62. return this.map.containsValue(paramObject);
  63. }
  64. public Set<Map.Entry<String, Object>> entrySet()
  65. {
  66. return this.map.entrySet();
  67. }
  68. public boolean equals(Object paramObject)
  69. {
  70. return this.map.equals(paramObject);
  71. }
  72. public Object get(Object paramObject)
  73. {
  74. return this.map.get(paramObject);
  75. }
  76. public BigDecimal getBigDecimal(String paramString)
  77. {
  78. return TypeUtils.castToBigDecimal(get(paramString));
  79. }
  80. public BigInteger getBigInteger(String paramString)
  81. {
  82. return TypeUtils.castToBigInteger(get(paramString));
  83. }
  84. public Boolean getBoolean(String paramString)
  85. {
  86. paramString = get(paramString);
  87. if (paramString == null)
  88. return null;
  89. return TypeUtils.castToBoolean(paramString);
  90. }
  91. public boolean getBooleanValue(String paramString)
  92. {
  93. paramString = get(paramString);
  94. if (paramString == null)
  95. return false;
  96. return TypeUtils.castToBoolean(paramString).booleanValue();
  97. }
  98. public Byte getByte(String paramString)
  99. {
  100. return TypeUtils.castToByte(get(paramString));
  101. }
  102. public byte getByteValue(String paramString)
  103. {
  104. paramString = get(paramString);
  105. if (paramString == null)
  106. return 0;
  107. return TypeUtils.castToByte(paramString).byteValue();
  108. }
  109. public byte[] getBytes(String paramString)
  110. {
  111. paramString = get(paramString);
  112. if (paramString == null)
  113. return null;
  114. return TypeUtils.castToBytes(paramString);
  115. }
  116. public java.util.Date getDate(String paramString)
  117. {
  118. return TypeUtils.castToDate(get(paramString));
  119. }
  120. public Double getDouble(String paramString)
  121. {
  122. return TypeUtils.castToDouble(get(paramString));
  123. }
  124. public double getDoubleValue(String paramString)
  125. {
  126. paramString = get(paramString);
  127. if (paramString == null)
  128. return 0.0D;
  129. return TypeUtils.castToDouble(paramString).doubleValue();
  130. }
  131. public Float getFloat(String paramString)
  132. {
  133. return TypeUtils.castToFloat(get(paramString));
  134. }
  135. public float getFloatValue(String paramString)
  136. {
  137. paramString = get(paramString);
  138. if (paramString == null)
  139. return 0.0F;
  140. return TypeUtils.castToFloat(paramString).floatValue();
  141. }
  142. public int getIntValue(String paramString)
  143. {
  144. paramString = get(paramString);
  145. if (paramString == null)
  146. return 0;
  147. return TypeUtils.castToInt(paramString).intValue();
  148. }
  149. public Integer getInteger(String paramString)
  150. {
  151. return TypeUtils.castToInt(get(paramString));
  152. }
  153. public JSONArray getJSONArray(String paramString)
  154. {
  155. paramString = this.map.get(paramString);
  156. if ((paramString instanceof JSONArray))
  157. return (JSONArray)paramString;
  158. return (JSONArray)toJSON(paramString);
  159. }
  160. public JSONObject getJSONObject(String paramString)
  161. {
  162. paramString = this.map.get(paramString);
  163. if ((paramString instanceof JSONObject))
  164. return (JSONObject)paramString;
  165. return (JSONObject)toJSON(paramString);
  166. }
  167. public Long getLong(String paramString)
  168. {
  169. return TypeUtils.castToLong(get(paramString));
  170. }
  171. public long getLongValue(String paramString)
  172. {
  173. paramString = get(paramString);
  174. if (paramString == null)
  175. return 0L;
  176. return TypeUtils.castToLong(paramString).longValue();
  177. }
  178. public <T> T getObject(String paramString, Class<T> paramClass)
  179. {
  180. return TypeUtils.castToJavaBean(this.map.get(paramString), paramClass);
  181. }
  182. public Short getShort(String paramString)
  183. {
  184. return TypeUtils.castToShort(get(paramString));
  185. }
  186. public short getShortValue(String paramString)
  187. {
  188. paramString = get(paramString);
  189. if (paramString == null)
  190. return 0;
  191. return TypeUtils.castToShort(paramString).shortValue();
  192. }
  193. public java.sql.Date getSqlDate(String paramString)
  194. {
  195. return TypeUtils.castToSqlDate(get(paramString));
  196. }
  197. public String getString(String paramString)
  198. {
  199. paramString = get(paramString);
  200. if (paramString == null)
  201. return null;
  202. return paramString.toString();
  203. }
  204. public Timestamp getTimestamp(String paramString)
  205. {
  206. return TypeUtils.castToTimestamp(get(paramString));
  207. }
  208. public int hashCode()
  209. {
  210. return this.map.hashCode();
  211. }
  212. public Object invoke(Object paramObject, Method paramMethod, Object[] paramArrayOfObject)
  213. throws Throwable
  214. {
  215. paramObject = paramMethod.getParameterTypes();
  216. Object localObject;
  217. if (paramObject.length == 1)
  218. {
  219. if (paramMethod.getReturnType() != Void.TYPE)
  220. throw new JSONException("illegal setter");
  221. localObject = null;
  222. JSONField localJSONField = (JSONField)paramMethod.getAnnotation(JSONField.class);
  223. paramObject = localObject;
  224. if (localJSONField != null)
  225. {
  226. paramObject = localObject;
  227. if (localJSONField.name().length() != 0)
  228. paramObject = localJSONField.name();
  229. }
  230. localObject = paramObject;
  231. if (paramObject == null)
  232. {
  233. paramObject = paramMethod.getName();
  234. if (!paramObject.startsWith("set"))
  235. throw new JSONException("illegal setter");
  236. paramObject = paramObject.substring(3);
  237. if (paramObject.length() == 0)
  238. throw new JSONException("illegal setter");
  239. localObject = Character.toLowerCase(paramObject.charAt(0)) + paramObject.substring(1);
  240. }
  241. this.map.put(localObject, paramArrayOfObject[0]);
  242. return null;
  243. }
  244. if (paramObject.length == 0)
  245. {
  246. if (paramMethod.getReturnType() == Void.TYPE)
  247. throw new JSONException("illegal getter");
  248. paramArrayOfObject = null;
  249. localObject = (JSONField)paramMethod.getAnnotation(JSONField.class);
  250. paramObject = paramArrayOfObject;
  251. if (localObject != null)
  252. {
  253. paramObject = paramArrayOfObject;
  254. if (((JSONField)localObject).name().length() != 0)
  255. paramObject = ((JSONField)localObject).name();
  256. }
  257. paramArrayOfObject = paramObject;
  258. if (paramObject == null)
  259. {
  260. paramObject = paramMethod.getName();
  261. if (!paramObject.startsWith("get"))
  262. break label350;
  263. paramObject = paramObject.substring(3);
  264. if (paramObject.length() == 0)
  265. throw new JSONException("illegal getter");
  266. }
  267. for (paramArrayOfObject = Character.toLowerCase(paramObject.charAt(0)) + paramObject.substring(1); ; paramArrayOfObject = Character.toLowerCase(paramObject.charAt(0)) + paramObject.substring(1))
  268. {
  269. return TypeUtils.cast(this.map.get(paramArrayOfObject), paramMethod.getGenericReturnType(), ParserConfig.getGlobalInstance());
  270. label350: if (!paramObject.startsWith("is"))
  271. break;
  272. paramObject = paramObject.substring(2);
  273. if (paramObject.length() == 0)
  274. throw new JSONException("illegal getter");
  275. }
  276. throw new JSONException("illegal getter");
  277. }
  278. throw new UnsupportedOperationException(paramMethod.toGenericString());
  279. }
  280. public boolean isEmpty()
  281. {
  282. return this.map.isEmpty();
  283. }
  284. public Set<String> keySet()
  285. {
  286. return this.map.keySet();
  287. }
  288. public Object put(String paramString, Object paramObject)
  289. {
  290. return this.map.put(paramString, paramObject);
  291. }
  292. public void putAll(Map<? extends String, ? extends Object> paramMap)
  293. {
  294. this.map.putAll(paramMap);
  295. }
  296. public Object remove(Object paramObject)
  297. {
  298. return this.map.remove(paramObject);
  299. }
  300. public int size()
  301. {
  302. return this.map.size();
  303. }
  304. public Collection<Object> values()
  305. {
  306. return this.map.values();
  307. }
  308. }
  309. /* Location: C:\Users\User\dex2jar-2.0\dex\qting\classes-dex2jar.jar
  310. * Qualified Name: com.alibaba.fastjson.JSONObject
  311. * JD-Core Version: 0.6.2
  312. */