public PeakSet subSet(double mz, double interval) {
        if (size() == 0) {
            return new PeakSet();
        }

        if (Double.compare(mz, first().getMz() - interval) < 0) {
            return new PeakSet();
        }

        if (Double.compare(mz, last().getMz() + interval) > 0) {
            return new PeakSet();
        }

        if (interval <= 0d) {
            return new PeakSet();
        }

        double start = mz - interval;
        double end = mz + interval;

        Peak startPeak;
        Peak endPeak;
        if (Double.compare(start, first().getMz()) <= 0) {
            startPeak = first();
        } else {
            //create a mock
            startPeak = new Peak(start, 0d);
            // location concrete start
            startPeak = floor(startPeak);
        }

        if (Double.compare(end, last().getMz()) >= 0) {
            endPeak = last();
        } else {
            endPeak = new Peak(end, 0d);
            endPeak = ceiling(endPeak);
        }

        NavigableSet<Peak> set = subSet(startPeak, true, endPeak, true);

        // create a new peak set, therefore, we can remove a peak from peak set safely.
        PeakSet result = new PeakSet(set);

        if (comparator.compare(mz - startPeak.getMz(), interval) > 0) {
            result.remove(startPeak);
        }

        if (comparator.compare(endPeak.getMz() - mz, interval) > 0) {
            result.remove(endPeak);
        }

        return result;
    }