| 5036 | } |
| 5037 | |
| 5038 | private static class ApproximateNormalizer |
| 5039 | implements Normalizer<IsoUnit> { |
| 5040 | |
| 5041 | //~ Instanzvariablen ---------------------------------------------- |
| 5042 | |
| 5043 | private final boolean daysToWeeks; |
| 5044 | private final int steps; |
| 5045 | private final ClockUnit unit; |
| 5046 | |
| 5047 | //~ Konstruktoren ------------------------------------------------- |
| 5048 | |
| 5049 | ApproximateNormalizer(boolean daysToWeeks) { |
| 5050 | super(); |
| 5051 | |
| 5052 | this.daysToWeeks = daysToWeeks; |
| 5053 | this.steps = 1; |
| 5054 | this.unit = null; |
| 5055 | |
| 5056 | } |
| 5057 | |
| 5058 | ApproximateNormalizer( |
| 5059 | int steps, |
| 5060 | ClockUnit unit |
| 5061 | ) { |
| 5062 | super(); |
| 5063 | |
| 5064 | if (steps < 1) { |
| 5065 | throw new IllegalArgumentException( |
| 5066 | "Step width is not positive: " + steps); |
| 5067 | } else if (unit.compareTo(SECONDS) > 0) { |
| 5068 | throw new IllegalArgumentException("Unsupported unit."); |
| 5069 | } |
| 5070 | |
| 5071 | this.daysToWeeks = false; |
| 5072 | this.steps = steps; |
| 5073 | this.unit = unit; |
| 5074 | |
| 5075 | } |
| 5076 | |
| 5077 | //~ Methoden ------------------------------------------------------ |
| 5078 | |
| 5079 | @Override |
| 5080 | public Duration<IsoUnit> normalize(TimeSpan<? extends IsoUnit> dur) { |
| 5081 | |
| 5082 | double total = 0.0; |
| 5083 | boolean empty = true; |
| 5084 | |
| 5085 | for (int i = 0, n = dur.getTotalLength().size(); i < n; i++) { |
| 5086 | Item<? extends IsoUnit> item = dur.getTotalLength().get(i); |
| 5087 | total += (item.getAmount() * item.getUnit().getLength()); |
| 5088 | if (item.getAmount() > 0) { |
| 5089 | empty = false; |
| 5090 | } |
| 5091 | } |
| 5092 | |
| 5093 | if (empty) { |
| 5094 | return Duration.ofZero(); |
| 5095 | } |
nothing calls this directly
no outgoing calls
no test coverage detected