// Path: src/main/java/com/oscarsalguero/smartystreetsautocomplete/model/Address.java
// public class Address implements Serializable {
// 
//     private String text;
// 
//     @SerializedName("street_line")
//     private String streetLine;
// 
//     private String city;
// 
//     private String state;
// 
//     public Address(String text, String streetLine, String city, String state) {
//         this.text = text;
//         this.streetLine = streetLine;
//         this.city = city;
//         this.state = state;
//     }
// 
//     public String getText() {
//         return text;
//     }
// 
//     public void setText(String text) {
//         this.text = text;
//     }
// 
//     public String getStreetLine() {
//         return streetLine;
//     }
// 
//     public void setStreetLine(String streetLine) {
//         this.streetLine = streetLine;
//     }
// 
//     public String getCity() {
//         return city;
//     }
// 
//     public void setCity(String city) {
//         this.city = city;
//     }
// 
//     public String getState() {
//         return state;
//     }
// 
//     public void setState(String state) {
//         this.state = state;
//     }
// 
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (!(o instanceof Address)) return false;
//         Address address = (Address) o;
//         if (text != null ? !text.equals(address.text) : address.text != null) return false;
//         return true;
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = text != null ? text.hashCode() : 0;
//         return result;
//     }
// 
// }
// 
// Path: src/main/java/com/oscarsalguero/smartystreetsautocomplete/model/SuggestionsResponse.java
// public class SuggestionsResponse implements Serializable {
// 
//     @SerializedName("suggestions")
//     List<Address> suggestions;
// 
//     public SuggestionsResponse(List<Address> suggestions) {
//         this.suggestions = suggestions;
//     }
// 
//     public List<Address> getSuggestions() {
//         return suggestions;
//     }
// 
//     public void setSuggestions(List<Address> suggestions) {
//         this.suggestions = suggestions;
//     }
// }
// 
// Path: src/main/java/com/oscarsalguero/smartystreetsautocomplete/util/ResourceUtils.java
// public final class ResourceUtils {
// 
//     public static void closeResourceQuietly(@Nullable Closeable closeable) {
//         if (closeable != null) {
//             try {
//                 closeable.close();
//             } catch (IOException e) {
//                 Log.e(ResourceUtils.class.getName(), e.getMessage(), e);
//             }
//         }
//     }
// 
//     private ResourceUtils() {
//     }
// }


import android.util.JsonReader;
import android.util.JsonWriter;
import com.oscarsalguero.smartystreetsautocomplete.model.Address;
import com.oscarsalguero.smartystreetsautocomplete.model.SuggestionsResponse;
import com.oscarsalguero.smartystreetsautocomplete.util.ResourceUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
/***
 * Copyright (c) 2017 Oscar Salguero www.oscarsalguero.com
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.oscarsalguero.smartystreetsautocomplete.json;




/**
 * JSON parser
 */
class AndroidSmartyStreetsApiJsonParser implements SmartyStreetsApiJsonParser {

    @Override
    public SuggestionsResponse autocompleteFromStream(final InputStream is) throws JsonParsingException {
        JsonReader reader = null;
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
            reader = new JsonReader(bufferedReader);

            List<Address> suggestions = null;

            reader.beginObject();
            while (reader.hasNext()) {
                switch (reader.nextName()) {
                    case "suggestions":
                        suggestions = readPredictionsArray(reader);
                        break;
                    default:
                        reader.skipValue();
                        break;
                }
            }
            reader.endObject();
// Path: src/main/java/com/oscarsalguero/smartystreetsautocomplete/model/Address.java
// public class Address implements Serializable {
// 
//     private String text;
// 
//     @SerializedName("street_line")
//     private String streetLine;
// 
//     private String city;
// 
//     private String state;
// 
//     public Address(String text, String streetLine, String city, String state) {
//         this.text = text;
//         this.streetLine = streetLine;
//         this.city = city;
//         this.state = state;
//     }
// 
//     public String getText() {
//         return text;
//     }
// 
//     public void setText(String text) {
//         this.text = text;
//     }
// 
//     public String getStreetLine() {
//         return streetLine;
//     }
// 
//     public void setStreetLine(String streetLine) {
//         this.streetLine = streetLine;
//     }
// 
//     public String getCity() {
//         return city;
//     }
// 
//     public void setCity(String city) {
//         this.city = city;
//     }
// 
//     public String getState() {
//         return state;
//     }
// 
//     public void setState(String state) {
//         this.state = state;
//     }
// 
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (!(o instanceof Address)) return false;
//         Address address = (Address) o;
//         if (text != null ? !text.equals(address.text) : address.text != null) return false;
//         return true;
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = text != null ? text.hashCode() : 0;
//         return result;
//     }
// 
// }
// 
// Path: src/main/java/com/oscarsalguero/smartystreetsautocomplete/model/SuggestionsResponse.java
// public class SuggestionsResponse implements Serializable {
// 
//     @SerializedName("suggestions")
//     List<Address> suggestions;
// 
//     public SuggestionsResponse(List<Address> suggestions) {
//         this.suggestions = suggestions;
//     }
// 
//     public List<Address> getSuggestions() {
//         return suggestions;
//     }
// 
//     public void setSuggestions(List<Address> suggestions) {
//         this.suggestions = suggestions;
//     }
// }
// 
// Path: src/main/java/com/oscarsalguero/smartystreetsautocomplete/util/ResourceUtils.java
// public final class ResourceUtils {
// 
//     public static void closeResourceQuietly(@Nullable Closeable closeable) {
//         if (closeable != null) {
//             try {
//                 closeable.close();
//             } catch (IOException e) {
//                 Log.e(ResourceUtils.class.getName(), e.getMessage(), e);
//             }
//         }
//     }
// 
//     private ResourceUtils() {
//     }
// }


// Path: src/main/java/com/oscarsalguero/smartystreetsautocomplete/json/AndroidSmartyStreetsApiJsonParser.java
import android.util.JsonReader;
import android.util.JsonWriter;
import com.oscarsalguero.smartystreetsautocomplete.model.Address;
import com.oscarsalguero.smartystreetsautocomplete.model.SuggestionsResponse;
import com.oscarsalguero.smartystreetsautocomplete.util.ResourceUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;

/***
 * Copyright (c) 2017 Oscar Salguero www.oscarsalguero.com
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.oscarsalguero.smartystreetsautocomplete.json;




/**
 * JSON parser
 */
class AndroidSmartyStreetsApiJsonParser implements SmartyStreetsApiJsonParser {

    @Override
    public SuggestionsResponse autocompleteFromStream(final InputStream is) throws JsonParsingException {
        JsonReader reader = null;
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
            reader = new JsonReader(bufferedReader);

            List<Address> suggestions = null;

            reader.beginObject();
            while (reader.hasNext()) {
                switch (reader.nextName()) {
                    case "suggestions":
                        suggestions = readPredictionsArray(reader);
                        break;
                    default:
                        reader.skipValue();
                        break;
                }
            }
            reader.endObject();
            return new SuggestionsResponse(suggestions);