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

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

Introduction

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

Prototype

public final E get(int i) 

Source Link

Usage

From source file:Main.java

public static <T> void addAll(CircularArray<T> target, CircularArray<T> source) {
    int N = source.size();
    for (int i = 0; i < N; i++) {
        target.addLast(source.get(i));
    }//  w w w  . j  a  v a 2 s . c o  m
}

From source file:Main.java

public static <T> boolean contains(CircularArray<T> array, T item) {
    int N = array.size();
    for (int i = 0; i < N; i++) {
        if (item == null && array.get(i) == null)
            return true;
        if (item != null && item.equals(array.get(i)))
            return true;
    }//from w w  w  . j  a  va2 s  .  com
    return false;
}

From source file:Main.java

private static <T> T[] toArray(CircularArray<T> items, T[] result) {
    int N = items.size();
    if (N != result.length)
        throw new IllegalArgumentException("Wrong array size");
    for (int i = 0; i < N; i++) {
        result[i] = items.get(i);
    }/*from  w  w  w  .ja v a2 s.  c  o  m*/
    return result;
}

From source file:Main.java

public static String join(String separator, CircularArray<String> items, StringBuilder appendTo) {
    int N = items.size();
    for (int i = 0; i < N; i++) {
        if (i > 0) {
            appendTo.append(separator);/*w w w .  j  av  a 2s  .c  o  m*/
        }
        appendTo.append(items.get(i));
    }
    return appendTo.toString();
}

From source file:com.appsimobile.appsii.Sidebar.java

private static int indexOfId(CircularArray<HotspotPageEntry> entries, long defaultPage) {
    if (defaultPage == -1L)
        return -1;
    for (int i = 0; i < entries.size(); i++) {
        HotspotPageEntry e = entries.get(i);
        if (e.mPageId == defaultPage)
            return i;
    }/*w w w .j  av  a  2  s  .  c om*/
    return -1;
}

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;/*from  w w  w  .  ja v  a2 s. co m*/

    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.WeatherDataParserTest.java

public void testWeatherParser_singleResult() throws ParseException, ResponseParserException, JSONException {
    AssetManager manager = getContext().getAssets();
    String json = AssetUtils.readAssetToString(manager, "weather1.json", new StringBuilder());
    CircularArray<WeatherData> result = new CircularArray<>();
    WeatherDataParser.parseWeatherData(result, json, ArrayUtils.asArray("1"));

    assertEquals(1, result.size());/*from ww w .  j  a  va2s.  c o m*/

    {
        WeatherData data1 = result.get(0);

        assertEquals("Etten-Leur", data1.location);
        assertEquals(-6, data1.windChill);
        assertEquals(70, data1.windDirection);
        assertEquals(14.48f, data1.windSpeed);

        assertEquals(83, data1.atmosphereHumidity);
        assertEquals(1015.92f, data1.atmospherePressure);
        assertEquals(0, data1.atmosphereRising);
        assertEquals(5f, data1.atmosphereVisible);

        assertEquals("8:32 am", data1.sunrise);
        assertEquals("5:13 pm", data1.sunset);

        assertEquals(26, data1.nowConditionCode);
        assertEquals(-1, data1.nowTemperature);
        assertEquals("Cloudy", data1.nowConditionText);

        assertEquals("1", data1.woeid);

        assertEquals(5, data1.forecasts.size());
        {
            WeatherData.Forecast fc = data1.forecasts.get(0);
            assertEquals(2457045, fc.julianDay);
            assertEquals(1, fc.high);
            assertEquals(-2, fc.low);
            assertEquals(29, fc.conditionCode);
            assertEquals("Partly Cloudy", fc.forecastText);
        }
    }

}

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

