public static Interval fromIntervalNumber(int intervalNumber, boolean preferMajor)
            throws UnknownIntervalException {
        for (Interval interval : Interval.values()) {
            if (interval.intervalNumber != null && interval.intervalNumber == intervalNumber) {
                if (interval.intervalQuality == IntervalQuality.Perfect) {
                    return interval;
                }
                if (preferMajor && interval.intervalQuality == IntervalQuality.Major) {
                    return interval;
                } else if (!preferMajor && interval.intervalQuality == IntervalQuality.Minor) {
                    return interval;
                }
            }
        }
        throw new UnknownIntervalException("Unknown interval with interval number " + intervalNumber);
    }