// Path: src/com/pocketreddit/library/things/Listing.java
// public class Listing<T extends Thing> extends Thing {
//     private static final long serialVersionUID = 1L;
// 
//     /**
//      * A list of things that this Listing wraps.
//      */
//     private List<T> children;
// 
//     /**
//      * The full name of the listing that precedes this page. Null, if there is
//      * no previous.
//      */
//     private String before;
// 
//     /**
//      * The fullname of the listing that follows after this page. null if there
//      * is no next page.
//      */
//     private String after;
// 
//     /**
//      * This modhash is not the same modhash provided upon login. You do not need
//      * to update your user's modhash everytime you get a new modhash. You can
//      * reuse the modhash given upon login.
//      */
//     private String modHash;
// 
//     public List<T> getChildren() {
//         return children;
//     }
// 
//     public void setChildren(List<T> children) {
//         this.children = children;
//     }
// 
//     public String getBefore() {
//         return before;
//     }
// 
//     public void setBefore(String before) {
//         this.before = before;
//     }
// 
//     public String getAfter() {
//         return after;
//     }
// 
//     public void setAfter(String after) {
//         this.after = after;
//     }
// 
//     public String getModHash() {
//         return modHash;
//     }
// 
//     public void setModHash(String modHash) {
//         this.modHash = modHash;
//     }
// 
//     @Override
//     public Kind getKind() {
//         return Kind.LISTING;
//     }
// }
// 
// Path: src/com/pocketreddit/library/things/Thing.java
// public abstract class Thing implements Serializable {
//     private static final long serialVersionUID = 1L;
// 
//     private String id;
//     private String name;
// 
//     public abstract Kind getKind();
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// }
// 
// Path: src/com/pocketreddit/library/things/utils/JsonToThingConverter.java
// public class JsonToThingConverter<T extends Thing> {
//     public JsonToThingConverter() {
//     }
// 
//     @SuppressWarnings({ "unchecked", "rawtypes" })
//     public T convert(JSONObject json) throws ThingFactoryException {
//         Kind kind;
//         try {
//             kind = Kind.toKind(json.getString("kind"));
//         } catch (JSONException e) {
//             throw new ThingFactoryException(
//                     "An error occurred trying to parse the kind of thing in provided json", e);
//         }
// 
//         ThingFactory thingFactory = null;
// 
//         switch (kind) {
//         case SUBREDDIT:
//             thingFactory = new SubredditFactory(json);
//             break;
//         case LISTING:
//             thingFactory = new ListingFactory(json);
//             break;
//         case THREAD:
//             try {
//                 thingFactory = json.getJSONObject("data").isNull("domain") ? new CommentFactory(
//                         json) : new LinkFactory(json);
//             } catch (JSONException e) {
//                 throw new ThingFactoryException("Could not parse data for Thread thing.", e);
//             }
//             break;
//         case COMMENT:
//             thingFactory = new CommentFactory(json);
//             break;
//         case MORE:
//             return (T) new More();
//         default:
//             throw new UnsupportedOperationException("Kind: " + kind
//                     + " conversion not yet supported.");
//         }
// 
//         return (T) thingFactory.createThing();
//     }
// }


import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.pocketreddit.library.things.Listing;
import com.pocketreddit.library.things.Thing;
import com.pocketreddit.library.things.utils.JsonToThingConverter;
package com.pocketreddit.library.things.factories;




public class ListingFactory<T extends Thing> implements ThingFactory {
    private JSONObject json;

    public ListingFactory(JSONObject json) {
        this.json = json;
    }

