On Thu, Mar 16, 2023, 3:15 AM Hasan Diwan <hasan.di...@gmail.com> wrote:

> Looking through StringUtils[1]m most of the methods have an "IgnoreCase"
> variant, so I don't think one needs to DO anything to achieve this. If you
> want to fold the ignoreCase variants, add something like:
>
>     private static boolean disregardCase = false;
>     /**
>      * Sets case-insensitivity in a fluent manner
>      */
>     private static StringUtils foldCase(String value) {
> if(startsWith(str, prefix, false);disregardCase) {
>    this.value = this.value.toLowerCase();
> }
>     }
>
>     public static StringUtils withCaseInsensitivity() {
> disregardCase = true;
> return this;
>     }
>
>     public static StringUtils withCaseSensitivity() {
> disregardCase = false;
> return this;
>     }
>
> and change all the relevant methods to call foldCase before doing their
> thing. -- H
>

My concern is the whole idiom. Is it more natural to say
"withCaseInsensitivity" or "withoutCaseSensitivity"? From questions like
that you get to withCaseSensitivity(boolean) and from there I evolved to an
enum because its constants are more expressive than true/false. Concerns
other than case sensitivity may be non-binary, yielding even more methods.
Generally speaking, if behavior is modeled in this way, there is gained the
possibility of placing the responsibility of setting a flag in the proposed
Strings object, or indeed more complex behavior, on the enum instance. If
all behavioral options were expressed in this way, the actual builder API
might consist of quite a limited number (in the sense of method names) of
(perhaps heavily overloaded) methods.

Matt

-- 
> OpenPGP: https://hasan.d8u.us/openpgp.asc
> If you wish to request my time, please do so using
> *bit.ly/hd1AppointmentRequest
> <http://bit.ly/hd1AppointmentRequest>*.
> Si vous voudrais faire connnaisance, allez a *bit.ly/hd1AppointmentRequest
> <http://bit.ly/hd1AppointmentRequest>*.
>
> <https://sks-keyservers.net/pks/lookup?op=get&search=0xFEBAD7FFD041BBA1
> >Sent
> from my mobile device
> Envoye de mon portable
>

Reply via email to