package willitconnect.service;

import org.apache.log4j.Logger;
import org.json.JSONObject;
import willitconnect.model.CheckedEntry;
import willitconnect.service.util.EntryConsumer;

import java.util.ArrayList;

/**
 * Checks VCAP_SERVICES for keys named host and values that look like URI's
 */
public class VcapServicesChecker {

    public static volatile ArrayList<CheckedEntry> results;

    private static Logger log = Logger.getLogger(VcapServicesChecker.class);

    public static void parse(JSONObject vcapServices) {
        java.util.Objects.requireNonNull(vcapServices);

        log.info(vcapServices);
        if ( 0 == vcapServices.length())
            return;

        ArrayList<CheckedEntry> entries = new ArrayList<CheckedEntry>();

        vcapServices.keys().forEachRemaining(new EntryConsumer(entries, vcapServices));
        results = entries;
    }

    public static void check() {


    }
}

@@ -176,16 +176,64 @@
 sumer;%0A%0A
+import java.sql.Date;%0Aimport java.time.Instant;%0A
 import j
@@ -252,16 +252,16 @@
 ayList;%0A
-
 %0A/**%0A * 
@@ -669,17 +669,16 @@
     if (
- 
 0 == vca
@@ -947,17 +947,163 @@
 eck() %7B%0A
-%0A
+        results.forEach(e -%3E %7B%0A            if (e.isValid()) %7B%0A                e.setLastChecked(Date.from(Instant.now()));%0A            %7D%0A        %7D);
 %0A    %7D%0A%7D

Check valid hosts