> > [...]
> > [...] is that check
> > ---CUT---
> >          if (!(source.normalized instanceof SharedStateSampler<?>)) {
> >              throw new UnsupportedOperationException("The underlying
> > sampler is not a SharedStateSampler");
> >          }
> > ---CUT---
> > necessary?
>
> That was already in the codebase. I added it to support
> SharedStateSampler in RNG-102.
>
> The withUniformRandomProvider method is documented to:
>
> @throws UnsupportedOperationException if the underlying sampler is not
> a {@link SharedStateSampler}.
> @throws ClassCastException if the underlying {@link SharedStateSampler}
> does not return a {@link NormalizedGaussianSampler}.
>
> So currently the two cases can be distinguished. If we drop the
>
> source.normalized instanceof SharedStateSampler<?>
>
> check then the next part will throw a ClassCastException if either case
> is true.
>
> So the question is really what exception should be raised in the rare
> case that the operation cannot be performed (because the user created
> with a NormalizedGaussianSampler not from the library). The
> ClassCastException (which indicates the executing code did not check
> what it can do) could be caught and rethrown as an
> UnsupportedOperationException. Or the object could be tested with
> instanceof before the cast. This would at least be consistent and show
> the code knows what it is doing. So if a user calls:
>
> GaussianSampler.withUniformRandomProvider(rng)
>
> The only exception they have to handle is an
> UnsupportedOperationException. An alternative would be an
> IllegalStateException but that would indicate that the method would be
> possible but not at this time. I think this would be better than a
> ClassCastException.
>
> My vote is to make UnsupportedOperationException the only exception to
> be thrown. The ClassCastException to allow the cases to be separated is
> unnecessary.

I'm fine with that.

Regards,
Gilles

>
> I can change this in master. It is only in GaussianSampler and
> LogNormalSampler. There are already unit tests for the edge cases so
> these just have to be updated to expect the appropriate documented
> exception.
>
>
> > [...]

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to