/** * The be-all end-all of KWIC, as the name implies. * * @author Alexander Schaap * */ public class MasterControl { KWICRecord kr; /** * Runs this KWIC program. * * @return KWIC output */ public String run() { // running the program kr.input.parse(kr.filename); kr.output.print(); return kr.output.getResult(); } /** * Prints human-readable configuration for testing/debug. * * @return configuration of modules used in this KWIC instance */ public String config() { return "StorageInterface implementation: " + kr.ls.getClass().getName() + '\n' + "StorageInterface implementation for shifts: " + kr.sls.getClass().getName() + '\n' + "StorageInterface implementation for sorted shifts: " + kr.ssls.getClass().getName() + '\n' + "InputInterface implementation: " + kr.input.getClass().getName() + '\n' + "WordCommandInterface implementation: " + kr.wc.getClass().getName() + '\n' + "CircularShifterInterface implementation: " + kr.shift.getClass().getName() + '\n' + "AlphabetizerInterface implementation: " + kr.alpha.getClass().getName() + '\n' + "OutputInterface implementation: " + kr.output.getClass().getName() + '\n' + "File: " + kr.filename; } /** * Creates instance of KWIC. * * @param kr * record containing all the modules for this KWIC instance */ public MasterControl(KWICRecord kr) { this.kr = kr; // link things together kr.ls.connect(kr.shift); kr.sls.connect(kr.alpha); //kr.ssls.connect(kr.output); kr.input.setWordCommand(kr.wc); kr.input.connect(kr.ls); kr.shift.connect(kr.sls); kr.alpha.connect(kr.ssls); kr.output.connect(kr.ssls); } /** * Will parse the first argument as a filename of a file to be parsed. * * @param args * either nothing or a number of things starting with a filename; * remaining args are ignored */ public static void main(String[] args) { StorageInterface>> ls = new StorageObservableLinkedList>>(); StorageInterface>>> sls = new StoragePassthrough>>>(); StorageInterface>>> ssls = new StoragePassthrough>>>(); //StorageInterface>>> ssls = sls; KWICRecord kr = new KWICRecord(ls, sls, ssls, new Input<>(), new WordCommandString(), new CircularShifter(), new AlphabetizerQuickSort<>(), new Output(), args[0]); MasterControl kwic = new MasterControl(kr); kwic.run(); } }