01: /* Licensed to the Apache Software Foundation (ASF) under one or more
02: * contributor license agreements. See the NOTICE file distributed with
03: * this work for additional information regarding copyright ownership.
04: * The ASF licenses this file to You under the Apache License, Version 2.0
05: * (the "License"); you may not use this file except in compliance with
06: * the License. You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package java.util;
18:
19: import java.io.Serializable;
20:
21: /**
22: * The unchecked exception will be thrown out when the parameter is incompatible
23: * with the corresponding format specifier.
24: *
25: * @since 1.5
26: */
27: public class IllegalFormatConversionException extends
28: IllegalFormatException implements Serializable {
29:
30: private static final long serialVersionUID = 17000126L;
31:
32: private char c;
33:
34: private Class<?> arg;
35:
36: /**
37: * Constructs an IllegalFormatConversionException with the class of the
38: * mismatched conversion and corresponding parameter.
39: *
40: * @param c
41: * The class of the mismatched conversion.
42: * @param arg
43: * The corresponding parameter.
44: */
45: public IllegalFormatConversionException(char c, Class<?> arg) {
46: this .c = c;
47: if (arg == null) {
48: throw new NullPointerException();
49: }
50: this .arg = arg;
51: }
52:
53: /**
54: * Return the class of the mismatched parameter.
55: *
56: * @return The class of the mismatched parameter.
57: */
58: public Class<?> getArgumentClass() {
59: return arg;
60: }
61:
62: /**
63: * Return the incompatible conversion.
64: *
65: * @return The incompatible conversion.
66: */
67: public char getConversion() {
68: return c;
69: }
70:
71: /**
72: * Return the message string of the IllegalFormatConversionException.
73: *
74: * @return The message string of the IllegalFormatConversionException.
75: */
76: @Override
77: public String getMessage() {
78: StringBuilder buffer = new StringBuilder();
79: buffer.append(c);
80: buffer.append(" is incompatible with ");
81: buffer.append(arg.getName());
82: return buffer.toString();
83: }
84:
85: }
|