/* * (non-Javadoc) * @see com.syncnapsis.data.service.PlayerManager#removeSitter(java.lang.Long, java.lang.Long) */ @Override public Player removeSitter(Long playerSittedId, Long playerSitterId) { Player sitted = get(playerSittedId); Player sitter = get(playerSitterId); sitted.getSitters().remove(sitter); return save(sitted); }
/* * (non-Javadoc) * @see com.syncnapsis.data.service.PlayerManager#addSitter(java.lang.Long, java.lang.Long) */ @Override public Player addSitter(Long playerSittedId, Long playerSitterId) { if (playerSittedId.equals(playerSitterId)) throw new PlayerSelectionInvalidException("sitted equals sitter"); Player sitted = get(playerSittedId); Player sitter = get(playerSitterId); for (Player sitter2 : sitted.getSitters()) { if (sitter2.getId().equals(sitter.getId())) throw new PlayerSittingExistsException("Sitting relation already exists!", sitter); } if (!checkSitter(sitter)) throw new PlayerSittingNotPossibleException("sitter has too much sitted", sitter); if (!checkSitted(sitted)) throw new PlayerSittingNotPossibleException("sitted has too much sitters", sitted); sitted.getSitters().add(sitter); return save(sitted); }
/* * (non-Javadoc) * @see com.syncnapsis.data.service.PlayerManager#checkSitted(com.syncnapsis.data.model.Player) */ @Override public boolean checkSitted(Player sitted) { return sitted.getRole().getMaxSitters() < 0 || sitted.getSitters().size() < sitted.getRole().getMaxSitters(); }