Package meganetpo

Source Code of meganetpo.PlayersRepository

package meganetpo;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

/**
*
* @author Burtovoy Semen
*/
class PlayersRepository {

    private List<Player> playerList = new ArrayList<Player>();

    Player get(String nick) {
  Player pl = new Player();
  pl.setName(nick);
  playerList.add(pl);
  return pl;
    }

    public void remove(String nick) {
  for (Player player : playerList) {
      if (player.getName().equals(nick)) {
    playerList.remove(player);
      }
  }
    }

    public void remove(Player player) {
  playerList.remove(player);
    }

    public List<Player> getPlayerList() {
  return playerList;
    }

    public void setPlayerList(List<Player> playerList) {
  this.playerList = playerList;
    }

    public void save(String fileName) throws FileNotFoundException {
  FileOutputStream out = new FileOutputStream(fileName);
  XMLEncoder xmlEncoder = new XMLEncoder(out);
  xmlEncoder.writeObject(playerList);
  xmlEncoder.flush();
  xmlEncoder.close();
    }

    public void load(String fileName) throws FileNotFoundException {
  FileInputStream in = new FileInputStream(fileName);
  XMLDecoder xmlDecoder = new XMLDecoder(in);
  playerList = (List<Player>) xmlDecoder.readObject();
  xmlDecoder.close();
    }
}
TOP

Related Classes of meganetpo.PlayersRepository

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.