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

Method safeAdd

base/src/main/java/net/time4j/base/MathUtils.java:87–110  ·  view source on GitHub ↗
(
        int op1,
        int op2
    )

Source from the content-addressed store, hash-verified

85 * @throws ArithmeticException if int-range overflows
86 */
87 public static int safeAdd(
88 int op1,
89 int op2
90 ) {
91
92 if (op2 == 0) {
93 return op1;
94 }
95
96 long result = ((long) op1) + ((long) op2);
97
98 if ((result < Integer.MIN_VALUE) || (result > Integer.MAX_VALUE)) {
99 StringBuilder sb = new StringBuilder(32);
100 sb.append("Integer overflow: (");
101 sb.append(op1);
102 sb.append(',');
103 sb.append(op2);
104 sb.append(')');
105 throw new ArithmeticException(sb.toString());
106 } else {
107 return (int) result;
108 }
109
110 }
111
112 /**
113 * <p>Sums up the numbers with range check. </p>

Callers 15

pushDurationMethod · 0.95
pushMethod · 0.95
convertMethod · 0.95
betweenMethod · 0.95
fromMethod · 0.95
fromMethod · 0.95
betweenMethod · 0.95
addToMethod · 0.95
normalizeMethod · 0.95
doAddMethod · 0.95
fromEpochMonthsMethod · 0.95
addDaysMethod · 0.95

Calls 1

toStringMethod · 0.65

Tested by

no test coverage detected