import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
-import com.google.common.base.Optional;
+import com.google.common.annotations.Beta;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.ServiceLoader;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.RegEx;
+import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
import org.opendaylight.yangtools.util.ClassLoaderUtils;
import org.opendaylight.yangtools.yang.binding.Action;
import org.opendaylight.yangtools.yang.binding.Augmentable;
import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.binding.BaseIdentity;
-import org.opendaylight.yangtools.yang.binding.BindingMapping;
import org.opendaylight.yangtools.yang.binding.ChildOf;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import org.opendaylight.yangtools.yang.binding.DataObject;
* have name. May return null if QName is not present.
*/
public static QName findQName(final Class<?> dataType) {
- return CLASS_TO_QNAME.getUnchecked(dataType).orNull();
+ return CLASS_TO_QNAME.getUnchecked(dataType).orElse(null);
}
/**
// 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;
}
/**
*
* @param targetMethod
* method to scan
- * @return Optional.absent() if result type could not be get, or return type is Void.
+ * @return Optional.empty() if result type could not be get, or return type is Void.
*/
@SuppressWarnings("rawtypes")
public static Optional<Class<?>> resolveRpcOutputClass(final Method targetMethod) {
if (rpcResultArgument instanceof Class && !Void.class.equals(rpcResultArgument)) {
return Optional.of((Class) rpcResultArgument);
}
- return Optional.absent();
+ return Optional.empty();
}
/**
*
* @param targetMethod
* method to scan
- * @return Optional.absent() if RPC has no input, RPC input type otherwise.
+ * @return Optional.empty() if RPC has no input, RPC input type otherwise.
*/
@SuppressWarnings("rawtypes")
public static Optional<Class<? extends DataContainer>> resolveRpcInputClass(final Method targetMethod) {
return Optional.of(clazz);
}
}
- return Optional.absent();
+ return Optional.empty();
}
public static QName getQName(final Class<? extends BaseIdentity> context) {
}
}
- /**
- * Extract a QNameModule from YangModuleInfo.
- *
- * @param modInfo Module info
- * @return QNameModule for the module
- * @throws NullPointerException in modInfo is null
- *
- * @deprecated Use {@code YangModuleInfo.getName().getModule()} instead.
- */
- @Deprecated
- public static QNameModule getQNameModule(final YangModuleInfo modInfo) {
- return modInfo.getName().getModule();
- }
-
/**
* Returns instance of {@link YangModuleInfo} of declaring model for specific class.
*
*/
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) {
- return Optional.absent();
+ 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.absent();
+ return Optional.empty();
});
} catch (Exception e) {
/*
LOG.debug("Unable to find YANG modeled return type for {}", method, e);
}
}
- return Optional.absent();
+ return Optional.empty();
}
private static class ClassToQNameLoader extends CacheLoader<Class<?>, Optional<QName>> {
*/
LOG.debug("Unexpected exception during extracting QName for {}", key, e);
}
- return Optional.absent();
+ return Optional.empty();
}
/**
}
}
- /**
- * Given a {@link YangModuleInfo}, create a QName representing it. The QName is formed by reusing the module's
- * namespace and revision using the module's name as the QName's local name.
- *
- * @param moduleInfo
- * module information
- * @return QName representing the module
- *
- * @deprecated Use {@link YangModuleInfo#getName()} instead.
- */
- @Deprecated
- public static QName getModuleQName(final YangModuleInfo moduleInfo) {
- checkArgument(moduleInfo != null, "moduleInfo must not be null.");
- return moduleInfo.getName();
- }
-
/**
* Extracts augmentation from Binding DTO field using reflection.
*