本文整理汇总了Java中com.android.internal.util.Predicate类的典型用法代码示例。如果您正苦于以下问题:Java Predicate类的具体用法?Java Predicate怎么用?Java Predicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Predicate类属于com.android.internal.util包,在下文中一共展示了Predicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRemoveAll
import com.android.internal.util.Predicate; //导入依赖的package包/类
@Test
public void testRemoveAll() {
mCountingLruMap.put("key1", 110);
mCountingLruMap.put("key2", 120);
mCountingLruMap.put("key3", 130);
mCountingLruMap.put("key4", 140);
mCountingLruMap.removeAll(
new Predicate<String>() {
@Override
public boolean apply(String key) {
return key.equals("key2") || key.equals("key3");
}
});
assertEquals(2, mCountingLruMap.getCount());
assertEquals(250, mCountingLruMap.getSizeInBytes());
assertKeyOrder("key1", "key4");
assertValueOrder(110, 140);
}
示例2: testGetMatchingEntries
import com.android.internal.util.Predicate; //导入依赖的package包/类
@Test
public void testGetMatchingEntries() {
mCountingLruMap.put("key1", 110);
mCountingLruMap.put("key2", 120);
mCountingLruMap.put("key3", 130);
mCountingLruMap.put("key4", 140);
List<LinkedHashMap.Entry<String, Integer>> entries = mCountingLruMap.getMatchingEntries(
new Predicate<String>() {
@Override
public boolean apply(String key) {
return key.equals("key2") || key.equals("key3");
}
});
assertNotNull(entries);
assertEquals(2, entries.size());
assertEquals("key2", entries.get(0).getKey());
assertEquals(120, (int) entries.get(0).getValue());
assertEquals("key3", entries.get(1).getKey());
assertEquals(130, (int) entries.get(1).getValue());
// getting entries should not affect the order nor the size
assertEquals(4, mCountingLruMap.getCount());
assertEquals(500, mCountingLruMap.getSizeInBytes());
assertKeyOrder("key1", "key2", "key3", "key4");
assertValueOrder(110, 120, 130, 140);
}
示例3: findChild
import com.android.internal.util.Predicate; //导入依赖的package包/类
private static View findChild(View root, Predicate<View> predicate) {
if (predicate.apply(root)) {
return root;
}
if (root instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) root;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View child = viewGroup.getChildAt(i);
View result = findChild(child, predicate);
if (result != null) {
return result;
}
}
}
return null;
}
示例4: inBackground
import com.android.internal.util.Predicate; //导入依赖的package包/类
@Override
protected boolean inBackground(boolean isRefresh, final ICatalogItem catalogItem) throws Throwable {
if (mCatalogData.size() == 0)
mCatalogData = AppsGamesCatalogApi.getCatalog(Client.getInstance(), (AppGameCatalog) m_CurrentCatalogItem);
if (catalogItem.getParent() != null && catalogItem.getId().equals(catalogItem.getParent().getId()))
return false;
mLoadResultList = getFilteredList(new Predicate<AppGameCatalog>() {
@Override
public boolean apply(AppGameCatalog catalog) {
return catalog.getParent() != null && catalog.getParent().getId().equals(catalogItem.getId());
}
});
return !(mCatalogData.size() > 0 && mLoadResultList.size() == 0);
}
示例5: inBackground
import com.android.internal.util.Predicate; //导入依赖的package包/类
@Override
protected boolean inBackground(boolean isRefresh, final ICatalogItem catalogItem) throws Throwable {
if (mCatalogData.size() == 0)
mCatalogData = DigestApi.getCatalog(Client.getInstance(), (DigestCatalog) m_CurrentCatalogItem);
if (((DigestCatalog) catalogItem).getLevel() == DigestCatalog.LEVEL_TOPICS_NEXT)
return false;
mLoadResultList = getFilteredList(new Predicate<DigestCatalog>() {
@Override
public boolean apply(DigestCatalog catalog) {
return catalog.getParent() != null && catalog.getParent().getId().equals(catalogItem.getId());
}
});
if (mCatalogData.size() > 0 && mLoadResultList.size() == 0)
return false;
return true;
}
示例6: findViewByPredicateInsideOut
import com.android.internal.util.Predicate; //导入依赖的package包/类
/**
* {@hide}
* Look for a child view that matches the specified predicate,
* starting with the specified view and its descendents and then
* recusively searching the ancestors and siblings of that view
* until this view is reached.
*
* This method is useful in cases where the predicate does not match
* a single unique view (perhaps multiple views use the same id)
* and we are trying to find the view that is "closest" in scope to the
* starting view.
*
* @param start The view to start from.
* @param predicate The predicate to evaluate.
* @return The first view that matches the predicate or null.
*/
public final View findViewByPredicateInsideOut(View start, Predicate<View> predicate) {
View childToSkip = null;
for (;;) {
View view = start.findViewByPredicateTraversal(predicate, childToSkip);
if (view != null || start == this) {
return view;
}
ViewParent parent = start.getParent();
if (parent == null || !(parent instanceof View)) {
return null;
}
childToSkip = start;
start = (View) parent;
}
}
示例7: tossOne
import com.android.internal.util.Predicate; //导入依赖的package包/类
T tossOne(Predicate<T> predicate) {
List<T> filtered;
if (predicate == null) {
filtered = getSamples();
} else {
filtered = new ArrayList<>();
for (T i : getSamples()) {
if (predicate.apply(i)) {
filtered.add(i);
}
}
}
if (filtered.size() <= 0) {
throw new IllegalArgumentException("No samples found that match the predicate");
}
int idx = mRandom.nextInt(filtered.size());
return filtered.get(idx);
}
示例8: showProgressDialogWhile
import com.android.internal.util.Predicate; //导入依赖的package包/类
public static void showProgressDialogWhile(final Context context, final Predicate<Void> predicate, final Runnable callback) {
if (predicate.apply(null)) {
callback.run();
} else {
final ProgressDialog progressDialog = showProgressDialog(context);
Runnable predicateVerifier = new Runnable() {
public void run() {
if (predicate.apply(null)) {
Tasks.runDelayed(this, 100);
} else {
progressDialog.dismiss();
callback.run();
}
}
};
Tasks.runDelayed(predicateVerifier, 100);
}
}
示例9: True
import com.android.internal.util.Predicate; //导入依赖的package包/类
public static <T> Predicate<T> True() {
return new Predicate<T>() {
@Override
public boolean apply(T t) {
return true;
}
};
}
示例10: False
import com.android.internal.util.Predicate; //导入依赖的package包/类
public static <T> Predicate<T> False() {
return new Predicate<T>() {
@Override
public boolean apply(T t) {
return false;
}
};
}
示例11: removeAll
import com.android.internal.util.Predicate; //导入依赖的package包/类
/**
* Removes all the items from the cache whose key matches the specified predicate.
*
* @param predicate returns true if an item with the given key should be removed
* @return number of the items removed from the cache
*/
public int removeAll(Predicate<K> predicate) {
ArrayList<Entry<K, V>> oldExclusives;
ArrayList<Entry<K, V>> oldEntries;
synchronized (this) {
oldExclusives = mExclusiveEntries.removeAll(predicate);
oldEntries = mCachedEntries.removeAll(predicate);
makeOrphans(oldEntries);
}
maybeClose(oldEntries);
maybeNotifyExclusiveEntryRemoval(oldExclusives);
maybeUpdateCacheParams();
maybeEvictEntries();
return oldEntries.size();
}
示例12: getMatchingEntries
import com.android.internal.util.Predicate; //导入依赖的package包/类
/** Gets the all matching elements. */
public synchronized ArrayList<LinkedHashMap.Entry<K, V>> getMatchingEntries(
@Nullable Predicate<K> predicate) {
ArrayList<LinkedHashMap.Entry<K, V>> matchingEntries = new ArrayList<>(mMap.entrySet().size());
for (LinkedHashMap.Entry<K, V> entry : mMap.entrySet()) {
if (predicate == null || predicate.apply(entry.getKey())) {
matchingEntries.add(entry);
}
}
return matchingEntries;
}
示例13: removeAll
import com.android.internal.util.Predicate; //导入依赖的package包/类
/** Removes all the matching elements from the map. */
public synchronized ArrayList<V> removeAll(@Nullable Predicate<K> predicate) {
ArrayList<V> oldValues = new ArrayList<>();
Iterator<LinkedHashMap.Entry<K, V>> iterator = mMap.entrySet().iterator();
while (iterator.hasNext()) {
LinkedHashMap.Entry<K, V> entry = iterator.next();
if (predicate == null || predicate.apply(entry.getKey())) {
oldValues.add(entry.getValue());
mSizeInBytes -= getValueSizeInBytes(entry.getValue());
iterator.remove();
}
}
return oldValues;
}
示例14: clearMemoryCaches
import com.android.internal.util.Predicate; //导入依赖的package包/类
/**
* Clear the memory caches
*/
public void clearMemoryCaches() {
Predicate<CacheKey> allPredicate =
new Predicate<CacheKey>() {
@Override
public boolean apply(CacheKey key) {
return true;
}
};
mBitmapMemoryCache.removeAll(allPredicate);
mEncodedMemoryCache.removeAll(allPredicate);
}
示例15: isInBitmapMemoryCache
import com.android.internal.util.Predicate; //导入依赖的package包/类
/**
* Returns whether the image is stored in the bitmap memory cache.
*
* @param uri the uri for the image to be looked up.
* @return true if the image was found in the bitmap memory cache, false otherwise
*/
public boolean isInBitmapMemoryCache(final Uri uri) {
if (uri == null) {
return false;
}
Predicate<CacheKey> bitmapCachePredicate = predicateForUri(uri);
return mBitmapMemoryCache.contains(bitmapCachePredicate);
}