package Model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Database {
    private List<Film> films;
    private List<Actor> actors;

    private static final Database instance = new Database();

    private Database() {
        this.films = new ArrayList<>();
        this.actors = new ArrayList<>();
    }

    public static Database getInstance() {
        return instance;
    }

    public List<Film> getFilms() {
        return films;
    }

    public List<Actor> getActors() {
        return actors;
    }

    public void addFilm(Film film) {
        films.add(film);
    }

    public void addActor(Actor actor) {
        actors.add(actor);
    }

    public boolean hasActorWithNoFilms() {
        for (Actor actor : actors) {
            if (actor.getFilms().isEmpty()) {
                return true;
            }
        }
        return false;
    }

    public List<Actor> getCoActors(Actor targetActor) {
        List<Actor> coActors = new ArrayList<>();
        for (Film film : films) {
            if (film.getActors().contains(targetActor)) {
                for (Actor actor : film.getActors()) {
                    if (!actor.equals(targetActor) && !coActors.contains(actor)) {
                        coActors.add(actor);
                    }
                }
            }
        }
        System.out.println("COA:" + coActors);
        return coActors;
    }


    public Film findFilmWithMostActors() {
        if (films.isEmpty()) {
            return null;
        }

        Film filmWithMostActors = films.get(0);
        for (Film film : films) {
            if (film.getActors().size() > filmWithMostActors.getActors().size()) {
                filmWithMostActors = film;
            }
        }
        return filmWithMostActors;
    }
    
    public Film findFilmByTitle(String title) {
        for (Film film : films) {
            if (film.getTitle().equals(title)) {
                return film;
            }
        }
        return null; // Если фильм с указанным названием не найден, возвращаем null
    }
    
    public Actor findActorByName(String name) {
        // Проверяем, что коллекция actors не пуста
        if (actors.isEmpty()) {
            System.out.println("The list of actors is empty.");
            return null;
        }
        
        // Выводим информацию о коллекции actors перед началом поиска
        System.out.println("Actors in the database: " + actors);
        
        // Используем итератор для поиска актера по имени
        Iterator<Actor> iterator = actors.iterator();
        while (iterator.hasNext()) {
            Actor actor = iterator.next();
            System.out.println("Comparing: " + actor.getName() + " with " + name);
            if (actor.getName().equals(name)) {
                return actor;
            }
        }
        System.out.println("No actor found with name: " + name);
        return null; // Если актер с указанным именем не найден, возвращаем null
    }


    
    public List<Actor> getActorsWithoutFilms(String actorName, int checker) {
        List<Actor> actorsWithoutFilms = new ArrayList<>();
        Iterator<Actor> iterator = actors.iterator();
        while (iterator.hasNext()) {
            Actor actor = iterator.next();
            if (actor.getFilms().isEmpty() && (actorName == null || actor.getName().equals(actorName))) {
                actorsWithoutFilms.add(actor);
                // Удаляем только конкретного актёра из списка, если checker равен 1
                if (checker == 1) {
                    iterator.remove();
                    System.out.println("Actor " + actor.getName() + " deleted");
                    break; // Прерываем цикл, так как нашли и удалили нужного актёра
                }
            }
        }
        return actorsWithoutFilms;
    }




}

Пожалуйста. Ну помоги ты уже. 

Film added: qwe
Actor added to film: q added to qwe
Actor: q
Actor added to film: w added to qwe
Actor: q
Actor: w
Actor added to film: e added to qwe
Actor: q
Actor: w
Actor: e
The list of actors is empty.
actorbyname:null