package in.twizmwaz.cardinal.module.modules.blitz;

import in.twizmwaz.cardinal.match.Match;
import in.twizmwaz.cardinal.module.ModuleBuilder;
import in.twizmwaz.cardinal.module.ModuleCollection;
import in.twizmwaz.cardinal.util.TimeUtils;
import org.jdom2.Element;

public class BlitzBuilder implements ModuleBuilder {

    public ModuleCollection load(Match match) {
        ModuleCollection result = new ModuleCollection();
        for (Element element : match.getDocument().getRootElement().getChildren("blitz")) {
            boolean broadcastLives = false;
            if (element.getChild("broadcastLives").getText() != null) {
                broadcastLives = Boolean.parseBoolean(element.getChild("broadcastLives").getText());
            }
            int lives = 1;
            if (element.getChild("lives").getText() != null) {
                lives = Integer.parseInt(element.getChild("lives").getText());
            }
            int time = 0;
            if (element.getChild("time").getText() != null) {
                time = TimeUtils.timePeriodsToSeconds(element.getChild("time").getText());
            }
            String title = null;
            if (element.getChild("title").getText() != null) {
                title = element.getChild("title").getText();
            }
            result.add(new Blitz(title, broadcastLives, lives, time));
        }
        return result;
    }

}


@@ -386,16 +386,23 @@
 llection
+%3CBlitz%3E
  result 
@@ -423,16 +423,23 @@
 llection
+%3CBlitz%3E
 ();%0A    
@@ -567,31 +567,8 @@
 s = 
-false;%0A            if (
 elem
@@ -601,62 +601,19 @@
 es%22)
-.getText() != null) %7B%0A                broadcastLives =
+ != null &&
  Boo
@@ -693,303 +693,176 @@
     
-%7D%0A            int lives = 1;%0A            if (element.getChild(%22lives%22).getText() != null) %7B%0A                lives = Integer.parseInt(element.getChild(%22lives%22).getText());%0A            %7D%0A            int time = 0;%0A            if (element.getChild(%22time%22).getText() != null) %7B%0A                time =
+int lives = element.getChild(%22lives%22) == null ? 1 : Integer.parseInt(element.getChild(%22lives%22).getText());%0A            int time = element.getChild(%22time%22) == null ? 0 :
  Tim
@@ -926,30 +926,16 @@
 ext());%0A
-            %7D%0A
         
@@ -957,151 +957,38 @@
 e = 
-null;%0A            if (element.getChild(%22title%22).getText() != null) %7B%0A                title = element.getChild(%22title%22).getText();%0A            %7D
+element.getChildText(%22title%22);
 %0A   

Fix an NPEs when elements are not present