1/*
2 * Copyright 2001-2009 OFFIS, Tammo Freese
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.matchers;
17
18import java.util.Arrays;
19
20import org.easymock.internal.ArgumentToString;
21
22public class ArrayEquals extends Equals {
23
24    private static final long serialVersionUID = 1L;
25
26    public ArrayEquals(Object expected) {
27        super(expected);
28    }
29
30    @Override
31    public boolean matches(Object actual) {
32        Object expected = getExpected();
33        if (expected instanceof boolean[]
34                && (actual == null || actual instanceof boolean[])) {
35            return Arrays.equals((boolean[]) expected, (boolean[]) actual);
36        } else if (expected instanceof byte[]
37                && (actual == null || actual instanceof byte[])) {
38            return Arrays.equals((byte[]) expected, (byte[]) actual);
39        } else if (expected instanceof char[]
40                && (actual == null || actual instanceof char[])) {
41            return Arrays.equals((char[]) expected, (char[]) actual);
42        } else if (expected instanceof double[]
43                && (actual == null || actual instanceof double[])) {
44            return Arrays.equals((double[]) expected, (double[]) actual);
45        } else if (expected instanceof float[]
46                && (actual == null || actual instanceof float[])) {
47            return Arrays.equals((float[]) expected, (float[]) actual);
48        } else if (expected instanceof int[]
49                && (actual == null || actual instanceof int[])) {
50            return Arrays.equals((int[]) expected, (int[]) actual);
51        } else if (expected instanceof long[]
52                && (actual == null || actual instanceof long[])) {
53            return Arrays.equals((long[]) expected, (long[]) actual);
54        } else if (expected instanceof short[]
55                && (actual == null || actual instanceof short[])) {
56            return Arrays.equals((short[]) expected, (short[]) actual);
57        } else if (expected instanceof Object[]
58                && (actual == null || actual instanceof Object[])) {
59            return Arrays.equals((Object[]) expected, (Object[]) actual);
60        } else {
61            return super.matches(actual);
62        }
63    }
64
65    @Override
66    public void appendTo(StringBuffer buffer) {
67        ArgumentToString.appendArgument(getExpected(), buffer);
68    }
69}
70