public void testWeatherParserWithError() throws ParseException, ResponseParserException, JSONException {
    AssetManager manager = getContext().getAssets();
    String json = AssetUtils.readAssetToString(manager, "weather_with_error.json", new StringBuilder());
    CircularArray<WeatherData> result = new CircularArray<>();
    WeatherDataParser.parseWeatherData(result, json, ArrayUtils.asArray("a", "b"));

    assertEquals(1, result.size());/*  w  ww . j a  v a  2  s.c  o  m*/

    {
        WeatherData data1 = result.get(0);

        assertEquals("Etten-Leur", data1.location);
        assertEquals(24, data1.windChill);
        assertEquals(60, data1.windDirection);
        assertEquals(6.0f, data1.windSpeed);

        assertEquals(91, data1.atmosphereHumidity);
        assertEquals(29.85f, data1.atmospherePressure);
        assertEquals(0, data1.atmosphereRising);
        assertEquals(3.73f, data1.atmosphereVisible);

        assertEquals("8:34 am", data1.sunrise);
        assertEquals("5:11 pm", data1.sunset);

        assertEquals(26, data1.nowConditionCode);
        assertEquals(30, data1.nowTemperature);
        assertEquals("Cloudy", data1.nowConditionText);

        assertEquals("b", data1.woeid);
        assertEquals(5, data1.forecasts.size());
        {
            WeatherData.Forecast fc = data1.forecasts.get(0);
            assertEquals(2457044, fc.julianDay);
            assertEquals(35, fc.high);
            assertEquals(27, fc.low);
            assertEquals(29, fc.conditionCode);
            assertEquals("Partly Cloudy", fc.forecastText);
        }
    }

}

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

public void testWeatherParser_multipleResults() throws ParseException, ResponseParserException, JSONException {
    AssetManager manager = getContext().getAssets();
    String json = AssetUtils.readAssetToString(manager, "weather.json", new StringBuilder());
    CircularArray<WeatherData> result = new CircularArray<>();
    WeatherDataParser.parseWeatherData(result, json, ArrayUtils.asArray("1", "2", "3"));

    assertEquals(3, result.size());/*from   ww  w .  j a va  2 s. com*/

    {
        WeatherData data1 = result.get(0);

        assertEquals("Breda", data1.location);
        assertEquals(34, data1.windChill);
        assertEquals(80, data1.windDirection);
        assertEquals(3.0f, data1.windSpeed);

        assertEquals(81, data1.atmosphereHumidity);
        assertEquals(29.85f, data1.atmospherePressure);
        assertEquals(0, data1.atmosphereRising);
        assertEquals(6.21f, data1.atmosphereVisible);

        assertEquals("8:34 am", data1.sunrise);
        assertEquals("5:11 pm", data1.sunset);

        assertEquals(26, data1.nowConditionCode);
        assertEquals(34, data1.nowTemperature);
        assertEquals("Cloudy", data1.nowConditionText);

        assertEquals("1", data1.woeid);

        assertEquals(5, data1.forecasts.size());
        {
            WeatherData.Forecast fc = data1.forecasts.get(0);
            assertEquals(2457044, fc.julianDay);
            assertEquals(36, fc.high);
            assertEquals(28, fc.low);
            assertEquals(29, fc.conditionCode);
            assertEquals("Partly Cloudy", fc.forecastText);
        }
    }

}

From source file:com.appsimobile.appsii.LocationLoader.java

void onLocationInfoLoaded(@Nullable YahooWeatherApiClient.LocationInfo locationInfo) {
    CircularArray<String> woeids = locationInfo == null ? null : locationInfo.woeids;

    String town = locationInfo == null ? null : locationInfo.town;
    String country = locationInfo == null ? null : locationInfo.country;
    String timezone = locationInfo == null ? null : locationInfo.timezone;

    Log.i("WeatherFragment", "town: " + town + " country: " + country + " woeids: " + woeids);
    if (woeids != null && town != null) {
        String woeid = woeids.get(0);
        mLocationReceiver.onCurrentLocationInfoReady(woeid, country, town, timezone);
    } else {//  w  ww.  jav  a 2 s . c om
        mLocationReceiver.onCurrentLocationInfoReady(null, null, null, null);
    }
}