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

Method summarize

base/src/main/java/net/time4j/Duration.java:3293–3413  ·  view source on GitHub ↗
(
        TimeSpan<? extends U> timespan,
        long[] sums
    )

Source from the content-addressed store, hash-verified

3291 }
3292
3293 private static <U extends IsoUnit> boolean summarize(
3294 TimeSpan<? extends U> timespan,
3295 long[] sums
3296 ) {
3297
3298 long months = sums[0];
3299 long days = sums[1];
3300 long secs = sums[2];
3301 long nanos = sums[3];
3302
3303 for (Item<? extends U> item : timespan.getTotalLength()) {
3304 U unit = item.getUnit();
3305 long amount = item.getAmount();
3306
3307 if (timespan.isNegative()) {
3308 amount = MathUtils.safeNegate(amount);
3309 }
3310
3311 if (unit instanceof CalendarUnit) {
3312 CalendarUnit cu = CalendarUnit.class.cast(unit);
3313 switch (cu) {
3314 case MILLENNIA:
3315 months =
3316 MathUtils.safeAdd(months,
3317 MathUtils.safeMultiply(amount, 12 * 1000));
3318 break;
3319 case CENTURIES:
3320 months =
3321 MathUtils.safeAdd(months,
3322 MathUtils.safeMultiply(amount, 12 * 100));
3323 break;
3324 case DECADES:
3325 months =
3326 MathUtils.safeAdd(months,
3327 MathUtils.safeMultiply(amount, 12 * 10));
3328 break;
3329 case YEARS:
3330 months =
3331 MathUtils.safeAdd(months,
3332 MathUtils.safeMultiply(amount, 12));
3333 break;
3334 case QUARTERS:
3335 months =
3336 MathUtils.safeAdd(months,
3337 MathUtils.safeMultiply(amount, 3));
3338 break;
3339 case MONTHS:
3340 months = MathUtils.safeAdd(months, amount);
3341 break;
3342 case WEEKS:
3343 days =
3344 MathUtils.safeAdd(days,
3345 MathUtils.safeMultiply(amount, 7));
3346 break;
3347 case DAYS:
3348 days = MathUtils.safeAdd(days, amount);
3349 break;
3350 default:

Callers 1

plusMethod · 0.95

Calls 9

safeNegateMethod · 0.95
safeAddMethod · 0.95
safeMultiplyMethod · 0.95
getTotalLengthMethod · 0.65
isNegativeMethod · 0.65
nameMethod · 0.65
getUnitMethod · 0.45
getAmountMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected