package CHAPTER09;

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

interface LibraryManager<T> {           // 제네릭 인터페이스 정의
    void addItem(T item);
    void removeItem(T item);
    List<T> getItems();
}

class Library<T> implements LibraryManager<T> {  // 제네릭 클래스 구현
    private List<T> items = new ArrayList<>();

    @Override
    public void addItem(T item) {
        items.add(item);
        System.out.println("추가된 자료: " + item);
    }
    @Override
    public void removeItem(T item) {
        items.remove(item);
    }
    @Override
    public List<T> getItems() {
        return items;
    }
    @Override
    public String toString() {
        return items.toString();
    }
}

class MultimediaLibrary<T> extends Library<T> { // 제네릭 상속
    public void playItem(T item) {
        System.out.println("Playing multimedia: " + item);
    }
}

class LibraryUtils {  // 와일드카드 다형성 활용
    public static <T> void transferItems(Library<? extends T> source, Library<? super T> target) {
        for (T item : source.getItems()) {
            target.addItem(item);
        }
    }
    public static <T> boolean compareItems(T item1, T item2) {
        return item1.equals(item2);
    }
}

public class LAB_02_BookList {
	public static void main(String[] args) {
        Library<String> bookLibrary = new Library<>();
        bookLibrary.addItem("Effective Java");
        bookLibrary.addItem("Clean Code");

        Library<String> researchLibrary = new Library<>();
        researchLibrary.addItem("Deep Learning Research");

        System.out.println("[책 도서관]");
        System.out.println("전체 자료: " + bookLibrary);

        System.out.println("\n[논문 도서관]");
        System.out.println("전체 자료: " + researchLibrary);

        // 두 자료 비교
        boolean areEqual = LibraryUtils.compareItems("Clean Code", "Deep Learning Research");
        System.out.println("\n자료 비교 결과: " + (areEqual ? "같습니다." : "다릅니다."));
    }
}