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

/** Clases y métodos genéricos, inferencia y boxing. */
public class BoxDemo {
    public static void main(String[] args) {
        Box<String> city = new Box<>();     // diamante: T = String se infiere
        city.put("Lima");
        String s = city.get();              // sin casting
        System.out.println("caja: " + s + ", vacía: " + city.isEmpty());

        Pair<String, Integer> stock = new Pair<>("arroz", 40);
        System.out.println(stock + " -> " + stock.swap());

        List<String> empty = new ArrayList<>();
        List<String> names = List.of("alice", "bob");
        System.out.println(ListUtils.firstOrDefault(names, "nadie"));
        System.out.println(ListUtils.firstOrDefault(empty, "nadie"));

        // Box<int> no existe: se usa Integer y Java convierte solo (boxing/unboxing).
        Box<Integer> count = new Box<>();
        count.put(7);                       // boxing: 7 -> Integer.valueOf(7)
        int n = count.get() + 1;            // unboxing: Integer -> int
        System.out.println("n = " + n);

        // == entre Integer compara referencias, no valores.
        Integer a = 127, b = 127, c = 1000, d = 1000;
        System.out.println("127 == 127: " + (a == b) + ", 1000 == 1000: " + (c == d)
                + ", equals: " + c.equals(d));
    }
}
