MCPcopy Create free account
hub / github.com/MenoData/Time4J / normalize

Method normalize

base/src/main/java/net/time4j/StdNormalizer.java:100–263  ·  view source on GitHub ↗
(TimeSpan<? extends U> timespan)

Source from the content-addressed store, hash-verified

98 }
99
100 @SuppressWarnings("unchecked")
101 @Override
102 public Duration<U> normalize(TimeSpan<? extends U> timespan) {
103
104 int count = timespan.getTotalLength().size();
105 List<TimeSpan.Item<U>> items = new ArrayList<>(count);
106 long years = 0, months = 0, weeks = 0, days = 0;
107 long hours = 0, minutes = 0, seconds = 0, nanos = 0;
108
109 for (int i = 0; i < count; i++) {
110 TimeSpan.Item<? extends U> item = timespan.getTotalLength().get(i);
111 long amount = item.getAmount();
112 U unit = item.getUnit();
113
114 if (unit instanceof CalendarUnit) {
115 switch ((CalendarUnit.class.cast(unit))) {
116 case MILLENNIA:
117 years =
118 MathUtils.safeAdd(
119 MathUtils.safeMultiply(amount, 1000),
120 years
121 );
122 break;
123 case CENTURIES:
124 years =
125 MathUtils.safeAdd(
126 MathUtils.safeMultiply(amount, 100),
127 years
128 );
129 break;
130 case DECADES:
131 years =
132 MathUtils.safeAdd(
133 MathUtils.safeMultiply(amount, 10),
134 years
135 );
136 break;
137 case YEARS:
138 years = MathUtils.safeAdd(amount, years);
139 break;
140 case QUARTERS:
141 months =
142 MathUtils.safeAdd(
143 MathUtils.safeMultiply(amount, 3),
144 months
145 );
146 break;
147 case MONTHS:
148 months = MathUtils.safeAdd(amount, months);
149 break;
150 case WEEKS:
151 weeks = amount;
152 break;
153 case DAYS:
154 days = amount;
155 break;
156 default:
157 throw new UnsupportedOperationException(unit.toString());

Callers

nothing calls this directly

Calls 12

safeAddMethod · 0.95
safeMultiplyMethod · 0.95
getTotalLengthMethod · 0.65
getMethod · 0.65
toStringMethod · 0.65
ofMethod · 0.65
isNegativeMethod · 0.65
sizeMethod · 0.45
getAmountMethod · 0.45
getUnitMethod · 0.45
castMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected