Here you can find the source of getAllInterfaces(Class cls)
Gets a List
of all interfaces implemented by the given class and its superclasses.
The order is determined by looking through each interface in turn as declared in the source file and following its hierarchy up.
Parameter | Description |
---|---|
cls | the class to look up, may be <code>null</code> |
List
of interfaces in order, null
if null input
public static List getAllInterfaces(Class cls)
//package com.java2s; /*// w w w .j a v a 2 s.c om * Copyright (c) 2007-2016 AREasy Runtime * * This library, AREasy Runtime and API for BMC Remedy AR System, is free software ("Licensed Software"); * you can redistribute it and/or modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either version 2.1 of the License, * or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * including but not limited to, the implied warranty of MERCHANTABILITY, NONINFRINGEMENT, * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. */ import java.util.*; public class Main { /** * <p>Gets a <code>List</code> of all interfaces implemented by the given * class and its superclasses.</p> * <p/> * <p>The order is determined by looking through each interface in turn as * declared in the source file and following its hierarchy up. Then each * superclass is considered in the same way. Later duplicates are ignored, * so the order is maintained.</p> * * @param cls the class to look up, may be <code>null</code> * @return the <code>List</code> of interfaces in order, * <code>null</code> if null input */ public static List getAllInterfaces(Class cls) { if (cls == null) return null; List list = new ArrayList(); while (cls != null) { Class[] interfaces = cls.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (list.contains(interfaces[i]) == false) { list.add(interfaces[i]); } List superInterfaces = getAllInterfaces(interfaces[i]); for (Iterator it = superInterfaces.iterator(); it.hasNext();) { Class intface = (Class) it.next(); if (list.contains(intface) == false) { list.add(intface); } } } cls = cls.getSuperclass(); } return list; } }