1/*
2 * Copyright 2003-2009 OFFIS, Henri Tremblay
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * 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 */
16package org.easymock.internal;
17
18import java.lang.reflect.Array;
19
20public final class ArgumentToString {
21
22    // ///CLOVER:OFF
23    private ArgumentToString() {
24    }
25    // ///CLOVER:ON
26
27    public static void appendArgument(Object value, StringBuffer buffer) {
28        if (value == null) {
29            buffer.append("null");
30        } else if (value instanceof String) {
31            buffer.append("\"");
32            buffer.append(value);
33            buffer.append("\"");
34        } else if (value instanceof Character) {
35            buffer.append("'");
36            buffer.append(value);
37            buffer.append("'");
38        } else if (value.getClass().isArray()) {
39            buffer.append("[");
40            for (int i = 0; i < Array.getLength(value); i++) {
41                if (i > 0) {
42                    buffer.append(", ");
43                }
44                appendArgument(Array.get(value, i), buffer);
45            }
46            buffer.append("]");
47        } else {
48            buffer.append(value);
49        }
50    }
51}
52