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

Method create

base/src/main/java/net/time4j/Duration.java:3096–3141  ·  view source on GitHub ↗
(
        Map<U, Long> map,
        boolean negative
    )

Source from the content-addressed store, hash-verified

3094 }
3095
3096 private static <U extends IsoUnit> Duration<U> create(
3097 Map<U, Long> map,
3098 boolean negative
3099 ) {
3100
3101 if (map.isEmpty()) {
3102 return ofZero();
3103 }
3104
3105 List<Item<U>> temp = new ArrayList<>(map.size());
3106 long nanos = 0;
3107
3108 for (Map.Entry<U, Long> entry : map.entrySet()) {
3109 long amount = entry.getValue().longValue();
3110
3111 if (amount != 0) {
3112 U key = entry.getKey();
3113
3114 if (key == MILLIS) {
3115 nanos =
3116 MathUtils.safeAdd(
3117 nanos,
3118 MathUtils.safeMultiply(amount, MIO));
3119 } else if (key == MICROS) {
3120 nanos =
3121 MathUtils.safeAdd(
3122 nanos,
3123 MathUtils.safeMultiply(amount, 1000));
3124 } else if (key == NANOS) {
3125 nanos = MathUtils.safeAdd(nanos, amount);
3126 } else {
3127 temp.add(Item.of(amount, key));
3128 }
3129 }
3130 }
3131
3132 if (nanos != 0) {
3133 U key = cast(NANOS);
3134 temp.add(Item.of(nanos, key));
3135 } else if (temp.isEmpty()) {
3136 return ofZero();
3137 }
3138
3139 return new Duration<>(temp, negative);
3140
3141 }
3142
3143 // binäre Suche
3144 private int getIndex(ChronoUnit unit) {

Callers 3

plusMethod · 0.95
mergeMethod · 0.95
convertMethod · 0.95

Calls 10

ofZeroMethod · 0.95
safeAddMethod · 0.95
safeMultiplyMethod · 0.95
ofMethod · 0.95
castMethod · 0.95
isEmptyMethod · 0.65
getValueMethod · 0.65
sizeMethod · 0.45
getKeyMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected