I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 0af8ed90 authored by str4d's avatar str4d
Browse files

Added NotEqual and EqualAny, removed show-on-null assumption

parent c761287a
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@
package net.i2p.android.wizard.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Conditional implements ModelCallbacks {
......@@ -45,10 +46,33 @@ public class Conditional implements ModelCallbacks {
}
public boolean isSatisfied() {
// If we have no data from the conditional,
// assume that the page will be shown.
if (mData == null) return true;
return mCompValue.equals(mData);
}
}
public class NotEqualCondition<T> implements Condition {
private T mCompValue;
public NotEqualCondition(Page page, T compValue) {
mCompValue = compValue;
mConditionalPages.add(page);
}
public boolean isSatisfied() {
return !(mCompValue.equals(mData));
}
}
public class EqualAnyCondition<T> implements Condition {
private ArrayList<T> mChoices = new ArrayList<T>();
public EqualAnyCondition(Page page, T... choices) {
mChoices.addAll(Arrays.asList(choices));
mConditionalPages.add(page);
}
public boolean isSatisfied() {
return mChoices.contains(mData);
}
}
}
......@@ -152,6 +152,18 @@ public abstract class Page implements PageTreeNode {
return this;
}
public <T> Page setNotEqualCondition(Conditional conditional, T comp) {
Conditional.Condition c = conditional.new NotEqualCondition<T>(this, comp);
mConditions.add(c);
return this;
}
public <T> Page setEqualAnyCondition(Conditional conditional, T... choices) {
Conditional.Condition c = conditional.new EqualAnyCondition<T>(this, choices);
mConditions.add(c);
return this;
}
public Page satisfyAllConditions(boolean conditionAnd) {
mConditionAnd = conditionAnd;
return this;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment