Measurement extends MeasurementData implements Observable { public Measurement restrict(DataType type) { Measurement m = new Measurement(); m.setTreatment(getTreatment()); switch (type) { case NONE: break; case RATE: m.setSampleSize(getSampleSize()); m.setResponders(getResponders()); break; case CONTINUOUS: m.setMean(getMean()); m.setStdDev(getStdDev()); m.setSampleSize(getSampleSize()); break; } return m; } Measurement(Treatment t, int responders, int sampleSize);  Measurement(Treatment t, double mean, double stdDev, int sampleSize);  Measurement(Treatment t);  Measurement(); @Override Treatment getTreatment(); @Override void setTreatment(Object value); void setTreatment(Treatment newValue); @Override void setMean(Double newValue); @Override void setStdDev(Double newValue); @Override void setSampleSize(Integer newValue); @Override void setResponders(Integer newValue); void addPropertyChangeListener(PropertyChangeListener listener); void removePropertyChangeListener(PropertyChangeListener listener); Measurement restrict(DataType type); static final String PROPERTY_TREATMENT; static final String PROPERTY_MEAN; static final String PROPERTY_STDDEV; static final String PROPERTY_SAMPLESIZE; static final String PROPERTY_RESPONDERS; }
@Test public void testRestrict() { Measurement m = new Measurement(); m.setMean(1.0); m.setStdDev(2.0); m.setSampleSize(100); m.setResponders(12); Treatment t = new Treatment(); t.setId("A"); m.setTreatment(t); Measurement mNone = m.restrict(DataType.NONE); assertNull(mNone.getMean()); assertNull(mNone.getStdDev()); assertNull(mNone.getSampleSize()); assertNull(mNone.getResponders()); assertEquals(m.getTreatment(), mNone.getTreatment()); Measurement mRate = m.restrict(DataType.RATE); assertNull(mRate.getMean()); assertNull(mRate.getStdDev()); assertEquals(m.getSampleSize(), mRate.getSampleSize()); assertEquals(m.getResponders(), mRate.getResponders()); assertEquals(m.getTreatment(), mRate.getTreatment()); Measurement mCont = m.restrict(DataType.CONTINUOUS); assertEquals(m.getMean(), mCont.getMean()); assertEquals(m.getStdDev(), mCont.getStdDev()); assertEquals(m.getSampleSize(), mCont.getSampleSize()); assertNull(mCont.getResponders()); assertEquals(m.getTreatment(), mCont.getTreatment()); }