JAL-3438 spotless for 2.11.2.0
[jalview.git] / src / org / json / simple / parser / ParseException.java
1 package org.json.simple.parser;
2
3 /**
4  * ParseException explains why and where the error occurs in source JSON text.
5  * 
6  * @author FangYidong<fangyidong@yahoo.com.cn>
7  *
8  */
9 public class ParseException extends Exception
10 {
11   private static final long serialVersionUID = -7880698968187728547L;
12
13   public static final int ERROR_UNEXPECTED_CHAR = 0;
14
15   public static final int ERROR_UNEXPECTED_TOKEN = 1;
16
17   public static final int ERROR_UNEXPECTED_EXCEPTION = 2;
18
19   private int errorType;
20
21   private Object unexpectedObject;
22
23   private int position;
24
25   public ParseException(int errorType)
26   {
27     this(-1, errorType, null);
28   }
29
30   public ParseException(int errorType, Object unexpectedObject)
31   {
32     this(-1, errorType, unexpectedObject);
33   }
34
35   public ParseException(int position, int errorType,
36           Object unexpectedObject)
37   {
38     this.position = position;
39     this.errorType = errorType;
40     this.unexpectedObject = unexpectedObject;
41   }
42
43   public int getErrorType()
44   {
45     return errorType;
46   }
47
48   public void setErrorType(int errorType)
49   {
50     this.errorType = errorType;
51   }
52
53   /**
54    * @see org.json.simple.parser.JSONParser#getPosition()
55    * 
56    * @return The character position (starting with 0) of the input where the
57    *         error occurs.
58    */
59   public int getPosition()
60   {
61     return position;
62   }
63
64   public void setPosition(int position)
65   {
66     this.position = position;
67   }
68
69   /**
70    * @see org.json.simple.parser.Yytoken
71    * 
72    * @return One of the following base on the value of errorType:
73    *         ERROR_UNEXPECTED_CHAR java.lang.Character ERROR_UNEXPECTED_TOKEN
74    *         org.json.simple.parser.Yytoken ERROR_UNEXPECTED_EXCEPTION
75    *         java.lang.Exception
76    */
77   public Object getUnexpectedObject()
78   {
79     return unexpectedObject;
80   }
81
82   public void setUnexpectedObject(Object unexpectedObject)
83   {
84     this.unexpectedObject = unexpectedObject;
85   }
86
87   public String getMessage()
88   {
89     StringBuffer sb = new StringBuffer();
90
91     switch (errorType)
92     {
93     case ERROR_UNEXPECTED_CHAR:
94       sb.append("Unexpected character (").append(unexpectedObject)
95               .append(") at position ").append(position).append(".");
96       break;
97     case ERROR_UNEXPECTED_TOKEN:
98       sb.append("Unexpected token ").append(unexpectedObject)
99               .append(" at position ").append(position).append(".");
100       break;
101     case ERROR_UNEXPECTED_EXCEPTION:
102       sb.append("Unexpected exception at position ").append(position)
103               .append(": ").append(unexpectedObject);
104       break;
105     default:
106       sb.append("Unkown error at position ").append(position).append(".");
107       break;
108     }
109     return sb.toString();
110   }
111 }