package sk.tomsik68.mclauncher.impl.versions.mcdownload;

import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import sk.tomsik68.mclauncher.api.common.IOperatingSystem;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

final class RuleList {
    private final List<Rule> rules;
    private static final RuleList EMPTY = new RuleList(Collections.<Rule>emptyList());

    RuleList(List<Rule> rules) {
        Objects.requireNonNull(rules);
        this.rules = Collections.unmodifiableList(rules);
    }

    static RuleList fromJson(JSONArray rulesArray) {
        if (rulesArray == null || rulesArray.isEmpty())
            return empty();

        List<Rule> rules = new ArrayList<>();
        for (Object r : rulesArray) {
            rules.add(new Rule((JSONObject) r));
        }

        return new RuleList(rules);
    }

    boolean allows(IOperatingSystem os, String version, IFeaturePredicate featurePred) {
        Objects.requireNonNull(featurePred);
        boolean result = true;

        for (Rule rule : rules) {
            result &= !rule.applies(featurePred) || rule.getAction() == Rule.Action.ALLOW;
        }

        return result;
    }

    static RuleList empty() {
        return EMPTY;
    }

    RuleList and(RuleList other) {
        List<Rule> newRules = new ArrayList<>(this.rules);
        newRules.addAll(other.rules);
        return new RuleList(newRules);
    }
}

@@ -1033,24 +1033,25 @@
 ePred);%0A
+%0A
         
 boolean 
@@ -1046,24 +1046,47 @@
     
-boolean result =
+if (rules.isEmpty())%0A            return
  tru
@@ -1139,19 +1139,12 @@
     
-result &= !
+if (
 rule
@@ -1164,19 +1164,40 @@
 urePred)
- %7C%7C
+)%0A                return
  rule.ge
@@ -1258,15 +1258,15 @@
 urn 
-result;
+false;%0A
 %0A   

Change RuleLists handling