ListGamesProxy.java :  » Game » jdiplomacy » diplomacy » access » Java Open Source

Java Open Source » Game » jdiplomacy 
jdiplomacy » diplomacy » access » ListGamesProxy.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package diplomacy.access;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import diplomacy.Main;
import diplomacy.game.GameInfo;

/**
 * Liste des jeux en cache
 * @author Jean-Baptiste Vovau
 */
public class ListGamesProxy {

  private static ListGamesProxy instance;
  
    private Map<TypeListGame,List<GameInfo>> cachedLists;

    public static ListGamesProxy getInstance(){
      if (instance == null) instance = new ListGamesProxy();
      return instance;
    }
    
    
    private ListGamesProxy() {
        cachedLists = new HashMap<TypeListGame,List<GameInfo>>();
    }

    /**
     * Retourne une liste de jeu gre en cache
     * @param listType
     * @return
     */
    public List<GameInfo> listGames(TypeListGame listType){


        List<GameInfo> result = cachedLists.get(listType);

        if (result == null){
            result = Main.getDBAccess().listGames(listType);
            cachedLists.put(listType, result);
        }

        return result;
    }

    /**
     * Vide le cache des listes
     */
    public void clearCache(){
        this.cachedLists.clear();
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.