Package ch.fusun.baron.player

Source Code of ch.fusun.baron.player.CountryServiceImpl

package ch.fusun.baron.player;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import ch.fusun.baron.data.AbstractDataProvider;
import ch.fusun.baron.data.DataUpdate;
import ch.fusun.baron.player.api.Country;
import ch.fusun.baron.player.api.CountryService;
import ch.fusun.baron.player.api.CountryUpdate;

/**
* Country service
*/
public class CountryServiceImpl extends AbstractDataProvider implements
    CountryService {

  private Map<String, Country> countries = new HashMap<String, Country>();
  private int counter = 0;

  /**
   * Kryo
   */
  public CountryServiceImpl() {
  }

  @Override
  public DataUpdate createFullUpdate() {
    synchronized (countries) {
      return new CountryUpdate(countries);
    }
  }

  @Override
  public void setCountries(Map<String, Country> countries) {
    synchronized (countries) {
      this.countries = countries;
      updateAllListeners(new CountryUpdate(countries));
    }
  }

  @Override
  public Country createCountry(String name) {
    synchronized (countries) {
      Country country = new Country(counter++, name);
      countries.put(name, country);
      updateAllListeners(new CreateCountryDataUpdate(name));
      return country;
    }
  }

  @Override
  public Collection<Country> getCountries() {
    synchronized (countries) {
      return countries.values();
    }
  }

}
TOP

Related Classes of ch.fusun.baron.player.CountryServiceImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.