Source:
<code>static Period roundToPrecision(Period period, Precision start, Precision end) { if (start == null && end == null) { return period; } if (start == Precision.YEAR && end == null) { return Period.years(period.getYears()); } if (start == Precision.YEAR && end == Precision.MONTH) { return Period.years(period.getYears()).withMonths(period.getMonths()); } if (start == Precision.MONTH && end == null) { return Period.years(period.getYears()).withMonths(period.getMonths()); } if (start == Precision.DAY && end == null) { return new Period(period).withHours(0).withMinutes(0).withSeconds(0).withMillis(0); } <START> if (start == Precision.DAY && end == Precision.HOUR) { <END> return new Period(period).withMinutes(0).withSeconds(0).withMillis(0); } if (start == Precision.DAY && end == Precision.MINUTE) { return new Period(period).withSeconds(0).withMillis(0); } if (start == Precision.DAY && end == Precision.SECOND) { return new Period(period).withMillis(0); } if (start == Precision.HOUR && end == null) { return new Period(period).withMinutes(0).withSeconds(0).withMillis(0); } if (start == Precision.HOUR && end == Precision.MINUTE) { return new Period(period).withSeconds(0).withMillis(0); } if (start == Precision.HOUR && end == Precision.SECOND) { return new Period(period).withMillis(0); } if (start == Precision.MINUTE && end == null) { return new Period(period).withSeconds(0).withMillis(0); } if (start == Precision.MINUTE && end == Precision.SECOND) { return new Period(period).withMillis(0); } if (start == Precision.SECOND && end == null) { return new Period(period).withMillis(0); } throw new IllegalArgumentException(String.format("Invalid start and end combination", start, end)); }</code><technical_language>a single if (start == Precision.DAY) branch handle end cases avoid repeated start == DAY checks</technical_language>

Target:
static Period roundToPrecision(Period period, Precision start, Precision end) { if (start == null && end == null) { return period; } if (start == Precision.YEAR) { if (end == null) { return Period.years(period.getYears()); } if (end == Precision.MONTH) { return Period.years(period.getYears()).withMonths(period.getMonths()); } } if (start == Precision.MONTH && end == null) { return Period.years(period.getYears()).withMonths(period.getMonths()); } if (start == Precision.DAY) { if (end == null) { return period.withHours(0).withMinutes(0).withSeconds(0).withMillis(0); } if (end == Precision.HOUR) { return period.withMinutes(0).withSeconds(0).withMillis(0); } if (end == Precision.MINUTE) { return period.withSeconds(0).withMillis(0); } if (end == Precision.SECOND) { return period.withMillis(0); } } if (start == Precision.HOUR) { if (end == null) { return period.withMinutes(0).withSeconds(0).withMillis(0); } if (end == Precision.MINUTE) { return period.withSeconds(0).withMillis(0); } if (end == Precision.SECOND) { return period.withMillis(0); } } if (start == Precision.MINUTE) { if (end == null) { return period.withSeconds(0).withMillis(0); } if (end == Precision.SECOND) { return period.withMillis(0); } } if (start == Precision.SECOND && end == null) { return period.withMillis(0); } throw new IllegalArgumentException("Invalid start and end combination"); }