import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
+import com.google.common.annotations.Beta;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
// resolveRpcInputClass() check.While RpcMethodInvoker counts with one argument for
// non input type and two arguments for input type, resolveRpcInputClass() counting
// with zero for non input and one for input type
- && possibleMethod.getParameterTypes().length <= 2;
+ && possibleMethod.getParameterCount() <= 2;
}
/**
*/
public static boolean isNotificationCallback(final Method method) {
checkArgument(method != null);
- if (method.getName().startsWith("on") && method.getParameterTypes().length == 1) {
+ if (method.getName().startsWith("on") && method.getParameterCount() == 1) {
Class<?> potentialNotification = method.getParameterTypes()[0];
if (isNotification(potentialNotification)
&& method.getName().equals("on" + potentialNotification.getSimpleName())) {
checkArgument(DataContainer.class.isAssignableFrom(type), "Supplied type must be derived from DataContainer");
List<Class<? extends DataObject>> ret = new LinkedList<>();
for (Method method : type.getMethods()) {
- Optional<Class<? extends DataContainer>> entity = getYangModeledReturnType(method);
+ Optional<Class<? extends DataContainer>> entity = getYangModeledReturnType(method,
+ BindingMapping.GETTER_PREFIX);
if (entity.isPresent()) {
ret.add((Class<? extends DataObject>) entity.get());
}
* @return Iterable of all data children, which have YANG modeled entity
*/
public static Map<Class<?>, Method> getChildrenClassToMethod(final Class<?> type) {
+ return getChildrenClassToMethod(type, BindingMapping.GETTER_PREFIX);
+ }
+
+ private static Map<Class<?>, Method> getChildrenClassToMethod(final Class<?> type, final String prefix) {
checkArgument(type != null, "Target type must not be null");
checkArgument(DataContainer.class.isAssignableFrom(type), "Supplied type %s must be derived from DataContainer",
type);
Map<Class<?>, Method> ret = new HashMap<>();
for (Method method : type.getMethods()) {
- Optional<Class<? extends DataContainer>> entity = getYangModeledReturnType(method);
+ Optional<Class<? extends DataContainer>> entity = getYangModeledReturnType(method, prefix);
if (entity.isPresent()) {
ret.put(entity.get(), method);
}
return ret;
}
+ @Beta
+ public static Map<Class<?>, Method> getChildrenClassToNonnullMethod(final Class<?> type) {
+ return getChildrenClassToMethod(type, BindingMapping.NONNULL_PREFIX);
+ }
+
@SuppressWarnings({ "unchecked", "rawtypes", "checkstyle:illegalCatch" })
- private static Optional<Class<? extends DataContainer>> getYangModeledReturnType(final Method method) {
- if ("getClass".equals(method.getName()) || !method.getName().startsWith("get")
- || method.getParameterTypes().length > 0) {
+ private static Optional<Class<? extends DataContainer>> getYangModeledReturnType(final Method method,
+ final String prefix) {
+ final String methodName = method.getName();
+ if ("getClass".equals(methodName) || !methodName.startsWith(prefix) || method.getParameterCount() > 0) {
return Optional.empty();
}
Class returnType = method.getReturnType();
if (DataContainer.class.isAssignableFrom(returnType)) {
return Optional.of(returnType);
- } else if (List.class.isAssignableFrom(returnType)) {
+ }
+ if (List.class.isAssignableFrom(returnType)) {
try {
return ClassLoaderUtils.callWithClassLoader(method.getDeclaringClass().getClassLoader(), () -> {
Type listResult = ClassLoaderUtils.getFirstGenericParameter(method.getGenericReturnType());
- if (listResult instanceof Class
- && DataContainer.class.isAssignableFrom((Class) listResult)) {
+ if (listResult instanceof Class && DataContainer.class.isAssignableFrom((Class) listResult)) {
return Optional.of((Class) listResult);
}
return Optional.empty();