In your example, you should replace
perc = perc.withEstimationType(EstimationType.R_5);
withEstimationType does not change the current instance, it creates a new instance, as documented in the Javadoc. The various
withXXX methods in several Hipparchus classes follow a mix of both the builder design patter and the fluent design pattern. They are expected to be used as follows:
SomeClass theFinalizedObject = new BasicConstructor(...).
So the object you get after the execution of this statement is in fact the fourth object built. The three previous objetcs are only temporary. The reason for this design choice is that it allows highly versatile construction with many variations, while keeping the API simple and readable. Built objects can also be kept immutable, which often improves performances.
This design is well suited when objects are built once (out of a loop) and used several times (inside a loop). Its advantages are more dubious when objects are created on the fly and used only once, because we really build n objects when we need one. In order to handle gracefully also this case, we could (should?) switch to a more canonical builder design pattern, where the builder and the built object correspond to different classes, the builder being mutable while the built object is immutable and built only during a final call to a no-argument
build() method. We did not make this move yet.