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

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

Introduction

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

Prototype

public final int size() 

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));/*from w ww . j  a v  a 2s  . co  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  av a2 s. c om
    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  a  2  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. ja  va2  s .  c  o m*/
        }
        appendTo.append(items.get(i));
    }
    return appendTo.toString();
}

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

public static <T> void sort(CircularArray<T> list, Comparator<? super T> comparator) {
    if (list.isEmpty())
        return;/*from  w  w  w. j  av a  2  s.  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.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;
    }//from  w  w w  .  j a v  a  2  s  . c  o m
    return -1;
}

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   w w w.ja  v  a 2  s  .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());

    {//from   w  w w  . java 2  s.com
        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   www  .j  a  v a2  s .  c  o  m
        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.module.weather.WeatherLoadingService.java

void onWeatherDataLoaded(@Nullable CircularArray<WeatherData> weatherDataList, String unit) {

    int N = weatherDataList == null ? 0 : weatherDataList.size();
    for (int i1 = 0; i1 < N; i1++) {
        WeatherData weatherData = weatherDataList.get(i1);

        ContentValues weatherValues = new ContentValues();

        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_LAST_UPDATED, System.currentTimeMillis());
        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_WOEID, weatherData.woeid);

        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_ATMOSPHERE_HUMIDITY,
                weatherData.atmosphereHumidity);
        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_ATMOSPHERE_PRESSURE,
                weatherData.atmospherePressure);
        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_ATMOSPHERE_RISING,
                weatherData.atmosphereRising);
        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_ATMOSPHERE_VISIBILITY,
                weatherData.atmosphereVisible);

        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_NOW_CONDITION_CODE,
                weatherData.nowConditionCode);
        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_NOW_TEMPERATURE,
                weatherData.nowTemperature);

        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_SUNRISE, weatherData.sunrise);
        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_SUNSET, weatherData.sunset);

        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_WIND_CHILL, weatherData.windChill);
        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_WIND_DIRECTION, weatherData.windDirection);
        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_WIND_SPEED, weatherData.windSpeed);
        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_CITY, weatherData.location);
        weatherValues.put(WeatherContract.WeatherColumns.COLUMN_NAME_UNIT, unit);

        ContentResolver contentResolver = mContext.getContentResolver();
        contentResolver.insert(WeatherContract.WeatherColumns.CONTENT_URI, weatherValues);

        List<WeatherData.Forecast> forecasts = weatherData.forecasts;
        if (!forecasts.isEmpty()) {

            int count = forecasts.size();
            ContentValues[] forecastValues = new ContentValues[count];

            for (int i = 0; i < count; i++) {
                WeatherData.Forecast forecast = forecasts.get(i);

                ContentValues contentValues = new ContentValues();
                contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_FORECAST_DAY, forecast.julianDay);
                contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_LAST_UPDATED,
                        System.currentTimeMillis());
                contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_LOCATION_WOEID,
                        weatherData.woeid);
                contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_CONDITION_CODE,
                        forecast.conditionCode);
                contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_TEMPERATURE_HIGH, forecast.high);
                contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_TEMPERATURE_LOW, forecast.low);
                contentValues.put(WeatherContract.ForecastColumns.COLUMN_NAME_UNIT, unit);
                forecastValues[i] = contentValues;
            }// w  w  w  . j  a v a2 s.c o  m
            Uri uri = WeatherContract.ForecastColumns.CONTENT_URI;
            contentResolver.bulkInsert(uri, forecastValues);
        }
    }

    Intent i = new Intent(ACTION_WEATHER_UPDATED);
    i.setPackage(mContext.getPackageName());
    mContext.sendBroadcast(i);
}