Source:
public Sample build() { checkArgument(user != null, "A User must be provided to create a Sample."); checkArgument(project != null, "A Project must be provided to create a Sample."); checkArgument(!LimsUtils.isStringEmptyOrNull(description), "Must provide a description to create a Sample"); checkArgument(!LimsUtils.isStringEmptyOrNull(sampleType), "Must provide a sampleType to create a Sample"); checkArgument(!LimsUtils.isStringEmptyOrNull(scientificName), "Must provide a scientificName to create a Sample"); if (sampleAdditionalInfo == null) { log.debug("Create a simple unparented MISO Sample."); return new SampleImpl(this); } else { checkArgument(sampleAdditionalInfo != null, "SampleAdditionalInfo must be provided to create a Sample."); checkArgument(sampleAdditionalInfo.getSampleClass() != null, "SampleAdditionalInfo.sampleClass must be provided to create a Sample."); if (identity != null) { log.debug("Create an Identity Sample."); checkArgument(rootSampleClass != null, "A root SampleClass must be provided to create an Identity Sample."); return new SampleIdentityNode(this); } else if (sampleAnalyte != null) { log.debug("Create an Analyte Sample."); checkArgument(parent != null, "parent must be provided to create a Sample."); checkArgument(sampleAdditionalInfo.getTissueOrigin() != null, "SampleAdditionalInfo.tissueOrigin must be provided to create a Sample."); checkArgument(sampleAdditionalInfo.getTissueType() != null, "SampleAdditionalInfo.tissueType must be provided to create a Sample."); return SampleImpl.sampleAnalyte(this); } } throw new IllegalArgumentException("No sample can be built with the specified parameters."); }

Target:
public Sample build() { checkArgument(user != null, "A User must be provided to create a Sample."); checkArgument(project != null, "A Project must be provided to create a Sample."); checkArgument(!LimsUtils.isStringEmptyOrNull(description), "Must provide a description to create a Sample"); checkArgument(!LimsUtils.isStringEmptyOrNull(sampleType), "Must provide a sampleType to create a Sample"); checkArgument(!LimsUtils.isStringEmptyOrNull(scientificName), "Must provide a scientificName to create a Sample"); if (sampleAdditionalInfo == null) { log.debug("Create a simple unparented MISO Sample."); return new SampleImpl(this); } else { checkArgument(sampleAdditionalInfo != null, "SampleAdditionalInfo must be provided to create a Sample."); checkArgument(sampleAdditionalInfo.getSampleClass() != null, "SampleAdditionalInfo.sampleClass must be provided to create a Sample."); if (identity != null) { log.debug("Create an Identity Sample."); checkArgument(rootSampleClass != null, "A root SampleClass must be provided to create an Identity Sample."); return new SampleIdentityNode(this); } else if (sampleAnalyte != null) { log.debug("Create an Analyte Sample."); checkArgument(parent != null, "parent must be provided to create a Sample."); checkArgument(sampleAdditionalInfo.getTissueOrigin() != null, "SampleAdditionalInfo.tissueOrigin must be provided to create a Sample."); checkArgument(sampleAdditionalInfo.getTissueType() != null, "SampleAdditionalInfo.tissueType must be provided to create a Sample."); return SampleImpl.sampleAnalyte(this); } else if (sampleTissue != null) { return SampleImpl.sampleTissue(this); } } throw new IllegalArgumentException("No sample can be built with the specified parameters."); }