import java.util.TreeSet; /** * * @author ilari */ public class MultiSet { public static void main(String[] args) { IO io = new IO(); TreeSet set = new TreeSet<>(); set.add(new UniqueInteger(2)); set.add(new UniqueInteger(2)); set.add(new UniqueInteger(3)); set.add(new UniqueInteger(1)); io.println("floor(2)=" + set.floor(new UniqueInteger(2)).getArvo()); set.remove(set.floor(new UniqueInteger(2))); io.println("floor(2)=" + set.floor(new UniqueInteger(2)).getArvo()); set.remove(set.floor(new UniqueInteger(2))); io.println("floor(2)=" + set.floor(new UniqueInteger(2)).getArvo()); io.close(); } public static boolean contains(TreeSet set, int arvo) { UniqueInteger floor = set.floor(new UniqueInteger(arvo)); if (floor == null) { return false; } return floor.getArvo() == arvo; } } class UniqueInteger implements Comparable { static int counter = 0; private int id; private int arvo; public UniqueInteger(int arvo) { this.id = counter++; this.arvo = arvo; } public int getArvo() { return arvo; } @Override public int compareTo(UniqueInteger other) { if (other.getArvo() == this.arvo) { return this.id - other.id; } return this.arvo - other.arvo; } }