public static void main(String[] args) { Set<Integer> real = new TreeSet<Integer>(); MyTreeSet<Integer> fake = new MyTreeSet<Integer>(); while (real.size() < NUMBER_OF_ELEMENTS) { debug("real: " + real); debug("fake: " + fake); Integer value = new Integer(random(MAX_VALUE)); boolean realBool = real.contains(value); boolean fakeBool = fake.contains(value); if (fakeBool != realBool) throw new RuntimeException( "contains(" + value + ") returned " + fakeBool + " and should return " + realBool); // add debug("add(" + value + ")"); realBool = real.add(value); fakeBool = fake.add(value); if (fakeBool != realBool) throw new RuntimeException( "add(" + value + ") returned " + fakeBool + " and should return " + realBool); int realInt = real.size(); int fakeInt = fake.size(); if (realInt != fakeInt) throw new RuntimeException("size() returned " + fakeInt + " and should return " + realInt); } while (real.size() > 0) { debug("real: " + real); debug("fake: " + fake); Integer value = new Integer(random(MAX_VALUE)); boolean realBool = real.contains(value); boolean fakeBool = fake.contains(value); if (fakeBool != realBool) throw new RuntimeException( "contains(" + value + ") returned " + fakeBool + " and should return " + realBool); // remove debug("remove(" + value + ")"); realBool = real.remove(value); fakeBool = fake.remove(value); if (fakeBool != realBool) throw new RuntimeException( "remove(" + value + ") returned " + fakeBool + " and should return " + realBool); int realInt = real.size(); int fakeInt = fake.size(); if (realInt != fakeInt) throw new RuntimeException("size() returned " + fakeInt + " and should return " + realInt); } System.out.println("MyTreeSet works!"); }
private void removeAllocation(Allocation alloc) { removeAlert(alloc); if (allocations.contains(alloc)) { allocations.remove(alloc); tableModel.fireTableDataChanged(); } }
private void checkAllocations(Enumeration en) { while (en.hasMoreElements()) { Allocation alloc = (Allocation) en.nextElement(); AllocationResult ar = alloc.getEstimatedResult(); if (ar != null) { if (!allocations.contains(alloc)) { allocations.add(alloc); tableModel.fireTableDataChanged(); } else { tableModel.fireTableDataChanged(); } if (ar.isSuccess()) { removeAlert(alloc); } else { createAlert(alloc); } } else { removeAllocation(alloc); } } }