    public Listing<T> createThing() throws ThingFactoryException {
        Listing<T> listing = new Listing<T>();
        List<T> children = new ArrayList<T>();

        try {
            JSONObject data = json.getJSONObject("data");
            JSONArray jsonChildren = data.getJSONArray("children");
            for (int i = 0; i < jsonChildren.length(); i++) {
// Path: src/com/pocketreddit/library/things/Listing.java
// public class Listing<T extends Thing> extends Thing {
//     private static final long serialVersionUID = 1L;
// 
//     /**
//      * A list of things that this Listing wraps.
//      */
//     private List<T> children;
// 
//     /**
//      * The full name of the listing that precedes this page. Null, if there is
//      * no previous.
//      */
//     private String before;
// 
//     /**
//      * The fullname of the listing that follows after this page. null if there
//      * is no next page.
//      */
//     private String after;
// 
//     /**
//      * This modhash is not the same modhash provided upon login. You do not need
//      * to update your user's modhash everytime you get a new modhash. You can
//      * reuse the modhash given upon login.
//      */
//     private String modHash;
// 
//     public List<T> getChildren() {
//         return children;
//     }
// 
//     public void setChildren(List<T> children) {
//         this.children = children;
//     }
// 
//     public String getBefore() {
//         return before;
//     }
// 
//     public void setBefore(String before) {
//         this.before = before;
//     }
// 
//     public String getAfter() {
//         return after;
//     }
// 
//     public void setAfter(String after) {
//         this.after = after;
//     }
// 
//     public String getModHash() {
//         return modHash;
//     }
// 
//     public void setModHash(String modHash) {
//         this.modHash = modHash;
//     }
// 
//     @Override
//     public Kind getKind() {
//         return Kind.LISTING;
//     }
// }
// 
// Path: src/com/pocketreddit/library/things/Thing.java
// public abstract class Thing implements Serializable {
//     private static final long serialVersionUID = 1L;
// 
//     private String id;
//     private String name;
// 
//     public abstract Kind getKind();
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// }
// 
// Path: src/com/pocketreddit/library/things/utils/JsonToThingConverter.java
// public class JsonToThingConverter<T extends Thing> {
//     public JsonToThingConverter() {
//     }
// 
//     @SuppressWarnings({ "unchecked", "rawtypes" })
//     public T convert(JSONObject json) throws ThingFactoryException {
//         Kind kind;
//         try {
//             kind = Kind.toKind(json.getString("kind"));
//         } catch (JSONException e) {
//             throw new ThingFactoryException(
//                     "An error occurred trying to parse the kind of thing in provided json", e);
//         }
// 
//         ThingFactory thingFactory = null;
// 
//         switch (kind) {
//         case SUBREDDIT:
//             thingFactory = new SubredditFactory(json);
//             break;
//         case LISTING:
//             thingFactory = new ListingFactory(json);
//             break;
//         case THREAD:
//             try {
//                 thingFactory = json.getJSONObject("data").isNull("domain") ? new CommentFactory(
//                         json) : new LinkFactory(json);
//             } catch (JSONException e) {
//                 throw new ThingFactoryException("Could not parse data for Thread thing.", e);
//             }
//             break;
//         case COMMENT:
//             thingFactory = new CommentFactory(json);
//             break;
//         case MORE:
//             return (T) new More();
//         default:
//             throw new UnsupportedOperationException("Kind: " + kind
//                     + " conversion not yet supported.");
//         }
// 
//         return (T) thingFactory.createThing();
//     }
// }


// Path: src/com/pocketreddit/library/things/factories/ListingFactory.java
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.pocketreddit.library.things.Listing;
import com.pocketreddit.library.things.Thing;
import com.pocketreddit.library.things.utils.JsonToThingConverter;

package com.pocketreddit.library.things.factories;




public class ListingFactory<T extends Thing> implements ThingFactory {
    private JSONObject json;

    public ListingFactory(JSONObject json) {
        this.json = json;
    }

    public Listing<T> createThing() throws ThingFactoryException {
        Listing<T> listing = new Listing<T>();
        List<T> children = new ArrayList<T>();

        try {
            JSONObject data = json.getJSONObject("data");
            JSONArray jsonChildren = data.getJSONArray("children");
            for (int i = 0; i < jsonChildren.length(); i++) {
                JsonToThingConverter<T> converter = new JsonToThingConverter<T>();