]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/output/template/IfStatement.java
add: documentation to output classes
[gigi.git] / src / org / cacert / gigi / output / template / IfStatement.java
index 39a89b80d515d8cfb69f4b3376e7f99973d1c45d..f2248bcc72fd3a3987b87cc22f7192d5c2883bdc 100644 (file)
@@ -1,11 +1,16 @@
 package org.cacert.gigi.output.template;
 
 import java.io.PrintWriter;
+import java.util.Collection;
 import java.util.Map;
 
 import org.cacert.gigi.localisation.Language;
 
-public final class IfStatement implements Outputable {
+/**
+ * One ore two {@link Outputable}s that are emitted conditionally if a given
+ * variable is neither <code>null</code> nor {@link Boolean#FALSE}.
+ */
+public final class IfStatement implements Translatable {
 
     private final String variable;
 
@@ -13,12 +18,30 @@ public final class IfStatement implements Outputable {
 
     private final TemplateBlock iffalse;
 
+    /**
+     * Creates a new {@link IfStatement} with an empty else-part.
+     * 
+     * @param variable
+     *            the variable to check
+     * @param body
+     *            the body to emit conditionally.
+     */
     public IfStatement(String variable, TemplateBlock body) {
         this.variable = variable;
         this.iftrue = body;
-        iffalse = null;
+        this.iffalse = null;
     }
 
+    /**
+     * Creates a new {@link IfStatement} with an else-block.
+     * 
+     * @param variable
+     *            the variable to check
+     * @param iftrue
+     *            the block to emit if the check succeeds.
+     * @param iffalse
+     *            the block to emit if the check fails
+     */
     public IfStatement(String variable, TemplateBlock iftrue, TemplateBlock iffalse) {
         this.variable = variable;
         this.iftrue = iftrue;
@@ -28,10 +51,20 @@ public final class IfStatement implements Outputable {
     @Override
     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
         Object o = vars.get(variable);
-        if ( !(o == null || o == Boolean.FALSE)) {
+
+        if ( !(o == null || Boolean.FALSE.equals(o))) {
             iftrue.output(out, l, vars);
         } else if (iffalse != null) {
             iffalse.output(out, l, vars);
         }
     }
+
+    @Override
+    public void addTranslations(Collection<String> s) {
+        iftrue.addTranslations(s);
+        if (iffalse != null) {
+            iffalse.addTranslations(s);
+        }
+    }
+
 }