Java Code Examples for org.gradle.util.CollectionUtils#findFirst()

The following examples show how to use org.gradle.util.CollectionUtils#findFirst() . 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: EnumFromCharSequenceNotationParser.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public T parseNotation(CharSequence notation) throws UnsupportedNotationException, TypeConversionException {
    final String enumString = notation.toString();
    List<? extends T> enumConstants = Arrays.asList(type.getEnumConstants());
    T match = CollectionUtils.findFirst(enumConstants, new Spec<T>() {
        public boolean isSatisfiedBy(T enumValue) {
            return enumValue.name().equalsIgnoreCase(enumString);
        }
    });
    if (match == null) {
        throw new TypeConversionException(
                String.format("Cannot coerce string value '%s' to an enum value of type '%s' (valid case insensitive values: %s)",
                        enumString, type.getName(), CollectionUtils.toStringList(Arrays.asList(type.getEnumConstants()))
                )
        );
    } else {
        return match;
    }
}
 
Example 2
Source File: EnumFromCharSequenceNotationParser.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public T parseNotation(CharSequence notation) throws UnsupportedNotationException, TypeConversionException {
    final String enumString = notation.toString();
    List<T> enumConstants = Arrays.asList(type.getEnumConstants());
    T match = CollectionUtils.findFirst(enumConstants, new Spec<T>() {
        public boolean isSatisfiedBy(T enumValue) {
            return enumValue.name().equalsIgnoreCase(enumString);
        }
    });
    if (match == null) {
        throw new TypeConversionException(
                String.format("Cannot coerce string value '%s' to an enum value of type '%s' (valid case insensitive values: %s)",
                        enumString, type.getName(), CollectionUtils.toStringList(Arrays.asList(type.getEnumConstants()))
                )
        );
    } else {
        return match;
    }
}
 
Example 3
Source File: EnumFromCharSequenceNotationParser.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public T parseNotation(CharSequence notation) throws UnsupportedNotationException, TypeConversionException {
    final String enumString = notation.toString();
    List<? extends T> enumConstants = Arrays.asList(type.getEnumConstants());
    T match = CollectionUtils.findFirst(enumConstants, new Spec<T>() {
        public boolean isSatisfiedBy(T enumValue) {
            return enumValue.name().equalsIgnoreCase(enumString);
        }
    });
    if (match == null) {
        throw new TypeConversionException(
                String.format("Cannot coerce string value '%s' to an enum value of type '%s' (valid case insensitive values: %s)",
                        enumString, type.getName(), CollectionUtils.toStringList(Arrays.asList(type.getEnumConstants()))
                )
        );
    } else {
        return match;
    }
}
 
Example 4
Source File: EnumFromCharSequenceNotationParser.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public T parseNotation(CharSequence notation) throws UnsupportedNotationException, TypeConversionException {
    final String enumString = notation.toString();
    List<T> enumConstants = Arrays.asList(type.getEnumConstants());
    T match = CollectionUtils.findFirst(enumConstants, new Spec<T>() {
        public boolean isSatisfiedBy(T enumValue) {
            return enumValue.name().equalsIgnoreCase(enumString);
        }
    });
    if (match == null) {
        throw new TypeConversionException(
                String.format("Cannot coerce string value '%s' to an enum value of type '%s' (valid case insensitive values: %s)",
                        enumString, type.getName(), CollectionUtils.toStringList(Arrays.asList(type.getEnumConstants()))
                )
        );
    } else {
        return match;
    }
}
 
Example 5
Source File: JavaReflectionUtil.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 6
Source File: ModelRegistry.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void closeChild(Object parent, ModelPath childPath) {
    try {
        String fieldName = childPath.getName();
        final String setterName = String.format("set%s%s", fieldName.substring(0, 1).toUpperCase(), fieldName.substring(1));
        Method setter = CollectionUtils.findFirst(parent.getClass().getDeclaredMethods(), new Spec<Method>() {
            public boolean isSatisfiedBy(Method method) {
                return method.getName().equals(setterName);
            }
        });
        setter.invoke(parent, get(childPath));
    } catch (Exception e) {
        throw new GradleException("Could not close model element children", e);
    }
}
 
Example 7
Source File: JavaReflectionUtil.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 8
Source File: JavaReflectionUtil.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 9
Source File: ModelRegistry.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void closeChild(Object parent, ModelPath childPath) {
    try {
        String fieldName = childPath.getName();
        final String setterName = String.format("set%s%s", fieldName.substring(0, 1).toUpperCase(), fieldName.substring(1));
        Method setter = CollectionUtils.findFirst(parent.getClass().getDeclaredMethods(), new Spec<Method>() {
            public boolean isSatisfiedBy(Method method) {
                return method.getName().equals(setterName);
            }
        });
        setter.invoke(parent, get(childPath));
    } catch (Exception e) {
        throw new GradleException("Could not close model element children", e);
    }
}
 
Example 10
Source File: JavaReflectionUtil.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}