I tried to use TreeSet:
Comparator<Product> pc = (p1, p2) -> ((Double) p1.getPrice()).compareTo(p2.getPrice());
Set<Product> products = new TreeSet<>(pc);
products.add(new Product(10));
products.add(new Product(10));
but problem is that it can not contain more than one equal values in terms of Comparator, and so only one of the product will be in products
set.
I need some Collection implementation, that will order newly inserted value, allow many equal(in terms of Comparator) values, and have insert complexity log(n) (possibly tree based impl)