/** * Gets all the instances of an application. * @param application an application (not null) * @return a non-null list of instances * <p> * The result is a list made up of ordered lists.<br> * root-0, child-0-1, child-0-2, child-0-1-1, etc.<br> * root-1, child-1-1, child-1-2, child-1-1-1, etc.<br> * </p> * <p> * It means the resulting list can be considered as valid for starting instances * from the root instances to the bottom leaves. * </p> */ public static List<Instance> getAllInstances( AbstractApplication application ) { List<Instance> result = new ArrayList<> (); for( Instance instance : application.getRootInstances()) result.addAll( InstanceHelpers.buildHierarchicalList( instance )); return result; }
/** * Finds all the scoped instances from an application. * @return a non-null list */ public static List<Instance> findAllScopedInstances( AbstractApplication app ) { List<Instance> instanceList = new ArrayList<> (); List<Instance> todo = new ArrayList<> (); todo.addAll( app.getRootInstances()); while( ! todo.isEmpty()) { Instance current = todo.remove( 0 ); todo.addAll( current.getChildren()); if( isTarget( current )) instanceList.add( current ); } return instanceList; }
/** * Determines whether an instance name is not already used by a sibling instance. * @param application the application (not null) * @param parentInstance the parent instance (can be null to indicate a root instance) * @param nameToSearch the name to search * @return true if a child instance of <code>parentInstance</code> has the same name, false otherwise */ public static boolean hasChildWithThisName( AbstractApplication application, Instance parentInstance, String nameToSearch ) { boolean hasAlreadyAChildWithThisName = false; Collection<Instance> list = parentInstance == null ? application.getRootInstances() : parentInstance.getChildren(); for( Iterator<Instance> it = list.iterator(); it.hasNext() && ! hasAlreadyAChildWithThisName; ) { hasAlreadyAChildWithThisName = Objects.equals( nameToSearch, it.next().getName()); } return hasAlreadyAChildWithThisName; }
currentList.addAll( application.getRootInstances());
&& ComponentHelpers.findAllAncestors( childInstance.getComponent()).isEmpty()) { application.getRootInstances().add( childInstance ); success = true;