Path: csiph.com!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!feeder.erje.net!2.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.java.programmer Subject: Re: How to handle same sanity checks Date: Fri, 23 Jun 2017 06:51:01 +0200 Organization: Decebal Computing Lines: 23 Message-ID: <87bmpfnw7e.fsf@munus.decebal.nl> References: <87o9tgo0a9.fsf@munus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="f007575c907e67c534b3e9f520a75a29"; logging-data="11185"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/AklJ0QQyvMZyHLc49x9fON2cQ9bf9U18=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:DqKWNG8zR4BRKLX6Nd1czUADGpI= sha1:lqTTVdSzU4MSfOW95+R5ltCrKtg= Xref: csiph.com comp.lang.java.programmer:36703 On Thursday 22 Jun 2017 12:27 CEST, Martin Gregorie wrote: > I agree that using such a method would tidy up the calling code, but > if I used this type of method I'd generalise it to something like > this: > > private void checkInRange(int n, > int lowLimit, > int highLimit, > String error) > { > String format = "%s: %d is outside range %d - %d"; > if ((n < lowLimit) || (n > highLimit)) > throw new InvalidParameterException( > String.format(format,error, n, lowLimit, highLimit)); > } I implemented your function. See my reply to Volker Borchert. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof