package recursive;

import java.io.File;

public class Recursive {

	public enum Test {
		FILE, FIBONACCI
	}

	public Recursive(Test t) {
		switch (t) {
		case FILE:
			runFileTest();
			break;
		case FIBONACCI:
			runFibonacciTest();
			break;
		}
	}

	private void runFibonacciTest() {
		System.err.println("Running recursive fibonacci test...");
		System.out.println(calcFibonacci(20));
	}

	public int calcFibonacci(int n) {
		if (n == 0)
			return 0;
		else if (n == 1)
			return 1;
		else
			return calcFibonacci(n - 1) + calcFibonacci(n - 2);
	}

	private void runFileTest() {
		System.err.println("Running recursive file test...");
		System.out.println(viewFiles("."));
	}

	private String viewFiles(String path) {
		String str = "\n";
		File folder = new File(path);
		File[] files = folder.listFiles();

		for (File f : files) {
			if (f.isDirectory())
				str += "\n" + f.getName() + "\t" + viewFiles(f.getAbsolutePath());
			else
				str += "\n\t" + f.getName();
		}
		return str;
	}
}
