@Test(dependsOnMethods = {"testSimpleResource"}) public void testCombination() { Model mo = new DefaultModel(); List<VM> vms = Util.newVMs(mo, 7); ShareableResource rc = new ShareableResource("foo"); for (int i = 0; i < 4; i++) { rc.setConsumption(vms.get(i), i); } rc.setConsumption(vms.get(4), 2); rc.setConsumption(vms.get(5), 2); rc.setConsumption(vms.get(6), 3); ShareableResource rc2 = new ShareableResource("bar"); for (int i = 0; i < 4; i++) { rc2.setConsumption(vms.get(i), i / 2); } rc2.setConsumption(vms.get(4), 1); rc2.setConsumption(vms.get(5), 3); rc2.setConsumption(vms.get(6), 3); VMConsumptionComparator c1 = new VMConsumptionComparator(rc, true); c1.append(rc2, false); vms.sort(c1); for (int i = 0; i < vms.size() - 1; i++) { VM id = vms.get(i); Assert.assertTrue(rc.getConsumption(id) <= rc.getConsumption(vms.get(i + 1))); if (rc.getConsumption(id) == rc.getConsumption(vms.get(i + 1))) { Assert.assertTrue(rc2.getConsumption(id) >= rc2.getConsumption(vms.get(i + 1))); } } c1 = new VMConsumptionComparator(rc, true); c1.append(rc2, true); vms.sort(c1); for (int i = 0; i < vms.size() - 1; i++) { VM id = vms.get(i); Assert.assertTrue(rc.getConsumption(id) <= rc.getConsumption(vms.get(i + 1))); if (rc.getConsumption(id) == rc.getConsumption(vms.get(i + 1))) { Assert.assertTrue(rc2.getConsumption(id) <= rc2.getConsumption(vms.get(i + 1))); } } }
public VMConsumptionComparator append(ShareableResource r, boolean asc) { rcs.add(r); ascs.add(asc ? 1 : -1); return this; }
VMConsumptionComparator implements Comparator<VM> { public VMConsumptionComparator append(ShareableResource r, boolean asc) { rcs.add(r); ascs.add(asc ? 1 : -1); return this; } }
VMConsumptionComparator implements Comparator<VM> { public VMConsumptionComparator append(ShareableResource r, boolean asc) { rcs.add(r); ascs.add(asc ? 1 : -1); return this; } VMConsumptionComparator(ShareableResource rc);  VMConsumptionComparator(ShareableResource rc, boolean asc); }
VMConsumptionComparator implements Comparator<VM> { public VMConsumptionComparator append(ShareableResource r, boolean asc) { rcs.add(r); ascs.add(asc ? 1 : -1); return this; } VMConsumptionComparator(ShareableResource rc);  VMConsumptionComparator(ShareableResource rc, boolean asc); VMConsumptionComparator append(ShareableResource r, boolean asc); @Override int compare(VM v1, VM v2); }
VMConsumptionComparator implements Comparator<VM> { public VMConsumptionComparator append(ShareableResource r, boolean asc) { rcs.add(r); ascs.add(asc ? 1 : -1); return this; } VMConsumptionComparator(ShareableResource rc);  VMConsumptionComparator(ShareableResource rc, boolean asc); VMConsumptionComparator append(ShareableResource r, boolean asc); @Override int compare(VM v1, VM v2);  }