java/sql-dk/src/info/globalcode/sql/dk/Functions.java
branchv_0
changeset 213 39d154429f7a
parent 181 80333d0ae763
child 218 8e38caf43ca8
equal deleted inserted replaced
212:d154d6012cbe 213:39d154429f7a
    22 import java.io.File;
    22 import java.io.File;
    23 import java.io.IOException;
    23 import java.io.IOException;
    24 import java.io.InputStream;
    24 import java.io.InputStream;
    25 import java.io.InputStreamReader;
    25 import java.io.InputStreamReader;
    26 import java.io.PrintWriter;
    26 import java.io.PrintWriter;
       
    27 import java.util.ArrayDeque;
       
    28 import java.util.ArrayList;
    27 import java.util.Arrays;
    29 import java.util.Arrays;
    28 import java.util.Collection;
    30 import java.util.Collection;
    29 import java.util.Collections;
    31 import java.util.Collections;
       
    32 import java.util.Deque;
       
    33 import java.util.List;
    30 import java.util.Map;
    34 import java.util.Map;
    31 
    35 
    32 /**
    36 /**
    33  *
    37  *
    34  * @author Ing. František Kučera (frantovo.cz)
    38  * @author Ing. František Kučera (frantovo.cz)
   162 				result.append('\n');
   166 				result.append('\n');
   163 			}
   167 			}
   164 			return result.toString();
   168 			return result.toString();
   165 		}
   169 		}
   166 	}
   170 	}
       
   171 
       
   172 	/**
       
   173 	 * @param <P> type of the last parent
       
   174 	 * @param <T> type of the examined class
       
   175 	 * @param type examined class
       
   176 	 * @param lastParent the last parent type to stop at
       
   177 	 * @return list of types starting with <code>type</code> and ending with <code>lastParent</code>
       
   178 	 */
       
   179 	public static <P, T extends P> List<Class<? extends P>> getClassHierarchy(Class<T> type, Class<P> lastParent) {
       
   180 		List<Class<? extends P>> hierarchy = new ArrayList<>();
       
   181 
       
   182 		for (Class current = type; current != null && lastParent.isAssignableFrom(current); current = current.getSuperclass()) {
       
   183 			hierarchy.add(current);
       
   184 		}
       
   185 
       
   186 		return hierarchy;
       
   187 	}
   167 }
   188 }