Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 
 package org.holoeverywhere.builder;
 
 import java.util.List;
 import java.util.Map;
import  org.json.JSONArray;
import  org.json.JSONObject;
public class Block implements Parseable<JSONObject, Block> {
    private static final Comparator<StringCOMPARATOR = new Comparator<String>() {
        @Override
        public int compare(String o1String o2) {
            return o1.compareTo(o2);
        }
    };
    public Map<StringStringdata = new HashMap<StringString>();
    public List<Stringinclude = new ArrayList<String>();
    public String parent;
    @Override
    @SuppressWarnings("unchecked")
    public Block parse(JSONObject data) {
         = null;
        .clear();
        this..clear();
        if (data.has("include")) {
            JSONArray a = data.optJSONArray("include");
            for (int i = 0; i < a.length(); i++) {
                .add(String.valueOf(a.opt(i)));
            }
        }
        if (data.has("parent")) {
             = data.optString("parent");
        }
        Iterator<Stringkeys = data.sortedKeys();
        while (keys.hasNext()) {
            String key = keys.next();
            if ("include".equals(key) || "parent".equals(key)) {
                continue;
            }
            String value = String.valueOf(data.opt(key));
            if (value != null) {
                this..put(keyvalue);
            }
        }
        return this;
    }
    public void process(XMLStreamWriter writerMap<StringBlockblocks)
            throws XMLStreamException {
        if ( != null) {
            writer.writeAttribute("parent");
        }
        for (String i : ) {
            if (blocks.containsKey(i)) {
                writer.writeComment("Include block: " + i);
                blocks.get(i).process(writerblocks);
                writer.writeComment("End of block " + i);
            } else {
                writer.writeComment(" Block not found: " + i + " ");
            }
        }
        SortedMap<StringStringdata = new TreeMap<StringString>();
        data.putAll(this.);
        for (Entry<StringStringentry : data.entrySet()) {
            writer.writeStartElement("item");
            writer.writeAttribute("name"entry.getKey());
            writer.writeCharacters(entry.getValue());
            writer.writeEndElement();
        }
    }
New to GrepCode? Check out our FAQ X