package com.alexstyl.specialdates.events.namedays.calendar.resource;

import com.alexstyl.specialdates.events.namedays.NamedayLocale;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

class NamedayJSONResourceProvider {

    private final NamedayJSONResourceLoader loader;

    NamedayJSONResourceProvider(NamedayJSONResourceLoader loader) {
        this.loader = loader;
    }

    NamedayJSON getNamedayJSONFor(NamedayLocale locale) throws JSONException {
        JSONObject json = loader.loadJSON(locale);
        JSONArray data = json.getJSONArray("data");
        JSONArray special = json.getJSONArray("special");
        return new NamedayJSON(data, special);
    }

}

@@ -303,16 +303,73 @@
  loader;
+%0A    private final JSONArray jsonArray = new JSONArray();
 %0A%0A    Na
@@ -681,35 +681,25 @@
 l = 
-json.getJSONArray(%22special%22
+getSpecialOf(json
 );%0A 
@@ -751,10 +751,212 @@
 %0A    %7D%0A%0A
+    private JSONArray getSpecialOf(JSONObject json) throws JSONException %7B%0A        if (json.has(%22special%22)) %7B%0A            return json.getJSONArray(%22special%22);%0A        %7D%0A        return jsonArray;%0A    %7D%0A%0A
 %7D%0A

Return empty JSONArray if no Special is found