javadocs in TournamentDecorator.java
This commit is contained in:
		
							parent
							
								
									7f2776d49d
								
							
						
					
					
						commit
						6f043e7925
					
				| 
						 | 
					@ -9,6 +9,7 @@ import java.util.List;
 | 
				
			||||||
import java.util.concurrent.ExecutorService;
 | 
					import java.util.concurrent.ExecutorService;
 | 
				
			||||||
import java.util.concurrent.Executors;
 | 
					import java.util.concurrent.Executors;
 | 
				
			||||||
import java.util.concurrent.TimeUnit;
 | 
					import java.util.concurrent.TimeUnit;
 | 
				
			||||||
 | 
					import java.util.logging.Logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class TournamentDecorator implements IsObservable{
 | 
					public class TournamentDecorator implements IsObservable{
 | 
				
			||||||
| 
						 | 
					@ -18,48 +19,84 @@ public class TournamentDecorator implements IsObservable{
 | 
				
			||||||
    private ExecutorService executorService;
 | 
					    private ExecutorService executorService;
 | 
				
			||||||
    private FactoryDecorator factoryDecorator;
 | 
					    private FactoryDecorator factoryDecorator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static final Logger logger = Logger.getLogger(TournamentDecorator.class.getCanonicalName());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Constructor to initialize TournamentDecorator
 | 
				
			||||||
 | 
					     * adds a listener to save the tournament every time if something is changed.
 | 
				
			||||||
 | 
					     * creates a executer service to do the saving process in separate thread for better performance.
 | 
				
			||||||
 | 
					     * @param fileIO
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    public TournamentDecorator(FileIO fileIO){
 | 
					    public TournamentDecorator(FileIO fileIO){
 | 
				
			||||||
 | 
					        logger.fine("initializing TournamentDecorator");
 | 
				
			||||||
        setFileIO(fileIO);
 | 
					        setFileIO(fileIO);
 | 
				
			||||||
        addListener(new IsObserver() {
 | 
					        addListener(new IsObserver() {
 | 
				
			||||||
            @Override
 | 
					            @Override
 | 
				
			||||||
            public void update() {
 | 
					            public void update() {
 | 
				
			||||||
                if(tournament != null){
 | 
					                if(tournament != null){
 | 
				
			||||||
 | 
					 | 
				
			||||||
                    saveTournament();
 | 
					                    saveTournament();
 | 
				
			||||||
 | 
					                    logger.fine("listener to save tournament was added");
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        executorService = Executors.newFixedThreadPool(1);
 | 
					        executorService = Executors.newFixedThreadPool(1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Setter method of FactoryDecorator
 | 
				
			||||||
 | 
					     * @param factoryDecorator the factory decorator to load different views.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    public void setFactoryDecorator(FactoryDecorator factoryDecorator) {
 | 
					    public void setFactoryDecorator(FactoryDecorator factoryDecorator) {
 | 
				
			||||||
        this.factoryDecorator = factoryDecorator;
 | 
					        this.factoryDecorator = factoryDecorator;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Setter Method of FileIO
 | 
				
			||||||
 | 
					     * @param fileIO the fileIO object to read and save to files.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    public void setFileIO(FileIO fileIO) {
 | 
					    public void setFileIO(FileIO fileIO) {
 | 
				
			||||||
        this.fileIO = fileIO;
 | 
					        this.fileIO = fileIO;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * setter Method of Tournament
 | 
				
			||||||
 | 
					     * @param tournament the new Tournament Object which was selected by user.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    public void setTournament(Tournament tournament) {
 | 
					    public void setTournament(Tournament tournament) {
 | 
				
			||||||
        this.tournament = tournament;
 | 
					        this.tournament = tournament;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * getter Method of Tournament
 | 
				
			||||||
 | 
					     * @return the actual tournament which is open.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    public Tournament getTournament() {
 | 
					    public Tournament getTournament() {
 | 
				
			||||||
        return tournament;
 | 
					        return tournament;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Method to add a listener in list.
 | 
				
			||||||
 | 
					     * @param observer the observer object which should be informed.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void addListener(IsObserver observer) {
 | 
					    public void addListener(IsObserver observer) {
 | 
				
			||||||
        listener.add(observer);
 | 
					        listener.add(observer);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Method to remove a listener from list.
 | 
				
			||||||
 | 
					     * @param observer the object to remove.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void removeListener(IsObserver observer) {
 | 
					    public void removeListener(IsObserver observer) {
 | 
				
			||||||
        listener.remove(observer);
 | 
					        listener.remove(observer);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Method to save the actual tournament to files.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    public void saveTournament(){
 | 
					    public void saveTournament(){
 | 
				
			||||||
 | 
					        logger.fine("Saving Tournament to File.");
 | 
				
			||||||
        executorService.execute(new saveTask());
 | 
					        executorService.execute(new saveTask());
 | 
				
			||||||
        factoryDecorator.clearMessage(false);
 | 
					        factoryDecorator.clearMessage(false);
 | 
				
			||||||
        String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("save");
 | 
					        String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("save");
 | 
				
			||||||
| 
						 | 
					@ -67,40 +104,49 @@ public class TournamentDecorator implements IsObservable{
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Method to create a new Tournament. It checks if the name is valid, creates a new instance of Tournament and calls
 | 
				
			||||||
 | 
					     * FileIO to save the new Tournament.
 | 
				
			||||||
 | 
					     * @param name The name which was entered by the user.
 | 
				
			||||||
 | 
					     * @param type The type of Tournament
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    public void createTournament(String name, Tournament.Type type){
 | 
					    public void createTournament(String name, Tournament.Type type){
 | 
				
			||||||
 | 
					 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            if(fileIO.tournamentExists(name)){
 | 
					            if(fileIO.tournamentExists(name)){
 | 
				
			||||||
                //TODO:Logger
 | 
					                logger.warning("a tournament with name " + name + "exists already.");
 | 
				
			||||||
                String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("tournamentExists");
 | 
					                String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("tournamentExists");
 | 
				
			||||||
                factoryDecorator.printMessageToFooter(msg, true);
 | 
					                factoryDecorator.printMessageToFooter(msg, true);
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Tournament tournament = new Tournament(name, type);
 | 
					            Tournament tournament = new Tournament(name, type);
 | 
				
			||||||
 | 
					            logger.fine("new tournament instance was created.");
 | 
				
			||||||
            fileIO.saveTournament(tournament);
 | 
					            fileIO.saveTournament(tournament);
 | 
				
			||||||
 | 
					            logger.fine("new Tournament File is saved.");
 | 
				
			||||||
            factoryDecorator.clearMessage(true);
 | 
					            factoryDecorator.clearMessage(true);
 | 
				
			||||||
            informListener();
 | 
					            informListener();
 | 
				
			||||||
        } catch (InvalidNameException e) {
 | 
					        } catch (InvalidNameException e) {
 | 
				
			||||||
            e.printStackTrace();
 | 
					            e.printStackTrace();
 | 
				
			||||||
            //TODO: Logger
 | 
					            logger.warning("The name which was entered is invalid.");
 | 
				
			||||||
            String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidName");
 | 
					            String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidName");
 | 
				
			||||||
            factoryDecorator.printMessageToFooter(msg, true);
 | 
					            factoryDecorator.printMessageToFooter(msg, true);
 | 
				
			||||||
        } catch (Tournament.InvalidTypeException e) {
 | 
					        } catch (Tournament.InvalidTypeException e) {
 | 
				
			||||||
            e.printStackTrace();
 | 
					            e.printStackTrace();
 | 
				
			||||||
            //TODO: Logger
 | 
					            logger.warning("The selected type of tournament is not valid.");
 | 
				
			||||||
            String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidMode");
 | 
					            String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidMode");
 | 
				
			||||||
            factoryDecorator.printMessageToFooter(msg, true);
 | 
					            factoryDecorator.printMessageToFooter(msg, true);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        } catch (IOException e) {
 | 
					        } catch (IOException e) {
 | 
				
			||||||
            e.printStackTrace();
 | 
					            e.printStackTrace();
 | 
				
			||||||
            //TODO: Logger
 | 
					            logger.warning("Creating a new Tournament File was failed.");
 | 
				
			||||||
            String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("IOException");
 | 
					            String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("IOException");
 | 
				
			||||||
            factoryDecorator.printMessageToFooter(msg, true);
 | 
					            factoryDecorator.printMessageToFooter(msg, true);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Method to delete a Tournament File
 | 
				
			||||||
 | 
					     * @param tournamentFile The File which should be deleted.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    public void deleteTournament(FileIO.TournamentFile tournamentFile){
 | 
					    public void deleteTournament(FileIO.TournamentFile tournamentFile){
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            fileIO.deleteTournament(tournamentFile);
 | 
					            fileIO.deleteTournament(tournamentFile);
 | 
				
			||||||
| 
						 | 
					@ -113,8 +159,11 @@ public class TournamentDecorator implements IsObservable{
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Method to create the list of games. The participants are entered in random order.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    public void createNewGameSchedule() {
 | 
					    public void createNewGameSchedule() {
 | 
				
			||||||
        //TODO: logging
 | 
					        logger.fine("Creating new Game Schedule");
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            tournament.createGameSchedule();
 | 
					            tournament.createGameSchedule();
 | 
				
			||||||
            factoryDecorator.clearMessage(true);
 | 
					            factoryDecorator.clearMessage(true);
 | 
				
			||||||
| 
						 | 
					@ -122,6 +171,7 @@ public class TournamentDecorator implements IsObservable{
 | 
				
			||||||
            e.printStackTrace();
 | 
					            e.printStackTrace();
 | 
				
			||||||
            String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("numberParticipant");
 | 
					            String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("numberParticipant");
 | 
				
			||||||
            factoryDecorator.printMessageToFooter(msg, true);
 | 
					            factoryDecorator.printMessageToFooter(msg, true);
 | 
				
			||||||
 | 
					            logger.warning("Failed to create Game Schedule. The number of Participants is invalid.");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        informListener();
 | 
					        informListener();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue