Example usage for android.support.v4.util CircularArray isEmpty

List of usage examples for android.support.v4.util CircularArray isEmpty

Introduction

In this page you can find the example usage for android.support.v4.util CircularArray isEmpty.

Prototype

public final boolean isEmpty() 

Source Link

Usage

From source file:com.appsimobile.util.ArrayUtils.java

public static <T> void sort(CircularArray<T> list, Comparator<? super T> comparator) {
    if (list.isEmpty())
        return;// w  w w.j ava2s .co  m
    T first = list.getFirst();
    T[] array = (T[]) Array.newInstance(first.getClass(), list.size());
    array = toArray(list, array);

    Arrays.sort(array, comparator);
    list.clear();
    for (T item : array) {
        list.addLast(item);
    }
}

From source file:com.appsimobile.appsii.module.weather.loader.WeatherDataParser.java

public static void parseWeatherData(CircularArray<WeatherData> result, String jsonString,
        CircularArray<String> woeids) throws JSONException, ResponseParserException, ParseException {

    if (woeids.isEmpty())
        return;//  w  w w  .  ja  v  a  2s. c  om

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.US);
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone(Time.TIMEZONE_UTC));

    SimpleJson json = new SimpleJson(jsonString);

    // when only a single woeid was requested, this is an object, otherwise it is an array.
    // So we need to check if we got an array; if so, handle each of the objects.
    // Otherwise get it as an object
    JSONArray resultsArray = json.getJsonArray("query.results.channel");

    if (resultsArray == null) {
        JSONObject weatherObject = json.optJsonObject("query.results.channel");
        if (weatherObject == null)
            return;

        String woeid = woeids.get(0);
        WeatherData weatherData = parseWeatherData(woeid, simpleDateFormat, weatherObject);
        if (weatherData != null) {
            result.addLast(weatherData);
        }
        return;
    }

    int length = resultsArray.length();
    for (int i = 0; i < length; i++) {
        JSONObject weatherJson = resultsArray.getJSONObject(i);
        WeatherData weatherData = parseWeatherData(woeids.get(i), simpleDateFormat, weatherJson);
        if (weatherData == null)
            continue;

        result.addLast(weatherData);

    }
}

From source file:com.appsimobile.appsii.module.weather.loader.YahooWeatherApiClient.java

@Nullable
public static CircularArray<WeatherData> getWeatherForWoeids(CircularArray<String> woeids, String unit)
        throws CantGetWeatherException {

    if (woeids == null || woeids.isEmpty())
        return null;

    HttpURLConnection connection = null;
    try {/*from   w ww  .j  a v  a2 s.  co m*/
        String url = buildWeatherQueryUrl(woeids, unit);
        if (BuildConfig.DEBUG)
            Log.d("YahooWeatherApiClient", "loading weather from: " + url);

        connection = Utils.openUrlConnection(url);

        CircularArray<WeatherData> result = new CircularArray<>();
        WeatherDataParser.parseWeatherData(result, connection.getInputStream(), woeids);

        return result;
    } catch (JSONException | ResponseParserException | ParseException | IOException | NumberFormatException e) {
        throw new CantGetWeatherException(true, R.string.no_weather_data, "Error parsing weather feed XML.", e);
    } finally {
        if (connection != null) {
            connection.disconnect();
        }
    }
}