@Test(expected = IllegalArgumentException.class) public void addDestinationWithoutId() { NavGraph graph = mNavGraphNavigator.createDestination(); NavDestination destination = new NavDestination(mock(Navigator.class)); graph.addDestination(destination); }
public void addDestination(@NonNull NavDestination node) { if (node.getId() == 0) { throw new IllegalArgumentException("Destinations must have an id." + " Call setId() or include an android:id in your navigation XML."); } NavDestination existingDestination = mNodes.get(node.getId()); if (existingDestination == node) { return; } if (node.getParent() != null) { throw new IllegalStateException("Destination already has a parent set." + " Call NavGraph.remove() to remove the previous parent."); } if (existingDestination != null) { existingDestination.setParent(null); } node.setParent(this); mNodes.put(node.getId(), node); }
NavGraph extends NavDestination implements Iterable<NavDestination> { public void addDestination(@NonNull NavDestination node) { if (node.getId() == 0) { throw new IllegalArgumentException("Destinations must have an id." + " Call setId() or include an android:id in your navigation XML."); } NavDestination existingDestination = mNodes.get(node.getId()); if (existingDestination == node) { return; } if (node.getParent() != null) { throw new IllegalStateException("Destination already has a parent set." + " Call NavGraph.remove() to remove the previous parent."); } if (existingDestination != null) { existingDestination.setParent(null); } node.setParent(this); mNodes.put(node.getId(), node); } }
NavGraph extends NavDestination implements Iterable<NavDestination> { public void addDestination(@NonNull NavDestination node) { if (node.getId() == 0) { throw new IllegalArgumentException("Destinations must have an id." + " Call setId() or include an android:id in your navigation XML."); } NavDestination existingDestination = mNodes.get(node.getId()); if (existingDestination == node) { return; } if (node.getParent() != null) { throw new IllegalStateException("Destination already has a parent set." + " Call NavGraph.remove() to remove the previous parent."); } if (existingDestination != null) { existingDestination.setParent(null); } node.setParent(this); mNodes.put(node.getId(), node); } NavGraph(@NonNull NavigatorProvider navigatorProvider);  NavGraph(@NonNull Navigator<? extends NavGraph> navGraphNavigator); }
NavGraph extends NavDestination implements Iterable<NavDestination> { public void addDestination(@NonNull NavDestination node) { if (node.getId() == 0) { throw new IllegalArgumentException("Destinations must have an id." + " Call setId() or include an android:id in your navigation XML."); } NavDestination existingDestination = mNodes.get(node.getId()); if (existingDestination == node) { return; } if (node.getParent() != null) { throw new IllegalStateException("Destination already has a parent set." + " Call NavGraph.remove() to remove the previous parent."); } if (existingDestination != null) { existingDestination.setParent(null); } node.setParent(this); mNodes.put(node.getId(), node); } NavGraph(@NonNull NavigatorProvider navigatorProvider);  NavGraph(@NonNull Navigator<? extends NavGraph> navGraphNavigator); @Override void onInflate(@NonNull Context context, @NonNull AttributeSet attrs); void addDestination(@NonNull NavDestination node); void addDestinations(@NonNull Collection<NavDestination> nodes); void addDestinations(@NonNull NavDestination... nodes); NavDestination findNode(@IdRes int resid); @NonNull @Override Iterator<NavDestination> iterator(); void addAll(@NonNull NavGraph other); void remove(@NonNull NavDestination node); void clear(); @IdRes int getStartDestination(); void setStartDestination(@IdRes int startDestId); }
NavGraph extends NavDestination implements Iterable<NavDestination> { public void addDestination(@NonNull NavDestination node) { if (node.getId() == 0) { throw new IllegalArgumentException("Destinations must have an id." + " Call setId() or include an android:id in your navigation XML."); } NavDestination existingDestination = mNodes.get(node.getId()); if (existingDestination == node) { return; } if (node.getParent() != null) { throw new IllegalStateException("Destination already has a parent set." + " Call NavGraph.remove() to remove the previous parent."); } if (existingDestination != null) { existingDestination.setParent(null); } node.setParent(this); mNodes.put(node.getId(), node); } NavGraph(@NonNull NavigatorProvider navigatorProvider);  NavGraph(@NonNull Navigator<? extends NavGraph> navGraphNavigator); @Override void onInflate(@NonNull Context context, @NonNull AttributeSet attrs); void addDestination(@NonNull NavDestination node); void addDestinations(@NonNull Collection<NavDestination> nodes); void addDestinations(@NonNull NavDestination... nodes); NavDestination findNode(@IdRes int resid); @NonNull @Override Iterator<NavDestination> iterator(); void addAll(@NonNull NavGraph other); void remove(@NonNull NavDestination node); void clear(); @IdRes int getStartDestination(); void setStartDestination(@IdRes int startDestId);  }