ParameterComparator implements Comparator<Parameter> { public int compare(Parameter o1, Parameter o2) { int par1Type = classes.indexOf(o1.getClass()); int par2Type = classes.indexOf(o2.getClass()); if (par1Type < 0 | par2Type < 0) { throw new IllegalArgumentException("Attempt to compare unknown Parameter class : " + o1.getClass()); } if (par1Type != par2Type) { return par1Type - par2Type; } if (o1 instanceof BasicParameter) { return ((BasicParameter) o1).compareTo((BasicParameter) o2); } else if (o1 instanceof SplitParameter) { return ((SplitParameter) o1).compareTo((SplitParameter) o2); } else if (o1 instanceof InconsistencyParameter) { return ((InconsistencyParameter) o1).compareTo((InconsistencyParameter) o2); } return 0; }  int compare(Parameter o1, Parameter o2);  }
@Test public void testCompareBasicParameters() { ParameterComparator pc = new ParameterComparator(); Treatment ta = new Treatment("A"); Treatment tb = new Treatment("B"); Treatment tc = new Treatment("C"); assertTrue(pc.compare(new BasicParameter(ta, tb), new BasicParameter(tc, tb)) < 0); assertTrue(pc.compare(new BasicParameter(tc, tb), new BasicParameter(ta, tb)) > 0); assertTrue(pc.compare(new BasicParameter(ta, tb), new BasicParameter(tc, ta)) < 0); assertTrue(pc.compare(new BasicParameter(ta, tb), new BasicParameter(ta, tb)) == 0); assertTrue(pc.compare(new BasicParameter(ta, tb), new BasicParameter(ta, tc)) < 0); assertTrue(pc.compare(new BasicParameter(ta, tc), new BasicParameter(ta, ta)) > 0); }
@Test public void testCompareInconsistencyParameters() { ParameterComparator pc = new ParameterComparator(); Treatment ta = new Treatment("A"); Treatment tb = new Treatment("B"); Treatment tc = new Treatment("C"); Treatment td = new Treatment("D"); List<Treatment> c1 = Arrays.asList(ta, tb, tc, ta); List<Treatment> c2 = Arrays.asList(ta, tb, td, ta); List<Treatment> c3 = Arrays.asList(ta, tb, tc, td, ta); assertTrue(pc.compare(new InconsistencyParameter(c1), new InconsistencyParameter(c2)) < 0); assertTrue(pc.compare(new InconsistencyParameter(c1), new InconsistencyParameter(c1)) == 0); assertTrue(pc.compare(new InconsistencyParameter(c2), new InconsistencyParameter(c1)) > 0); assertTrue(pc.compare(new InconsistencyParameter(c1), new InconsistencyParameter(c3)) < 0); }
@Test public void testCompareSplitParameters() { ParameterComparator pc = new ParameterComparator(); Treatment ta = new Treatment("A"); Treatment tb = new Treatment("B"); assertTrue(pc.compare(new SplitParameter(ta, tb, true), new SplitParameter(ta, tb, false)) < 0); assertTrue(pc.compare(new SplitParameter(ta, tb, true), new SplitParameter(ta, tb, true)) == 0); }
@Test public void testCompareMixed() { ParameterComparator pc = new ParameterComparator(); Treatment ta = new Treatment("A"); Treatment tb = new Treatment("B"); Treatment tc = new Treatment("C"); List<Treatment> c1 = Arrays.asList(ta, tb, tc, ta); assertTrue(pc.compare(new BasicParameter(ta, tb), new InconsistencyParameter(c1)) < 0); assertTrue(pc.compare(new InconsistencyParameter(c1), new BasicParameter(ta, tb)) > 0); assertTrue(pc.compare(new BasicParameter(tb, tc), new InconsistencyParameter(c1)) < 0); assertTrue(pc.compare(new BasicParameter(ta, tb), new SplitParameter(ta, tb, true)) < 0); assertTrue(pc.compare(new SplitParameter(ta, tb, true), new BasicParameter(ta, tb)) > 0); assertTrue(pc.compare(new BasicParameter(tb, tc), new SplitParameter(ta, tb, true)) < 0); }