Example usage for android.support.v4.util LongSparseArray put

List of usage examples for android.support.v4.util LongSparseArray put

Introduction

In this page you can find the example usage for android.support.v4.util LongSparseArray put.

Prototype

public void put(long j, E e) 

Source Link

Usage

From source file:org.mariotaku.twidere.util.LongSparseArrayUtils.java

/**
 * Sets all supplied keys to the given unique value.
 * /*from  w ww .  j a va  2 s.co  m*/
 * @param keys Keys to set
 * @param uniqueValue Value to set all supplied keys to
 */
public static <E> void setValues(final LongSparseArray<E> array, final long[] keys, final E uniqueValue) {
    final int length = keys.length;
    for (long key : keys) {
        array.put(key, uniqueValue);
    }
}

From source file:ru.orangesoftware.financisto2.model.MyEntity.java

public static <T extends MyEntity> LongSparseArray<T> asMap(List<T> list) {
    LongSparseArray<T> map = new LongSparseArray<T>();
    for (T e : list) {
        map.put(e.id, e);
    }//from ww  w  . ja va 2s  .com
    return map;
}

From source file:de.vanita5.twittnuker.util.LongSparseArrayUtils.java

/**
 * Sets all supplied keys to the given unique value.
 * //from  w  w w . ja v  a 2s. com
 * @param keys Keys to set
 * @param uniqueValue Value to set all supplied keys to
 */
public static <E> void setValues(final LongSparseArray<E> array, final long[] keys, final E uniqueValue) {
    final int length = keys.length;
    for (int i = 0; i < length; i++) {
        array.put(keys[i], uniqueValue);
    }
}

From source file:com.appsimobile.appsii.module.home.config.AbstractHomeItemConfiguration.java

@VisibleForTesting
static ConfigurationProperty createProperty(LongSparseArray<ConfigurationProperty> result, long cellId) {
    ConfigurationProperty property;//from  w w w  . j  a  v a 2 s.  c o  m
    property = new ConfigurationProperty();
    property.mCellId = cellId;
    result.put(cellId, property);
    return property;
}

From source file:ru.orangesoftware.financisto2.model.CategoryTree.java

private static void initializeMap(LongSparseArray<Category> map, List<Category> categories) {
    if (categories == null)
        return;/*from w  w w  .ja v  a2  s .  c o m*/
    for (Category c : categories) {
        map.put(c.id, c);
        if (c.hasChildren()) {
            initializeMap(map, c.children);
        }
    }
}

From source file:ru.orangesoftware.financisto2.db.MyEntityManager.java

private static <T extends MyEntity> LongSparseArray<T> entitiesAsIdMap(List<T> entities) {
    LongSparseArray<T> map = new LongSparseArray<T>();
    for (T e : entities) {
        map.put(e.id, e);
    }//from  ww w  .  j ava 2  s .co  m
    return map;
}

From source file:nz.ac.otago.psyanlab.common.model.util.LongSparseArrayGsonAdapter.java

@Override
public LongSparseArray<T> read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();/* w w w.ja v a2 s.c  om*/
        return null;
    }
    LongSparseArray<Object> temp = mGson.fromJson(in, mTypeOfLongSparseArrayOfObject);
    LongSparseArray<T> result = new LongSparseArray<T>(temp.size());
    long key;
    JsonElement tElement;
    for (int i = 0; i < temp.size(); i++) {
        key = temp.keyAt(i);
        tElement = mGson.toJsonTree(temp.get(key), new TypeToken<T>() {
        }.getType());
        result.put(key, mGson.fromJson(tElement, mTClazz));
    }
    return result;
}

From source file:com.example.amapdemo.heatmap.HeatmapTileProvider.java

/**
 * Calculate a reasonable maximum intensity value to map to maximum color intensity
 *
 * @param points    Collection of LatLngs to put into buckets
 * @param bounds    Bucket boundaries//w w  w .j  av  a 2  s .  c o m
 * @param radius    radius of convolution
 * @param screenDim larger dimension of screen in pixels (for scale)
 * @return Approximate max value
 */
