package UE02_100924_Collections_TreeSet;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class UE02_Main {

    public static void main(String[] args) {
        testPerson();
        testPunkt();
        testBuch();
    }

    public static void testPerson() {
//        Comparator<Person> personComp = (o1, o2) -> {
//            int compare = o1.famname.compareToIgnoreCase(o2.famname);
//            if (compare != 0) return compare;
//            return o1.vorname.compareToIgnoreCase(o2.vorname);
//        };
//        Set<Person> persons = new TreeSet<>(personComp);

        Set<Person> persons = new TreeSet<>();

        persons.add(new Person("Tom", "Human"));
        persons.add(new Person("Benton", "Mensch"));
        persons.add(new Person("Anton", "Mensch"));
        persons.add(new Person("Anton", "Mensch"));

        System.out.println(persons);
    }

    public static void testPunkt() {
        Set<Punkt> points = new TreeSet<>();

        points.add(new Punkt(1, 1));
        points.add(new Punkt(3, 3));
        points.add(new Punkt(4, 4));
        points.add(new Punkt(-1, -1));
        points.add(new Punkt(1, -1));
        points.add(new Punkt(-1, 1));
        System.out.println(points);
    }

    public static void testBuch() {
        Set<Buch> books = new TreeSet<>();

        books.add(new Buch("Book", "AntonZ", 10));
        books.add(new Buch("Book", "Anton", 10));
        books.add(new Buch("Anaconda", "Anton", 10));
        books.add(new Buch("Book", "Tom", 40));
        books.add(new Buch("Book", "Tom", 10));
        books.add(new Buch("Book", "Tom", 20));
        books.add(new Buch("Book", "Tom", 10));
        books.add(new Buch("Book", "Tom", 10));

        System.out.println(books);

        Comparator<Buch> buchComp = (o1, o2) -> {
            if (!o1.title.equals(o2.title)) return o1.title.compareToIgnoreCase(o2.title);
            if (!o1.autor.equals(o2.autor)) return o1.autor.compareToIgnoreCase(o2.autor);
            return Integer.compare(o1.price, o2.price);
        };
        Set<Buch> compBooks = new TreeSet<>(buchComp);
        System.out.println(compBooks);
    }
}
