/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */
package org.apache.bval.jsr303.util;

import java.security.AccessController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Common operations on classes that do not require an {@link AccessController}.
 * 
 * @author Carlos Vara
 */
public class ClassHelper {

    private ClassHelper() {
        // No instances please
    }
    
    /**
     * Fill the list with the full class/interface hierarchy of the given class.
     * List is ordered from the most to less specific.
     * 
     * @param allClasses
     *            The current list of classes in the hierarchy.
     * @param clazz
     *            The current class, root of the hierarchy to traverse.
     */
    static public void fillFullClassHierarchyAsList(List<Class<?>> allClasses, Class<?> clazz) {
        if ( clazz == null || clazz == Object.class ) {
            return;
        }
        if ( allClasses.contains(clazz) ) {
            return;
        }
        allClasses.add(clazz);
        List<Class<?>> subClasses = new ArrayList(Arrays.asList(clazz.getInterfaces()));
        subClasses.add(0, clazz.getSuperclass());
        for ( Class<?> subClass : subClasses ) {
            fillFullClassHierarchyAsList(allClasses, subClass);
        }        
    }
    
}

@@ -1166,20 +1166,16 @@
 e%0A    %7D%0A
-    
 %0A    /**
@@ -1617,17 +1617,16 @@
     if (
- 
 clazz ==
@@ -1655,17 +1655,16 @@
 ct.class
- 
 ) %7B%0A    
@@ -1701,17 +1701,16 @@
     if (
- 
 allClass
@@ -1727,17 +1727,16 @@
 s(clazz)
- 
 ) %7B%0A    
@@ -1841,16 +1841,26 @@
 rrayList
+%3CClass%3C?%3E%3E
 (Arrays.
@@ -1954,17 +1954,16 @@
    for (
- 
 Class%3C?%3E
@@ -1984,17 +1984,16 @@
 bClasses
- 
 ) %7B%0A    
@@ -2065,26 +2065,14 @@
    %7D
-        
 %0A    %7D%0A
-    
 %0A%7D%0A

format; remove a warning