@Test(expected = NullPointerException.class) public void testReadDataWithTwoParams() { readData(mockedDataObject, DataObject.class); }
public static <T extends DataObject, P extends DataObject> Map<InstanceIdentifier<T>, T> readData( final P parent, final InstanceIdentifier<P> parentPath, final InstanceIdentifier<T> childPath) { checkArgument(parent != null, "Parent must not be null."); checkArgument(parentPath != null, "Parent path must not be null"); checkArgument(childPath != null, "Child path must not be null"); checkArgument(parentPath.containsWildcarded(childPath), "Parent object must be parent of child."); List<PathArgument> pathArgs = subList(parentPath.getPathArguments(), childPath.getPathArguments()); @SuppressWarnings("rawtypes") Map<InstanceIdentifier, DataContainer> lastFound = Collections.singletonMap(parentPath, parent); for (PathArgument pathArgument : pathArgs) { @SuppressWarnings("rawtypes") final ImmutableMap.Builder<InstanceIdentifier, DataContainer> potentialBuilder = ImmutableMap.builder(); for (@SuppressWarnings("rawtypes") Entry<InstanceIdentifier, DataContainer> entry : lastFound.entrySet()) { potentialBuilder.putAll(readData(entry, pathArgument)); } lastFound = potentialBuilder.build(); if (lastFound.isEmpty()) { return Collections.emptyMap(); } } @SuppressWarnings({ "unchecked", "rawtypes" }) final Map<InstanceIdentifier<T>, T> result = (Map) lastFound; return result; }
DataObjectReadingUtil { public static <T extends DataObject, P extends DataObject> Map<InstanceIdentifier<T>, T> readData( final P parent, final InstanceIdentifier<P> parentPath, final InstanceIdentifier<T> childPath) { checkArgument(parent != null, "Parent must not be null."); checkArgument(parentPath != null, "Parent path must not be null"); checkArgument(childPath != null, "Child path must not be null"); checkArgument(parentPath.containsWildcarded(childPath), "Parent object must be parent of child."); List<PathArgument> pathArgs = subList(parentPath.getPathArguments(), childPath.getPathArguments()); @SuppressWarnings("rawtypes") Map<InstanceIdentifier, DataContainer> lastFound = Collections.singletonMap(parentPath, parent); for (PathArgument pathArgument : pathArgs) { @SuppressWarnings("rawtypes") final ImmutableMap.Builder<InstanceIdentifier, DataContainer> potentialBuilder = ImmutableMap.builder(); for (@SuppressWarnings("rawtypes") Entry<InstanceIdentifier, DataContainer> entry : lastFound.entrySet()) { potentialBuilder.putAll(readData(entry, pathArgument)); } lastFound = potentialBuilder.build(); if (lastFound.isEmpty()) { return Collections.emptyMap(); } } @SuppressWarnings({ "unchecked", "rawtypes" }) final Map<InstanceIdentifier<T>, T> result = (Map) lastFound; return result; } }
DataObjectReadingUtil { public static <T extends DataObject, P extends DataObject> Map<InstanceIdentifier<T>, T> readData( final P parent, final InstanceIdentifier<P> parentPath, final InstanceIdentifier<T> childPath) { checkArgument(parent != null, "Parent must not be null."); checkArgument(parentPath != null, "Parent path must not be null"); checkArgument(childPath != null, "Child path must not be null"); checkArgument(parentPath.containsWildcarded(childPath), "Parent object must be parent of child."); List<PathArgument> pathArgs = subList(parentPath.getPathArguments(), childPath.getPathArguments()); @SuppressWarnings("rawtypes") Map<InstanceIdentifier, DataContainer> lastFound = Collections.singletonMap(parentPath, parent); for (PathArgument pathArgument : pathArgs) { @SuppressWarnings("rawtypes") final ImmutableMap.Builder<InstanceIdentifier, DataContainer> potentialBuilder = ImmutableMap.builder(); for (@SuppressWarnings("rawtypes") Entry<InstanceIdentifier, DataContainer> entry : lastFound.entrySet()) { potentialBuilder.putAll(readData(entry, pathArgument)); } lastFound = potentialBuilder.build(); if (lastFound.isEmpty()) { return Collections.emptyMap(); } } @SuppressWarnings({ "unchecked", "rawtypes" }) final Map<InstanceIdentifier<T>, T> result = (Map) lastFound; return result; } private  DataObjectReadingUtil(); }
DataObjectReadingUtil { public static <T extends DataObject, P extends DataObject> Map<InstanceIdentifier<T>, T> readData( final P parent, final InstanceIdentifier<P> parentPath, final InstanceIdentifier<T> childPath) { checkArgument(parent != null, "Parent must not be null."); checkArgument(parentPath != null, "Parent path must not be null"); checkArgument(childPath != null, "Child path must not be null"); checkArgument(parentPath.containsWildcarded(childPath), "Parent object must be parent of child."); List<PathArgument> pathArgs = subList(parentPath.getPathArguments(), childPath.getPathArguments()); @SuppressWarnings("rawtypes") Map<InstanceIdentifier, DataContainer> lastFound = Collections.singletonMap(parentPath, parent); for (PathArgument pathArgument : pathArgs) { @SuppressWarnings("rawtypes") final ImmutableMap.Builder<InstanceIdentifier, DataContainer> potentialBuilder = ImmutableMap.builder(); for (@SuppressWarnings("rawtypes") Entry<InstanceIdentifier, DataContainer> entry : lastFound.entrySet()) { potentialBuilder.putAll(readData(entry, pathArgument)); } lastFound = potentialBuilder.build(); if (lastFound.isEmpty()) { return Collections.emptyMap(); } } @SuppressWarnings({ "unchecked", "rawtypes" }) final Map<InstanceIdentifier<T>, T> result = (Map) lastFound; return result; } private  DataObjectReadingUtil(); static Map<InstanceIdentifier<T>, T> readData(
            final P parent, final InstanceIdentifier<P> parentPath, final InstanceIdentifier<T> childPath); static Optional<T> readData(final DataObject source, final Class<T> child); }
