android.util.SparseLongArray Java Examples

The following examples show how to use android.util.SparseLongArray. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CacheQuotaStrategy.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public CacheQuotaStrategy(
        Context context, UsageStatsManagerInternal usageStatsManager, Installer installer,
        ArrayMap<String, SparseLongArray> quotaMap) {
    mContext = Preconditions.checkNotNull(context);
    mUsageStats = Preconditions.checkNotNull(usageStatsManager);
    mInstaller = Preconditions.checkNotNull(installer);
    mQuotaMap = Preconditions.checkNotNull(quotaMap);
    mPreviousValuesFile = new AtomicFile(new File(
            new File(Environment.getDataDirectory(), "system"), "cachequota.xml"));
}
 
Example #2
Source File: StringUtils.java    From XKnife-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 判断对象是否为空
 *
 * @param obj 对象
 * @return {@code true}: 为空<br>{@code false}: 不为空
 */
public static boolean isEmpty(Object obj) {
    if (obj == null) {
        return true;
    }
    if (obj instanceof String && obj.toString().length() == 0) {
        return true;
    }
    if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
        return true;
    }
    if (obj instanceof Collection && ((Collection) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof Map && ((Map) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof SparseArray && ((SparseArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseBooleanArray && ((SparseBooleanArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseIntArray && ((SparseIntArray) obj).size() == 0) {
        return true;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (obj instanceof SparseLongArray && ((SparseLongArray) obj).size() == 0) {
            return true;
        }
    }
    return false;
}
 
Example #3
Source File: EmptyUtils.java    From Android-UtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * 判断对象是否为空
 *
 * @param obj 对象
 * @return {@code true}: 为空<br>{@code false}: 不为空
 */
public static boolean isEmpty(Object obj) {
    if (obj == null) {
        return true;
    }
    if (obj instanceof String && obj.toString().length() == 0) {
        return true;
    }
    if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
        return true;
    }
    if (obj instanceof Collection && ((Collection) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof Map && ((Map) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof SparseArray && ((SparseArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseBooleanArray && ((SparseBooleanArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseIntArray && ((SparseIntArray) obj).size() == 0) {
        return true;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (obj instanceof SparseLongArray && ((SparseLongArray) obj).size() == 0) {
            return true;
        }
    }
    return false;
}
 
Example #4
Source File: EmptyUtilsTest.java    From Android-UtilCode with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Test
public void isEmpty() throws Exception {
    String string = "";
    String string1 = " ";
    int[][] arr = new int[][]{};
    int[] arr1 = null;
    LinkedList<Integer> list = new LinkedList<>();
    HashMap<String,Integer> map = new HashMap<>();
    SparseArray<String> sa = new SparseArray<>();
    SparseBooleanArray sba = new SparseBooleanArray();
    SparseIntArray sia = new SparseIntArray();
    SparseLongArray sla = new SparseLongArray();

    assertThat(EmptyUtils.isEmpty(string)).isTrue();
    assertThat(EmptyUtils.isEmpty(string1)).isFalse();
    assertThat(EmptyUtils.isEmpty(arr)).isTrue();
    assertThat(EmptyUtils.isEmpty(arr1)).isTrue();
    assertThat(EmptyUtils.isEmpty(list)).isTrue();
    assertThat(EmptyUtils.isEmpty(map)).isTrue();
    assertThat(EmptyUtils.isEmpty(sa)).isTrue();
    assertThat(EmptyUtils.isEmpty(sba)).isTrue();
    assertThat(EmptyUtils.isEmpty(sia)).isTrue();
    assertThat(EmptyUtils.isEmpty(sla)).isTrue();

    assertThat(!EmptyUtils.isNotEmpty(string)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(string1)).isFalse();
    assertThat(!EmptyUtils.isNotEmpty(arr)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(arr1)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(list)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(map)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(sa)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(sba)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(sia)).isTrue();
    assertThat(!EmptyUtils.isNotEmpty(sla)).isTrue();
}
 
Example #5
Source File: RxDataTool.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
/**
 * 判断对象是否为空
 *
 * @param obj 对象
 * @return {@code true}: 为空<br>{@code false}: 不为空
 */
public static boolean isEmpty(Object obj) {
    if (obj == null) {
        return true;
    }
    if (obj instanceof String && obj.toString().length() == 0) {
        return true;
    }
    if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
        return true;
    }
    if (obj instanceof Collection && ((Collection) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof Map && ((Map) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof SparseArray && ((SparseArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseBooleanArray && ((SparseBooleanArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseIntArray && ((SparseIntArray) obj).size() == 0) {
        return true;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (obj instanceof SparseLongArray && ((SparseLongArray) obj).size() == 0) {
            return true;
        }
    }
    return false;
}
 
Example #6
Source File: XEmptyUtils.java    From XFrame with Apache License 2.0 5 votes vote down vote up
/**
 * 判断对象是否为null或长度数量为0
 *
 * @param obj 对象
 * @return {@code true}: 为空<br>{@code false}: 不为空
 */
public static boolean isEmpty(Object obj) {
    if (obj == null) {
        return true;
    }
    if (obj instanceof String && obj.toString().length() == 0) {
        return true;
    }
    if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
        return true;
    }
    if (obj instanceof Collection && ((Collection) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof Map && ((Map) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof SparseArray && ((SparseArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseBooleanArray && ((SparseBooleanArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseIntArray && ((SparseIntArray) obj).size() == 0) {
        return true;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (obj instanceof SparseLongArray && ((SparseLongArray) obj).size() == 0) {
            return true;
        }
    }
    return false;
}
 
Example #7
Source File: DeviceClient.java    From SensorDashboard with Apache License 2.0 5 votes vote down vote up
private DeviceClient(Context context) {
    this.context = context;

    googleApiClient = new GoogleApiClient.Builder(context).addApi(Wearable.API).build();

    executorService = Executors.newCachedThreadPool();
    lastSensorData = new SparseLongArray();
}
 
Example #8
Source File: PersistentDataStore.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public BrightnessConfigurations() {
    mConfigurations = new SparseArray<>();
    mTimeStamps = new SparseLongArray();
    mPackageNames = new SparseArray<>();
}
 
Example #9
Source File: EmptyUtils.java    From timecat with Apache License 2.0 4 votes vote down vote up
/**
 * 判断对象是否为空
 *
 * @param obj 对象
 * @return {@code true}: 为空<br>{@code false}: 不为空
 */
public static boolean isEmpty(final Object obj) {
    if (obj == null) {
        return true;
    }
    if (obj instanceof String && obj.toString().length() == 0) {
        return true;
    }
    if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
        return true;
    }
    if (obj instanceof Collection && ((Collection) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof Map && ((Map) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof SimpleArrayMap && ((SimpleArrayMap) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof SparseArray && ((SparseArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseBooleanArray && ((SparseBooleanArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseIntArray && ((SparseIntArray) obj).size() == 0) {
        return true;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (obj instanceof SparseLongArray && ((SparseLongArray) obj).size() == 0) {
            return true;
        }
    }
    if (obj instanceof LongSparseArray && ((LongSparseArray) obj).size() == 0) {
        return true;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (obj instanceof android.util.LongSparseArray && ((android.util.LongSparseArray) obj).size() == 0) {
            return true;
        }
    }
    return false;
}
 
Example #10
Source File: ScriptContext.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private HashMap<Class,IteratorFactory> lazyIteratorFactories(){
    if(iterators==null){
        iterators=new HashMap<>();
        IteratorFactory factory= v -> {
            int length;
            length = length(v);
            Method keyAt=v.getClass().getMethod("keyAt",int.class);
            Method valueAt=v.getClass().getMethod("valueAt",int.class);
            return new MapIterator() {
                int i;
                @Override
                public Object[] nextEntry() throws Throwable{
                    return new Object[]{keyAt.invoke(v,i),valueAt.invoke(v,i++)};
                }

                @Override
                public boolean hasNext() {
                    return i<length;
                }
            };
        };
        iterators.put(SparseArray.class, factory);
        iterators.put(SparseBooleanArray.class, factory);
        iterators.put(SparseIntArray.class, factory);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            iterators.put(SparseLongArray.class, factory);
        }
        iterators.put(JSONObject.class, (IteratorFactory<JSONObject>) v -> {
            Iterator<String> iterator=v.keys();
            return new MapIterator() {
                @Override
                public boolean hasNext() {
                    return iterator.hasNext();
                }

                @Override
                public Object[] nextEntry() throws Throwable {
                    String key=iterator.next();
                    return new Object[]{key,v.get(key)};
                }
            };
        });

    }
    return iterators;
}
 
Example #11
Source File: ObjectUtils.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
/**
 * Return whether object is empty.
 *
 * @param obj The object.
 * @return {@code true}: yes<br>{@code false}: no
 */
public static boolean isEmpty(final Object obj) {
    if (obj == null) {
        return true;
    }
    if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
        return true;
    }
    if (obj instanceof CharSequence && obj.toString().length() == 0) {
        return true;
    }
    if (obj instanceof Collection && ((Collection) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof Map && ((Map) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof SimpleArrayMap && ((SimpleArrayMap) obj).isEmpty()) {
        return true;
    }
    if (obj instanceof SparseArray && ((SparseArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseBooleanArray && ((SparseBooleanArray) obj).size() == 0) {
        return true;
    }
    if (obj instanceof SparseIntArray && ((SparseIntArray) obj).size() == 0) {
        return true;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (obj instanceof SparseLongArray && ((SparseLongArray) obj).size() == 0) {
            return true;
        }
    }
    if (obj instanceof LongSparseArray && ((LongSparseArray) obj).size() == 0) {
        return true;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (obj instanceof android.util.LongSparseArray
                && ((android.util.LongSparseArray) obj).size() == 0) {
            return true;
        }
    }
    return false;
}
 
Example #12
Source File: ObjectUtils.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
public static boolean isEmpty(final SparseLongArray obj) {
    return obj == null || obj.size() == 0;
}
 
Example #13
Source File: ObjectUtils.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
public static boolean isNotEmpty(final SparseLongArray obj) {
    return !isEmpty(obj);
}
 
Example #14
Source File: ObjectUtilsTest.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
@Test
public void isEmpty() {
    StringBuilder sb = new StringBuilder("");
    StringBuilder sb1 = new StringBuilder(" ");
    String string = "";
    String string1 = " ";
    int[][] arr = new int[][]{};
    LinkedList<Integer> list = new LinkedList<>();
    HashMap<String, Integer> map = new HashMap<>();
    SimpleArrayMap<String, Integer> sam = new SimpleArrayMap<>();
    SparseArray<String> sa = new SparseArray<>();
    SparseBooleanArray sba = new SparseBooleanArray();
    SparseIntArray sia = new SparseIntArray();
    SparseLongArray sla = new SparseLongArray();
    LongSparseArray<String> lsa = new LongSparseArray<>();
    android.util.LongSparseArray<String> lsaV4 = new android.util.LongSparseArray<>();

    assertTrue(ObjectUtils.isEmpty(sb));
    assertFalse(ObjectUtils.isEmpty(sb1));
    assertTrue(ObjectUtils.isEmpty(string));
    assertFalse(ObjectUtils.isEmpty(string1));
    assertTrue(ObjectUtils.isEmpty(arr));
    assertTrue(ObjectUtils.isEmpty(list));
    assertTrue(ObjectUtils.isEmpty(map));
    assertTrue(ObjectUtils.isEmpty(sam));
    assertTrue(ObjectUtils.isEmpty(sa));
    assertTrue(ObjectUtils.isEmpty(sba));
    assertTrue(ObjectUtils.isEmpty(sia));
    assertTrue(ObjectUtils.isEmpty(sla));
    assertTrue(ObjectUtils.isEmpty(lsa));
    assertTrue(ObjectUtils.isEmpty(lsaV4));

    assertTrue(!ObjectUtils.isNotEmpty(sb));
    assertFalse(!ObjectUtils.isNotEmpty(sb1));
    assertTrue(!ObjectUtils.isNotEmpty(string));
    assertFalse(!ObjectUtils.isNotEmpty(string1));
    assertTrue(!ObjectUtils.isNotEmpty(arr));
    assertTrue(!ObjectUtils.isNotEmpty(list));
    assertTrue(!ObjectUtils.isNotEmpty(map));
    assertTrue(!ObjectUtils.isNotEmpty(sam));
    assertTrue(!ObjectUtils.isNotEmpty(sa));
    assertTrue(!ObjectUtils.isNotEmpty(sba));
    assertTrue(!ObjectUtils.isNotEmpty(sia));
    assertTrue(!ObjectUtils.isNotEmpty(sla));
    assertTrue(!ObjectUtils.isNotEmpty(lsa));
    assertTrue(!ObjectUtils.isNotEmpty(lsaV4));
}
 
Example #15
Source File: SparseLongArrayAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public SparseLongArrayAssert(SparseLongArray actual) {
  super(actual, SparseLongArrayAssert.class);
}