static double getMaxValue(Collection<WeightedLatLng> points, Bounds bounds, int radius, int screenDim) {
    // Approximate scale as if entire heatmap is on the screen
    // ie scale dimensions to larger of width or height (screenDim)
    double minX = bounds.minX;
    double maxX = bounds.maxX;
    double minY = bounds.minY;
    double maxY = bounds.maxY;
    double boundsDim = (maxX - minX > maxY - minY) ? maxX - minX : maxY - minY;

    // Number of buckets: have diameter sized buckets
    int nBuckets = (int) (screenDim / (2 * radius) + 0.5);
    // Scaling factor to convert width in terms of point distance, to which bucket
    double scale = nBuckets / boundsDim;

    // Make buckets
    // Use a sparse array - use LongSparseArray just in case
    LongSparseArray<LongSparseArray<Double>> buckets = new LongSparseArray<LongSparseArray<Double>>();
    //double[][] buckets = new double[nBuckets][nBuckets];

    // Assign into buckets + find max value as we go along
    double x, y;
    double max = 0;
    for (WeightedLatLng l : points) {
        x = l.getPoint().x;
        y = l.getPoint().y;

        int xBucket = (int) ((x - minX) * scale);
        int yBucket = (int) ((y - minY) * scale);

        // Check if x bucket exists, if not make it
        LongSparseArray<Double> column = buckets.get(xBucket);
        if (column == null) {
            column = new LongSparseArray<Double>();
            buckets.put(xBucket, column);
        }
        // Check if there is already a y value there
        Double value = column.get(yBucket);
        if (value == null) {
            value = 0.0;
        }
        value += l.getIntensity();
        // Yes, do need to update it, despite it being a Double.
        column.put(yBucket, value);

        if (value > max)
            max = value;
    }

    return max;
}

From source file:com.wei.c.im.test.msg.client.MsgListHelper.java

public static synchronized void loadSendMsgBeansToMap(ContentResolver resolver, long mid, long uid,
        LongSparseArray<MsgBean> mapSend, long targetOrderNum, int count) {
    checkUIDs(mid, uid);/* w w  w. j  a  v a  2s.  c  o m*/
    if (targetOrderNum < 0)
        targetOrderNum = ContentHelper.getMaxOrderNumSendOrReceived(resolver, mid, uid) - count;

    Cursor cursorSend = ContentHelper.MSG_SEND.getCursorOrderNumDesc(resolver, mid, uid);
    if (cursorSend != null) {
        while (cursorSend.moveToNext()) {
            long orderNum = cursorSend.getLong(cursorSend.getColumnIndex(MSG.DbColumns.MsgSend._ORDER_NUM));
            if (orderNum <= targetOrderNum) {
                break;
            }
            long id = cursorSend.getLong(cursorSend.getColumnIndex(MSG.DbColumns.MsgSend._ID));
            int ctype = cursorSend.getInt(cursorSend.getColumnIndex(MSG.DbColumns.MsgSend._TYPE_CONTENT));
            String content = cursorSend.getString(cursorSend.getColumnIndex(MSG.DbColumns.MsgSend._CONTENT));
            int arriveState = cursorSend.getInt(cursorSend.getColumnIndex(MSG.DbColumns.MsgSend._ARRIVE_STATE));
            MsgBean bean = new MsgBean(id, MsgBean.TYPE_ME, ctype, content, orderNum, 0, arriveState);
            bean.timeSend = cursorSend.getLong(cursorSend.getColumnIndex(MSG.DbColumns.MsgSend._TIME_LOCAL));
            mapSend.put(bean.id, bean);
        }
        cursorSend.close();
    }
}

From source file:com.topfeeds4j.sample.utils.Prefs.java

/**
 * Get all blogger meta information./* w ww.j  a  v  a 2  s .c o m*/
 *
 * @return A list of [blogger-id : blogger-name].
 */
public LongSparseArray<String> getBloggersMeta() {
    LongSparseArray<String> lst = new LongSparseArray<>();
    String ids = getString(KEY_BLOGGER_ID_LIST, null);
    String names = getString(KEY_BLOGGER_NAME_LIST, null);
    String[] idList = ids.split(",");
    String[] nameList = names.split(",");
    int i = 0;
    for (String id : idList) {
        lst.put(Long.valueOf(id), nameList[i++]);
    }
    return lst;
}