Java Code Examples for org.gradle.api.specs.Spec#isSatisfiedBy()

The following examples show how to use org.gradle.api.specs.Spec#isSatisfiedBy() . These examples are extracted from open source projects. 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
private static List<Method> findAllMethodsInternal(Class<?> target, Spec<Method> predicate, MultiMap<String, Method> seen, List<Method> collector, boolean stopAtFirst) {
    for (final Method method : target.getDeclaredMethods()) {
        List<Method> seenWithName = seen.get(method.getName());
        Method override = CollectionUtils.findFirst(seenWithName, new Spec<Method>() {
            public boolean isSatisfiedBy(Method potentionOverride) {
                return potentionOverride.getName().equals(method.getName())
                        && Arrays.equals(potentionOverride.getParameterTypes(), method.getParameterTypes());
            }
        });


        if (override == null) {
            seenWithName.add(method);
            if (predicate.isSatisfiedBy(method)) {
                collector.add(method);
                if (stopAtFirst) {
                    return collector;
                }
            }
        }
    }

    Class<?> parent = target.getSuperclass();
    if (parent != null) {
        return findAllMethodsInternal(parent, predicate, seen, collector, stopAtFirst);
    }

    return collector;
}
 
Example 2
public static <T> T findFirst(Iterable<? extends T> source, Spec<? super T> filter) {
    for (T item : source) {
        if (filter.isSatisfiedBy(item)) {
            return item;
        }
    }

    return null;
}
 
Example 3
public static <T> T findFirst(T[] source, Spec<? super T> filter) {
    for (T thing : source) {
        if (filter.isSatisfiedBy(thing)) {
            return thing;
        }
    }

    return null;
}
 
Example 4
public static <E> boolean replace(List<E> list, Spec<? super E> filter, Transformer<? extends E, ? super E> transformer) {
    boolean replaced = false;
    int i = 0;
    for (E it : list) {
        if (filter.isSatisfiedBy(it)) {
            list.set(i, transformer.transform(it));
            replaced = true;
        }
        ++i;
    }
    return replaced;
}
 
Example 5
public static <T> boolean every(Iterable<? extends T> things, Spec<? super T> predicate) {
    for (T thing : things) {
        if (!predicate.isSatisfiedBy(thing)) {
            return false;
        }
    }

    return true;
}
 
Example 6
private List<DaemonInfo> daemonInfosOfEntriesMatching(Spec<DaemonInfo> spec) {
    List<DaemonInfo> matches = new ArrayList<DaemonInfo>();
    for (DaemonInfo daemonInfo : daemonInfos.values()) {
        if (spec.isSatisfiedBy(daemonInfo)) {
            matches.add(daemonInfo);
        }
    }

    return matches;
}
 
Example 7
private <K, V extends Response<?>> V maybeFetch(String operationName, final PersistentIndexedCache<K, V> cache, final K key, Factory<V> factory, Spec<? super V> shouldFetch) {
    V cachedValue = cacheAccess.useCache(operationName + " - read", new Factory<V>() {
        public V create() {
            return cache.get(key);
        }
    });

    boolean fetch = cachedValue == null || shouldFetch.isSatisfiedBy(cachedValue);
    if (fetch) {
        return fetch(operationName, cache, key, factory);
    } else {
        return cachedValue;
    }
}
 
Example 8
public Set<ResolvedDependency> getFirstLevelModuleDependencies(Spec<? super Dependency> dependencySpec) {
    Set<ResolvedDependency> matches = new LinkedHashSet<ResolvedDependency>();
    for (Map.Entry<ModuleDependency, ResolvedDependency> entry : results.more().getFirstLevelDependencies().entrySet()) {
        if (dependencySpec.isSatisfiedBy(entry.getKey())) {
            matches.add(entry.getValue());
        }
    }
    return matches;
}
 
Example 9
public Set<T> findAll(Spec<? super T> constraint) {
    Set<T> matches = new HashSet<T>();
    for (T project : projects.values()) {
        if (constraint.isSatisfiedBy(project)) {
            matches.add(project);
        }
    }
    return matches;
}
 
Example 10
private static List<Method> findAllMethodsInternal(Class<?> target, Spec<Method> predicate, MultiMap<String, Method> seen, List<Method> collector, boolean stopAtFirst) {
    for (final Method method : target.getDeclaredMethods()) {
        List<Method> seenWithName = seen.get(method.getName());
        Method override = CollectionUtils.findFirst(seenWithName, new Spec<Method>() {
            public boolean isSatisfiedBy(Method potentionOverride) {
                return potentionOverride.getName().equals(method.getName())
                        && Arrays.equals(potentionOverride.getParameterTypes(), method.getParameterTypes());
            }
        });


        if (override == null) {
            seenWithName.add(method);
            if (predicate.isSatisfiedBy(method)) {
                collector.add(method);
                if (stopAtFirst) {
                    return collector;
                }
            }
        }
    }

    Class<?> parent = target.getSuperclass();
    if (parent != null) {
        return findAllMethodsInternal(parent, predicate, seen, collector, stopAtFirst);
    }

    return collector;
}
 
