IsotopePattern { @Override public Object clone() throws CloneNotSupportedException { IsotopePattern isoClone = new IsotopePattern(); IsotopeContainer isoHighest = getMonoIsotope(); for (IsotopeContainer isoContainer : isotopeCList) { if (isoHighest.equals(isoContainer)) isoClone.setMonoIsotope((IsotopeContainer) isoContainer.clone()); else isoClone.addIsotope((IsotopeContainer) isoContainer.clone()); } isoClone.setCharge(getCharge()); return isoClone; } IsotopePattern(); void setMonoIsotope(IsotopeContainer isoContainer); void addIsotope(IsotopeContainer isoContainer); IsotopeContainer getMonoIsotope(); List<IsotopeContainer> getIsotopes(); IsotopeContainer getIsotope(int position); int getNumberOfIsotopes(); void setCharge(double charge); double getCharge(); @Override Object clone();  }
@Test public void testClone() throws Exception { IsotopePattern spExp = new IsotopePattern(); spExp.setMonoIsotope(new IsotopeContainer(156.07770, 1)); spExp.addIsotope(new IsotopeContainer(157.07503, 0.0004)); spExp.addIsotope(new IsotopeContainer(157.08059, 0.0003)); spExp.addIsotope(new IsotopeContainer(158.08135, 0.002)); spExp.setCharge(1); IsotopePattern clone = (IsotopePattern) spExp.clone(); Assert.assertEquals(156.07770, clone.getMonoIsotope().getMass(), 0.001); Assert.assertEquals(156.07770, clone.getIsotopes().get(0).getMass(), 0.001); Assert.assertEquals(157.07503, clone.getIsotopes().get(1).getMass(), 0.001); Assert.assertEquals(157.08059, clone.getIsotopes().get(2).getMass(), 0.001); Assert.assertEquals(158.08135, clone.getIsotopes().get(3).getMass(), 0.001); Assert.assertEquals(1, clone.getMonoIsotope().getIntensity(), 0.001); Assert.assertEquals(1, clone.getIsotopes().get(0).getIntensity(), 0.001); Assert.assertEquals(0.0004, clone.getIsotopes().get(1).getIntensity(), 0.001); Assert.assertEquals(0.0003, clone.getIsotopes().get(2).getIntensity(), 0.001); Assert.assertEquals(0.002, clone.getIsotopes().get(3).getIntensity(), 0.001); Assert.assertEquals(1, clone.getCharge(), 0.001); }