public LCMSDataSubset merge ( LCMSDataSubset other ) { LCMSDataSubset merged = new LCMSDataSubset ( ) ; Set < Integer > msLvlsThis = getMsLvls ( ) ; Set < Integer > msLvlsThat = other . getMsLvls ( ) ; // only merge if both are not null, otherwise null signifies the whole // run, so we can keep it null in the merged version if ( msLvlsThis != null && msLvlsThat != null ) { HashSet < Integer > mergedMsLvls = new HashSet <> ( msLvlsThis ) ; mergedMsLvls . addAll ( msLvlsThat ) ; merged . setMsLvls ( mergedMsLvls ) ; } // merge mz ranges List < DoubleRange > mzRangesThis = getMzRanges ( ) ; List < DoubleRange > mzRangesThat = other . getMzRanges ( ) ; if ( mzRangesThis != null && mzRangesThat != null ) { ArrayList < DoubleRange > mergedMzRanges = new ArrayList <> ( mzRangesThis ) ; mergedMzRanges . addAll ( mzRangesThat ) ; merged . setMzRanges ( mergedMzRanges ) ; } // compare scan number ranges Integer scanNumLoThis = getScanNumLo ( ) ; Integer scanNumLoThat = other . getScanNumLo ( ) ; if ( scanNumLoThis != null && scanNumLoThat != null ) { merged . setScanNumLo ( Math . min ( scanNumLoThis , scanNumLoThat ) ) ; } Integer scanNumHiThis = getScanNumHi ( ) ; Integer scanNumHiThat = other . getScanNumHi ( ) ; if ( scanNumHiThis != null && scanNumHiThat != null ) { merged . setScanNumHi ( Math . max ( scanNumHiThis , scanNumHiThat ) ) ; } return merged ; }
Doesn t modify original values always returns a new one .