1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements.  See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License.  You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
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
17package java.util;
18
19import java.io.Serializable;
20
21/**
22 * An {@code IllegalFormatConversionException} will be thrown when the parameter
23 * is incompatible with the corresponding format specifier.
24 *
25 * @see java.lang.RuntimeException
26 * @since Android 1.0
27 */
28public class IllegalFormatConversionException extends IllegalFormatException
29        implements Serializable {
30    private static final long serialVersionUID = 17000126L;
31
32    private char c;
33
34    private Class<?> arg;
35
36    /**
37     * Constructs a new {@code IllegalFormatConversionException} with the class
38     * of the 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     * Returns 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     * Returns the incompatible conversion.
64     *
65     * @return the incompatible conversion.
66     */
67    public char getConversion() {
68        return c;
69    }
70
71    /**
72     * Returns 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}
86