package com.noradltd.medusa.scrum;

import static com.noradltd.medusa.scrum.CardBuilder.createCardsLike;
import static com.noradltd.medusa.scrum.TeamBuilder.createTeamOf;

import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import com.noradltd.medusa.scrum.Card.Size;

public abstract class SprintBuilder {

	private SprintBuilder() {
	}

	public static final Sprint emptySprint() {
		return new Sprint();
	}

	public static final Sprint defaultSprint() {
		Sprint sprint = overcommittedSprint();
		sprint.days = 10;

		return sprint;
	}

	public static final Sprint undercommittedSprint() {
		Sprint sprint = emptySprint();
		sprint.days = 5;
		sprint.addCards(createCardsLike(Size.SMALL, 5));
		sprint.team = createTeamOf(5);

		return sprint;
	}

	public static final Sprint overcommittedSprint() {
		Sprint sprint = emptySprint();

		sprint.days = 5;
		sprint.addCards(createCardsLike(Size.SMALL, 5));
		sprint.addCards(createCardsLike(Size.MEDIUM, 5));
		sprint.addCards(createCardsLike(Size.LARGE, 5));
		sprint.team = createTeamOf(5);

		return sprint;
	}

	public static final Sprint addDefectsTo(Sprint sprint, Integer defectCount) {
		Card[] array = sprint.cards.toArray(new Card[] {});
		List<Card> list = Arrays.asList(array);
		Collections.shuffle(list);
		Iterator<Card> cardItr = list.iterator();
		Card currentCard = cardItr.next();
		for (int ct = 0; ct < defectCount; ct++) {
			currentCard.shouldCreateDefect = true;
			currentCard.defectImpactRelativeToOriginalSize = 1.0f;
			currentCard = cardItr.next();
		}
		return sprint;
	}

}

@@ -1190,16 +1190,50 @@
 ount) %7B%0A
+%09%09if (!sprint.cards.isEmpty()) %7B%0A%09
 %09%09Card%5B%5D
@@ -1280,16 +1280,17 @@
  %7B%7D);%0A%09%09
+%09
 List%3CCar
@@ -1321,16 +1321,17 @@
 array);%0A
+%09
 %09%09Collec
@@ -1353,16 +1353,17 @@
 ist);%0A%09%09
+%09
 Iterator
@@ -1398,16 +1398,17 @@
 or();%0A%09%09
+%09
 Card cur
@@ -1434,16 +1434,17 @@
 next();%0A
+%09
 %09%09for (i
@@ -1479,24 +1479,25 @@
  ct++) %7B%0A%09%09%09
+%09
 currentCard.
@@ -1523,16 +1523,17 @@
 = true;%0A
+%09
 %09%09%09curre
@@ -1582,16 +1582,17 @@
 = 1.0f;%0A
+%09
 %09%09%09curre
@@ -1616,16 +1616,21 @@
 next();%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%09re

test sprint list for empty before creating defects