Example 11
public static <T> T findFirst(Iterable<? extends T> source, Spec<? super T> filter) {
    for (T item : source) {
        if (filter.isSatisfiedBy(item)) {
            return item;
        }
    }

    return null;
}
 
Example 12
public static <E> boolean replace(List<E> list, Spec<? super E> filter, Transformer<? extends E, ? super E> transformer) {
    boolean replaced = false;
    int i = 0;
    for (E it : list) {
        if (filter.isSatisfiedBy(it)) {
            list.set(i, transformer.transform(it));
            replaced = true;
        }
        ++i;
    }
    return replaced;
}
 
Example 13
public static <T> boolean every(Iterable<? extends T> things, Spec<? super T> predicate) {
    for (T thing : things) {
        if (!predicate.isSatisfiedBy(thing)) {
            return false;
        }
    }

    return true;
}
 
Example 14
private List<DaemonInfo> daemonInfosOfEntriesMatching(Spec<DaemonInfo> spec) {
    List<DaemonInfo> matches = new ArrayList<DaemonInfo>();
    for (DaemonInfo daemonInfo : daemonInfos.values()) {
        if (spec.isSatisfiedBy(daemonInfo)) {
            matches.add(daemonInfo);
        }
    }

    return matches;
}
 
Example 15
public Set<ResolvedDependency> getFirstLevelModuleDependencies(Spec<? super Dependency> dependencySpec) {
    Set<ResolvedDependency> matches = new LinkedHashSet<ResolvedDependency>();
    for (Map.Entry<ModuleDependency, ResolvedDependency> entry : results.more().getFirstLevelDependencies().entrySet()) {
        if (dependencySpec.isSatisfiedBy(entry.getKey())) {
            matches.add(entry.getValue());
        }
    }
    return matches;
}
 
Example 16
public Set<T> findAll(Spec<? super T> constraint) {
    Set<T> matches = new HashSet<T>();
    for (T project : projects.values()) {
        if (constraint.isSatisfiedBy(project)) {
            matches.add(project);
        }
    }
    return matches;
}
 
Example 17
Source Project: DexKnifePlugin   File: DexSplitTools.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isAtMainDex(
        Map<String, Boolean> mainCls, String sMapCls,
        ClassFileTreeElement treeElement, Spec<FileTreeElement> asSpec, boolean logFilter) {
    boolean isRecommend = false;

    // adt推荐
    if (mainCls != null) {
        Boolean value = mainCls.get(sMapCls);
        if (value != null) {
            isRecommend = value;
        }
    }

    // 全局过滤
    boolean inGlobalFilter = asSpec != null && asSpec.isSatisfiedBy(treeElement);

    if (logFilter) {
        String ret;
        if (isRecommend && inGlobalFilter) {
            ret = "true";
        } else if (isRecommend) {
            ret = "Recommend";
        } else if (inGlobalFilter) {
            ret = "Global";
        } else {
            ret = "false";
        }

        String s = "AtMainDex: " + treeElement.getPath() + " [" + ret + "]";

        if (isRecommend || inGlobalFilter) {
            System.err.println(s);
        } else {
            System.out.println(s);
        }
    }

    // 合并结果
    return isRecommend || inGlobalFilter;
}
 
Example 18
boolean isAllowed(FileTreeElement element, Spec<FileTreeElement> spec) {
    return spec.isSatisfiedBy(element);
}
 
Example 19
Source Project: DexKnifePlugin   File: DexSplitTools.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * get the maindexlist of android gradle plugin.
 * if enable ProGuard, return the mapped class.
 */
private static Map<String, Boolean> getRecommendMainDexClasses(
        File adtMainDexList,
        PatternSet mainDexPattern,
        boolean logFilter) throws Exception {

    if (adtMainDexList == null || !adtMainDexList.exists()) {
        System.err.println("DexKnife Warning: Android recommend Main dex is no exist.");
        return null;
    }

    HashMap<String, Boolean> mainCls = new HashMap<>();
    BufferedReader reader = new BufferedReader(new FileReader(adtMainDexList));

    ClassFileTreeElement treeElement = new ClassFileTreeElement();
    Spec<FileTreeElement> asSpec = mainDexPattern != null ? getMaindexSpec(mainDexPattern) : null;

    String line, clsPath;
    while ((line = reader.readLine()) != null) {
        line = line.trim();
        int clsPos = line.lastIndexOf(CLASS_SUFFIX);
        if (clsPos != -1) {
            boolean satisfiedBy = true;

            if (asSpec != null) {
                clsPath = line.substring(0, clsPos).replace('.', '/') + CLASS_SUFFIX;
                treeElement.setClassPath(clsPath);

                satisfiedBy = asSpec.isSatisfiedBy(treeElement);
                if (logFilter) {
                    System.out.println("DexKnife-Suggest: [" +
                            (satisfiedBy ? "Keep" : "Split") + "]  " + clsPath);
                }
            }

            mainCls.put(line, satisfiedBy);
        }
    }

    reader.close();

    if (mainCls.size() == 0) {
        mainCls = null;
    }

    return mainCls;
}
 
Example 20
boolean isAllowed(FileTreeElement element, Spec<FileTreeElement> spec) {
    return spec.isSatisfiedBy(element);
}