/** * Removes all overrides for a given treatment * @param treatmentName The treatment to remove overrides for */ public Experiment removeOverrides(String treatmentName) { final Treatment treatment = treatments.get(treatmentName); if (treatment == null) { return this; } final Iterator<Entry<String, TreatmentOverride>> iterator = overrides.entrySet().iterator(); while (iterator.hasNext()) { final Entry<String, TreatmentOverride> entry = iterator.next(); if (entry.getValue().getTreatment().equals(treatment)) { iterator.remove(); } } return this; }
private void mergeAdjacentAllocations() { // merge all adjacent allocations for the same treatment if (allocations.size() < 2) { return; } final List<Allocation> newList = Lists.newArrayList(); int totalSize = allocations.get(0).getSize(); int offset = allocations.get(0).getOffset(); Treatment treatment = allocations.get(0).getTreatment(); for (int i=1; i<allocations.size(); i++) { final Allocation allocation = allocations.get(i); if (!allocation.getTreatment().equals(treatment)) { // different treatment newList.add(new Allocation(treatment, offset, totalSize)); totalSize = allocation.getSize(); offset = allocation.getOffset(); treatment = allocation.getTreatment(); } else { // same treatment, accumulate size totalSize += allocation.getSize(); } } newList.add(new Allocation(treatment, offset, totalSize)); allocations = newList; }
/** * De-allocates bins from a treatment * @param treatment The treatment * @param size The number of bins */ 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) { // a piece could not be evenly split by the amount we wanted to deallocate, need to add back in allocations.add(new Allocation(treatment, next.getOffset() + next.getSize() + sizeLeft, -sizeLeft)); break; } } sortAllocations(); mergeAdjacentAllocations(); rebuildAllocationTables(); }
lastOffset = next.getOffset() + next.getSize(); if (!next.getTreatment().equals(source)) { continue;