本文整理汇总了Java中com.heaven7.java.base.util.SparseArray.size方法的典型用法代码示例。如果您正苦于以下问题:Java SparseArray.size方法的具体用法?Java SparseArray.size怎么用?Java SparseArray.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.heaven7.java.base.util.SparseArray
的用法示例。
在下文中一共展示了SparseArray.size方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toJson
import com.heaven7.java.base.util.SparseArray; //导入方法依赖的package包/类
/**
* convert the target object to json. currently support simple object, array , list. SparseArray
* @param t the object. must have annotation {@linkplain JsonAdapter}
* @return the json string.
* @see SparseArray
*/
public static String toJson(Object t) {
GsonBuilder builder = new GsonBuilder()
.setVersion(GlobalSetting.getDefault().getGsonVersion());
if(t instanceof SparseArray){
SparseArray sa = (SparseArray) t;
if(sa.size() == 0){
return "{}";
}
Class<?> clazz = sa.valueAt(0).getClass();
/* builder.registerTypeAdapter(
TypeToken.getParameterized(SparseArray.class, clazz).getType(),
new SparseArrayTypeAdapter<>(TypeHandler.getTypeAdapter(clazz)));*/
builder.registerTypeAdapter(SparseArray.class,
new SparseArrayTypeAdapter<>(TypeHandler.getTypeAdapter(clazz)));
}
return builder.create().toJson(t);
}
示例2: write
import com.heaven7.java.base.util.SparseArray; //导入方法依赖的package包/类
@Override
public void write(JsonWriter out, GsonProperty property, Object value) throws IOException {
final Class<?> simpleType = property.getType();
out.beginObject();
if(value != null) {
final SparseArray sa = (SparseArray) value;
if(simpleType.isPrimitive() || isBoxedClass(simpleType)){
for (int size = sa.size(), i = size - 1; i >= 0; i--) {
out.name(sa.keyAt(i) + "");
writePrimitiveOrItsBox(out, simpleType, sa.valueAt(i));
}
}else {
TypeAdapter adapter = getTypeAdapter(simpleType);
for (int size = sa.size(), i = size - 1; i >= 0; i--) {
out.name(sa.keyAt(i) + "");
adapter.write(out, sa.valueAt(i));
}
}
}
out.endObject();
}
示例3: dispose
import com.heaven7.java.base.util.SparseArray; //导入方法依赖的package包/类
@Override
public final void dispose() {
// destroy foreground states.
if (mGlobalGroup != null) {
mGlobalGroup.dispose();
}
mGroup.dispose();
// destroy back/cache state. and clear
final SparseArray<S> map = this.mStateMap;
for (int size = map.size(), i = size - 1; i >= 0; i--) {
map.valueAt(i).dispose();
}
map.clear();
synchronized (this) {
if (mDelayMessages != null) {
for (MessageInfo info : mDelayMessages) {
info.msg.recycleUnchecked();
}
mDelayMessages.clear();
}
}
// clean up controller
this.mOwner = null;
}
示例4: write
import com.heaven7.java.base.util.SparseArray; //导入方法依赖的package包/类
@Override
public void write(JsonWriter out, SparseArray<T> value) throws IOException {
out.beginObject();
if(value != null) {
for (int size = value.size(), i = size - 1; i >= 0; i--) {
out.name(value.keyAt(i) + "");
mAdapter.write(out, value.valueAt(i));
}
}
out.endObject();
}
示例5: write
import com.heaven7.java.base.util.SparseArray; //导入方法依赖的package包/类
@Override
public void write(JsonWriter out, SparseArray<Car3> value) throws IOException {
out.beginObject();
if(value != null) {
for (int size = value.size(), i = size - 1; i >= 0; i--) {
out.name(value.keyAt(i) + "");
mAdapter.write(out, value.valueAt(i));
}
}
out.endObject();
}
示例6: writeSparseArray0
import com.heaven7.java.base.util.SparseArray; //导入方法依赖的package包/类
static void writeSparseArray0(Parcel in, SparseArray val) {
if (val == null) {
in.writeInt(-1);
return;
}
int N = val.size();
in.writeInt(N);
int i=0;
while (i < N) {
in.writeInt(val.keyAt(i));
in.writeValue(val.valueAt(i));
i++;
}
}