| 3849 | } |
| 3850 | |
| 3851 | private static <U extends ChronoUnit> ChronoUnit addParsedItem( |
| 3852 | ChronoUnit unit, |
| 3853 | ChronoUnit last, // optional |
| 3854 | long amount, |
| 3855 | String period, |
| 3856 | int index, |
| 3857 | List<Item<U>> items |
| 3858 | ) throws ParseException { |
| 3859 | |
| 3860 | if ( |
| 3861 | (last == null) |
| 3862 | || (Double.compare(unit.getLength(), last.getLength()) < 0) |
| 3863 | ) { |
| 3864 | if (amount != 0) { |
| 3865 | U reified = cast(unit); |
| 3866 | items.add(Item.of(amount, reified)); |
| 3867 | } |
| 3868 | return unit; |
| 3869 | } else if (Double.compare(unit.getLength(), last.getLength()) == 0) { |
| 3870 | throw new ParseException( |
| 3871 | "Duplicate unit items: " + period, index); |
| 3872 | } else { |
| 3873 | throw new ParseException( |
| 3874 | "Wrong order of unit items: " + period, index); |
| 3875 | } |
| 3876 | |
| 3877 | } |
| 3878 | |
| 3879 | private static long parseAmount( |
| 3880 | String period, |