/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package asistencia.servlets;

import java.util.HashMap;
import java.util.List;
import static java.util.stream.Collectors.toList;
import org.json.JSONArray;
import org.json.JSONObject;


public class NewClass {
    public static void main(String[] args) {
        JSONArray arr = new JSONArray();
        JSONObject obj = new JSONObject();
        obj.put("nombre", "billy");
        obj.put("apellido", "larru");
        arr.put(obj);
        
        JSONObject obj2 = new JSONObject();
        obj2.put("nombre", "felipe");
        obj2.put("apellido", "escala");
        arr.put(obj2);
        
        JSONObject obj3 = new JSONObject();
        obj3.put("nombre", "");
        obj3.put("apellido", "escala");
        arr.put(obj3);
        
        System.out.println(arr.toList().get(0).getClass().getTypeName());
        
        
        List<HashMap> list =  arr.toList().stream().filter(HashMap.class::isInstance).map(HashMap.class::cast).collect(toList());
        List<HashMap<String, String>> list2 = (List<HashMap<String, String>>)(Object)list;
//        list.stream().filter(h -> h.entrySet().stream().filter(e -> e.g) );
//        HashMap<String, String> map = list.get(0);
//        map.entrySet().stream().filter(e -> e.get)
//         list2.forEach(h -> h.entrySet().stream().filter(e ->  e.getKey().equals("nombre") &&!e.getValue().isEmpty()).forEach(e -> System.out.println("e="+e.getKey()+ " "+e.getValue())));
        System.out.println(list);
        
        
        List<HashMap<String, String>> listmap = (List<HashMap<String, String>>)(Object)arr.toList();
        listmap.forEach(
                h -> h.entrySet().stream()
                        .filter(e -> e.getKey().equals("nombre") && !e.getValue().isEmpty())
                        .forEach(e -> System.out.println("k="+e.getKey()+", v="+e.getValue()))
        );
    }
}
