1/* GENERATED SOURCE. DO NOT MODIFY. */
2/*
3 *******************************************************************************
4 * Copyright (C) 2003-2014, International Business Machines Corporation and    *
5 * others. All Rights Reserved.                                                *
6 *******************************************************************************
7 */
8package android.icu.text;
9
10import java.text.ParseException;
11
12/**
13 * Exception that signals an error has occurred while parsing the
14 * input to StringPrep or IDNA.
15 *
16 * @author Ram Viswanadha
17 */
18public class StringPrepParseException extends ParseException {
19    // Generated by serialver from JDK 1.4.1_01
20    static final long serialVersionUID = 7160264827701651255L;
21
22    /**
23     */
24    public static final int INVALID_CHAR_FOUND      = 0;
25    /**
26     */
27    public static final int ILLEGAL_CHAR_FOUND      = 1;
28    /**
29     */
30    public static final int PROHIBITED_ERROR        = 2;
31    /**
32     */
33    public static final int UNASSIGNED_ERROR        = 3;
34    /**
35     */
36    public static final int CHECK_BIDI_ERROR        = 4;
37    /**
38     */
39    public static final int STD3_ASCII_RULES_ERROR  = 5;
40    /**
41     */
42    public static final int ACE_PREFIX_ERROR        = 6;
43    /**
44     */
45    public static final int VERIFICATION_ERROR      = 7;
46    /**
47     */
48    public static final int LABEL_TOO_LONG_ERROR    = 8;
49    /**
50     */
51    public static final int BUFFER_OVERFLOW_ERROR   = 9;
52
53    /**
54     */
55    public static final int ZERO_LENGTH_LABEL   = 10;
56
57    /**
58     */
59    public static final int DOMAIN_NAME_TOO_LONG_ERROR   = 11;
60
61    /**
62     * Construct a ParseException object with the given message
63     * and error code
64     *
65     * @param message A string describing the type of error that occurred
66     * @param error   The error that has occurred
67     */
68    public StringPrepParseException(String message,int error){
69        super(message, -1);
70        this.error = error;
71        this.line = 0;
72    }
73
74    /**
75     * Construct a ParseException object with the given message and
76     * error code
77     *
78     * @param message A string describing the type of error that occurred
79     * @param error   The error that has occurred
80     * @param rules   The input rules string
81     * @param pos     The position of error in the rules string
82     */
83    public StringPrepParseException(String message,int error, String rules, int pos){
84        super(message, -1);
85        this.error = error;
86        setContext(rules,pos);
87        this.line = 0;
88    }
89    /**
90     * Construct  a ParseException object with the given message and error code
91     *
92     * @param message    A string describing the type of error that occurred
93     * @param error      The error that has occurred
94     * @param rules      The input rules string
95     * @param pos        The position of error in the rules string
96     * @param lineNumber The line number at which the error has occurred.
97     *                   If the parse engine is not using this field, it should set it to zero.  Otherwise
98     *                   it should be a positive integer. The default value of this field
99     *                   is -1. It will be set to 0 if the code populating this struct is not
100     *                   using line numbers.
101     */
102    public StringPrepParseException(String message, int error, String rules, int pos, int lineNumber){
103        super(message, -1);
104        this.error = error;
105        setContext(rules,pos);
106        this.line = lineNumber;
107    }
108    /**
109     * Compare this ParseException to another and evaluate if they are equal.
110     * The comparison works only on the type of error and does not compare
111     * the rules strings, if any, for equality.
112     *
113     * @param other The exception that this object should be compared to
114     * @return true if the objects are equal, false if unequal
115     */
116    public boolean equals(Object other){
117        if(!(other instanceof StringPrepParseException)){
118            return false;
119        }
120        return ((StringPrepParseException)other).error == this.error;
121
122    }
123
124    /**
125     * Mock implementation of hashCode(). This implementation always returns a constant
126     * value. When Java assertion is enabled, this method triggers an assertion failure.
127     * @deprecated This API is ICU internal only.
128     * @hide original deprecated declaration
129     * @hide draft / provisional / internal are hidden on Android
130     */
131    @Deprecated
132    public int hashCode() {
133        assert false : "hashCode not designed";
134        return 42;
135    }
136
137    /**
138     * Returns the position of error in the rules string
139     *
140     * @return String
141     */
142    public String toString(){
143        StringBuilder buf = new StringBuilder();
144        buf.append(super.getMessage());
145        buf.append(". line:  ");
146        buf.append(line);
147        buf.append(". preContext:  ");
148        buf.append(preContext);
149        buf.append(". postContext: ");
150        buf.append(postContext);
151        buf.append("\n");
152        return buf.toString();
153    }
154
155    private int error;
156
157    /**
158     * The line on which the error occurred.  If the parse engine
159     * is not using this field, it should set it to zero.  Otherwise
160     * it should be a positive integer. The default value of this field
161     * is -1. It will be set to 0 if the code populating this struct is not
162     * using line numbers.
163     */
164    private int line;
165
166
167    /**
168     * Textual context before the error.  Null-terminated.
169     * May be the empty string if not implemented by parser.
170     */
171    private StringBuffer preContext = new StringBuffer();
172
173    /**
174     * Textual context after the error.  Null-terminated.
175     * May be the empty string if not implemented by parser.
176     */
177    private StringBuffer postContext =  new StringBuffer();
178
179    private static final int PARSE_CONTEXT_LEN = 16;
180
181    private void setPreContext(String str, int pos){
182        setPreContext(str.toCharArray(),pos);
183    }
184
185    private void setPreContext(char[] str, int pos){
186        int start = (pos <= PARSE_CONTEXT_LEN)? 0 : (pos - (PARSE_CONTEXT_LEN-1));
187        int len = (start <= PARSE_CONTEXT_LEN)? start : PARSE_CONTEXT_LEN;
188        preContext.append(str,start,len);
189
190    }
191
192    private void setPostContext(String str, int pos){
193        setPostContext(str.toCharArray(),pos);
194    }
195
196    private void setPostContext(char[] str, int pos){
197        int start = pos;
198        int len  = str.length - start;
199        postContext.append(str,start,len);
200
201    }
202
203    private void setContext(String str,int pos){
204        setPreContext(str,pos);
205        setPostContext(str,pos);
206    }
207
208    /**
209     * Returns the error code of this exception.
210     * This method is only used for testing to verify the error.
211     * @return The error code
212     */
213    public int getError(){
214        return error;
215    }
216}
217