@Test public void testDeallocate() { final Allocations allocations = new Allocations(Lists.<Allocation>newArrayList()); allocations.allocate(control, 10); allocations.allocate(withLogin, 20); allocations.allocate(withoutLogin, 30); allocations.deallocate(control, 5); allocations.deallocate(withLogin, 10); allocations.deallocate(withoutLogin, 15); assertEquals( "allocations should be smaller and within the same offset range", Lists.newArrayList( new Allocation(control, 5, 5), new Allocation(withLogin, 20, 10), new Allocation(withoutLogin, 45, 15) ), allocations.getAllocations() ); }
public void deallocate(Treatment treatment, int size) { final Iterator<Allocation> iter = allocations.iterator(); int sizeLeft = size; while (iter.hasNext()) { final Allocation next = iter.next(); if (next.getTreatment().equals(treatment)) { sizeLeft -= next.getSize(); iter.remove(); } if (sizeLeft < 0) { allocations.add(new Allocation(treatment, next.getOffset() + next.getSize() + sizeLeft, -sizeLeft)); break; } } sortAllocations(); mergeAdjacentAllocations(); rebuildAllocationTables(); }
Allocations { public void deallocate(Treatment treatment, int size) { final Iterator<Allocation> iter = allocations.iterator(); int sizeLeft = size; while (iter.hasNext()) { final Allocation next = iter.next(); if (next.getTreatment().equals(treatment)) { sizeLeft -= next.getSize(); iter.remove(); } if (sizeLeft < 0) { allocations.add(new Allocation(treatment, next.getOffset() + next.getSize() + sizeLeft, -sizeLeft)); break; } } sortAllocations(); mergeAdjacentAllocations(); rebuildAllocationTables(); } }
Allocations { public void deallocate(Treatment treatment, int size) { final Iterator<Allocation> iter = allocations.iterator(); int sizeLeft = size; while (iter.hasNext()) { final Allocation next = iter.next(); if (next.getTreatment().equals(treatment)) { sizeLeft -= next.getSize(); iter.remove(); } if (sizeLeft < 0) { allocations.add(new Allocation(treatment, next.getOffset() + next.getSize() + sizeLeft, -sizeLeft)); break; } } sortAllocations(); mergeAdjacentAllocations(); rebuildAllocationTables(); } Allocations();  Allocations(Iterable<Allocation> allocations); }
Allocations { public void deallocate(Treatment treatment, int size) { final Iterator<Allocation> iter = allocations.iterator(); int sizeLeft = size; while (iter.hasNext()) { final Allocation next = iter.next(); if (next.getTreatment().equals(treatment)) { sizeLeft -= next.getSize(); iter.remove(); } if (sizeLeft < 0) { allocations.add(new Allocation(treatment, next.getOffset() + next.getSize() + sizeLeft, -sizeLeft)); break; } } sortAllocations(); mergeAdjacentAllocations(); rebuildAllocationTables(); } Allocations();  Allocations(Iterable<Allocation> allocations); Treatment getTreatment(int bin); void allocate(Treatment treatment, int size); void deallocate(Treatment treatment, int size); void reallocate(Treatment source, Treatment destination, int size); List<Allocation> getAllocations(); int getSize(); int getUnallocatedSize(); void clear(); }
Allocations { public void deallocate(Treatment treatment, int size) { final Iterator<Allocation> iter = allocations.iterator(); int sizeLeft = size; while (iter.hasNext()) { final Allocation next = iter.next(); if (next.getTreatment().equals(treatment)) { sizeLeft -= next.getSize(); iter.remove(); } if (sizeLeft < 0) { allocations.add(new Allocation(treatment, next.getOffset() + next.getSize() + sizeLeft, -sizeLeft)); break; } } sortAllocations(); mergeAdjacentAllocations(); rebuildAllocationTables(); } Allocations();  Allocations(Iterable<Allocation> allocations); Treatment getTreatment(int bin); void allocate(Treatment treatment, int size); void deallocate(Treatment treatment, int size); void reallocate(Treatment source, Treatment destination, int size); List<Allocation> getAllocations(); int getSize(); int getUnallocatedSize(); void clear(); static final int NUM_BINS; }