/** * Tries to extract the leaf of the {@link Directory} if the directory is a {@link FilterDirectory} and cast * it to the given target class or returns <code>null</code> if the leaf is not assignable to the target class. * If the given {@link Directory} is a concrete directory it will treated as a leaf and the above applies. */ public static <T extends Directory> T getLeaf(Directory dir, Class<T> targetClass) { return getLeaf(dir, targetClass, null); } /**
/** * Tries to extract the leaf of the {@link Directory} if the directory is a {@link FilterDirectory} and cast * it to the given target class or returns the given default value, if the leaf is not assignable to the target class. * If the given {@link Directory} is a concrete directory it will treated as a leaf and the above applies. */ public static <T extends Directory> T getLeaf(Directory dir, Class<T> targetClass, T defaultValue) { Directory d = dir; if (dir instanceof FilterDirectory) { d = getLeafDirectory((FilterDirectory) dir, targetClass); } if (d instanceof FileSwitchDirectory) { T leaf = getLeaf(((FileSwitchDirectory) d).getPrimaryDir(), targetClass); if (leaf == null) { d = getLeaf(((FileSwitchDirectory) d).getSecondaryDir(), targetClass, defaultValue); } else { d = leaf; } } if (d != null && targetClass.isAssignableFrom(d.getClass())) { return targetClass.cast(d); } else { return defaultValue; } }
/** * Tries to extract the leaf of the {@link Directory} if the directory is a {@link FilterDirectory} and cast * it to the given target class or returns the given default value, if the leaf is not assignable to the target class. * If the given {@link Directory} is a concrete directory it will treated as a leaf and the above applies. */ public static <T extends Directory> T getLeaf(Directory dir, Class<T> targetClass, T defaultValue) { Directory d = dir; if (dir instanceof FilterDirectory) { d = getLeafDirectory((FilterDirectory) dir, targetClass); } if (d instanceof FileSwitchDirectory) { T leaf = getLeaf(((FileSwitchDirectory) d).getPrimaryDir(), targetClass); if (leaf == null) { d = getLeaf(((FileSwitchDirectory) d).getSecondaryDir(), targetClass, defaultValue); } else { d = leaf; } } if (d != null && targetClass.isAssignableFrom(d.getClass())) { return targetClass.cast(d); } else { return defaultValue; } }
/** * Tries to extract the leaf of the {@link Directory} if the directory is a {@link FilterDirectory} and cast * it to the given target class or returns the given default value, if the leaf is not assignable to the target class. * If the given {@link Directory} is a concrete directory it will treated as a leaf and the above applies. */ public static <T extends Directory> T getLeaf(Directory dir, Class<T> targetClass, T defaultValue) { Directory d = dir; if (dir instanceof FilterDirectory) { d = getLeafDirectory((FilterDirectory) dir, targetClass); } if (d instanceof FileSwitchDirectory) { T leaf = getLeaf(((FileSwitchDirectory) d).getPrimaryDir(), targetClass); if (leaf == null) { d = getLeaf(((FileSwitchDirectory) d).getSecondaryDir(), targetClass, defaultValue); } else { d = leaf; } } if (d != null && targetClass.isAssignableFrom(d.getClass())) { return targetClass.cast(d); } else { return defaultValue; } }
/** * Tries to extract the leaf of the {@link Directory} if the directory is a {@link FilterDirectory} and cast * it to the given target class or returns <code>null</code> if the leaf is not assignable to the target class. * If the given {@link Directory} is a concrete directory it will treated as a leaf and the above applies. */ public static <T extends Directory> T getLeaf(Directory dir, Class<T> targetClass) { return getLeaf(dir, targetClass, null); } /**
/** * Tries to extract the leaf of the {@link Directory} if the directory is a {@link FilterDirectory} and cast * it to the given target class or returns <code>null</code> if the leaf is not assignable to the target class. * If the given {@link Directory} is a concrete directory it will treated as a leaf and the above applies. */ public static <T extends Directory> T getLeaf(Directory dir, Class<T> targetClass) { return getLeaf(dir, targetClass, null); } /**