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

Method apply

base/src/main/java/net/time4j/RoundingOperator.java:70–96  ·  view source on GitHub ↗
(T entity)

Source from the content-addressed store, hash-verified

68 //~ Methoden ----------------------------------------------------------
69
70 @Override
71 public T apply(T entity) {
72
73 double value = entity.get(this.element).doubleValue();
74 double nv;
75
76 if (this.up == null) {
77 double high = Math.ceil(value / this.stepwidth) * this.stepwidth;
78 double low = Math.floor(value / this.stepwidth) * this.stepwidth;
79 nv = ((value - low < high - value) ? low : high);
80 } else if (this.up.booleanValue()) {
81 nv = Math.ceil(value / this.stepwidth) * this.stepwidth;
82 } else {
83 nv = Math.floor(value / this.stepwidth) * this.stepwidth;
84 }
85
86 Number num;
87
88 if (this.longBased) {
89 num = Long.valueOf((long) nv);
90 } else {
91 num = Integer.valueOf((int) nv);
92 }
93
94 return entity.with(lenient(this.element, num));
95
96 }
97
98 private static <V extends Number, T extends ChronoEntity<T>>
99 ChronoOperator<T> lenient(

Callers

nothing calls this directly

Calls 5

lenientMethod · 0.95
floorMethod · 0.80
getMethod · 0.65
withMethod · 0.65
valueOfMethod · 0.45

Tested by

no test coverage detected