class TrainingSetManager {

	public synchronized TrainingSet acquireTrainingSet(long id)
	{
		if (assignedTrainingSets.stream().noneMatch(o -> o.getClientID() == id))
		{
			TrainingSet trainingSet = trainingSets.poll();
			if (trainingSet == null)
			{
				trainingSet = getExpiredAssignedTrainingSet();
			}
			if (trainingSet != null)
			{
				assignedTrainingSets.add(new AssignedTrainingSet(id, trainingSet,
						(long) trainingSet.getDuration() * TIME_MULTIPLIER_TO_FINISH_TRAINING * SEC_TO_NANO));
			}
		}
		AssignedTrainingSet assignedTrainingSet = getAssignedTrainingSet(id);
		return assignedTrainingSet != null ? assignedTrainingSet.getTrainingSet() : null;
	}

	  TrainingSetManager();

}