DataObjectReadingUtil { public static <T extends DataObject, P extends DataObject> Map<InstanceIdentifier<T>, T> readData( final P parent, final InstanceIdentifier<P> parentPath, final InstanceIdentifier<T> childPath) { checkArgument(parent != null, "Parent must not be null."); checkArgument(parentPath != null, "Parent path must not be null"); checkArgument(childPath != null, "Child path must not be null"); checkArgument(parentPath.containsWildcarded(childPath), "Parent object must be parent of child."); List<PathArgument> pathArgs = subList(parentPath.getPathArguments(), childPath.getPathArguments()); @SuppressWarnings("rawtypes") Map<InstanceIdentifier, DataContainer> lastFound = Collections.singletonMap(parentPath, parent); for (PathArgument pathArgument : pathArgs) { @SuppressWarnings("rawtypes") final ImmutableMap.Builder<InstanceIdentifier, DataContainer> potentialBuilder = ImmutableMap.builder(); for (@SuppressWarnings("rawtypes") Entry<InstanceIdentifier, DataContainer> entry : lastFound.entrySet()) { potentialBuilder.putAll(readData(entry, pathArgument)); } lastFound = potentialBuilder.build(); if (lastFound.isEmpty()) { return Collections.emptyMap(); } } @SuppressWarnings({ "unchecked", "rawtypes" }) final Map<InstanceIdentifier<T>, T> result = (Map) lastFound; return result; } private  DataObjectReadingUtil(); static Map<InstanceIdentifier<T>, T> readData(
            final P parent, final InstanceIdentifier<P> parentPath, final InstanceIdentifier<T> childPath); static Optional<T> readData(final DataObject source, final Class<T> child);  }