1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package org.apache.commons.math.exception.util;
18
19import java.util.List;
20import java.util.ArrayList;
21
22/**
23 * Utility class for transforming the list of arguments passed to
24 * constructors of exceptions.
25 *
26 * @version $Revision$ $Date$
27 * @since 2.2
28 */
29public class ArgUtils {
30    /**
31     * Private constructor
32     */
33    private ArgUtils() {
34    }
35
36    /**
37     * Transform a multidimensional array into a one-dimensional list.
38     *
39     * @param array Array (possibly multidimensional).
40     * @return a list of all the {@code Object} instances contained in
41     * {@code array}.
42     */
43    public static Object[] flatten(Object[] array) {
44        final List<Object> list = new ArrayList<Object>();
45        if (array != null) {
46            for (Object o : array) {
47                if (o instanceof Object[]) {
48                    for (Object oR : flatten((Object[]) o)) {
49                        list.add(oR);
50                    }
51                } else {
52                    list.add(o);
53                }
54            }
55        }
56        return list.toArray();
57    }
58}
59