class OrganisationUnitHierarchy {

    public Set<Long> getChildren( long parentId )
    {
        Set<Long> preparedChildren = subTrees.get( parentId );
        
        if ( preparedChildren != null )
        {
            return new HashSet<>( preparedChildren );
        }
        
        List<Long> children = new ArrayList<>();
        
        children.add( 0, parentId ); // Adds parent id to beginning of list

        int childCounter = 1;
        
        for ( int i = 0; i < childCounter; i++ )
        {
            Set<Long> currentChildren = relationships.get( children.get( i ) );
            
            if ( currentChildren != null )
            {
                children.addAll( currentChildren );
            
                childCounter += currentChildren.size();
            }
        }
        
        return new HashSet<>( children );
    }

    public  OrganisationUnitHierarchy( Map<Long, Set<Long>> relationships );
    public  OrganisationUnitHierarchy( Collection<OrganisationUnitRelationship> relations );

}