From dev-return-166513-archive-asf-public=cust-asf.ponee.io@commons.apache.org Fri Feb 23 22:01:43 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id B827B180652 for ; Fri, 23 Feb 2018 22:01:42 +0100 (CET) Received: (qmail 16102 invoked by uid 500); 23 Feb 2018 21:01:41 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 16090 invoked by uid 99); 23 Feb 2018 21:01:40 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Feb 2018 21:01:40 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 6AFFB1A057F for ; Fri, 23 Feb 2018 21:01:40 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.898 X-Spam-Level: * X-Spam-Status: No, score=1.898 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id fIqExv5_VRCH for ; Fri, 23 Feb 2018 21:01:36 +0000 (UTC) Received: from mail-qk0-f172.google.com (mail-qk0-f172.google.com [209.85.220.172]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id A686F5F189 for ; Fri, 23 Feb 2018 21:01:35 +0000 (UTC) Received: by mail-qk0-f172.google.com with SMTP id y137so12398466qka.4 for ; Fri, 23 Feb 2018 13:01:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=6qmwjIsu/wCHqL4ovO7AQaN2wew4gp3x3rSGc/eImog=; b=UeGyR9M7PQXCVWa6n8z5p7f5KZpNmp+DdKr9aZ0vMXS6eysJ8ywR+Z0oRWQ2a8V8wg KqE5R5+/lSKpTHsC3lHT2XfqUftE0SdNn45r+tTOKbTjjW4YOyDRngt4BE9qSJ6BC+T1 xGwiRF7rHn7vYQw8dltyMLn5e0c/4V/uzfHIZ2jD4L32G+ew95KotgOMc0aOisyruZhb w0gstpVjyCzEX6hmftz/8PN82tuxNIqfGAVWkzAsb/sTM48wv6IBV/3UD/Y1CFEeeUJM /RI4BkuOW/QFr3Swg4j/FHjNx694DawNvA2nh6mpHMDZtMLEUm4ZQNJtnpS2VsgyA5PU ICbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=6qmwjIsu/wCHqL4ovO7AQaN2wew4gp3x3rSGc/eImog=; b=a1sH+aoFwkhblrl8dwIBqAWlEtLWG3exqMYNBgePvOHMzQNsA64Sw39SldP8GkYJy7 J5TRl4zTHZiQhp96+UsrqhWl9Ymnu/nSkXJBlCv83TaQO4btzmG1u+IX9I9vvRVV2HEe 0BiUIwmr98wVqeKt2ujor+DEIBrEhVuvsoUnAVwi6V2gKdyxHLhIVHLeAcueg0yRRcyk SIXIAH1sHvyvNf0/QoHzTQxpeY78fWBjZg/FMekg6WZGyLyK/l0Np6f74QJlG4R1vZQ9 Ygq8H4tSSCV/p6lbmrEbS9Kz98edUXfsZWKfWvBxHzju5tHlZc9qG9X5joqjLhjAmVmX GW4A== X-Gm-Message-State: APf1xPAm6sGFguxFZEyoFTZAw8BC+br1UgmorTVVg/ko/++/0SYtY2XM 284kzhBnB3RWeJzCfkF0I/nIH1R3EO5O67FgOmuI X-Google-Smtp-Source: AG47ELvncIKmsOuaX9v9hbdk2dBj9nF87uDB7cJXVbsO8WQugXEXlw0vnotrUDfNK4369OvlwVO1RrlDkAVbAPD0Sdo= X-Received: by 10.55.81.10 with SMTP id f10mr4667997qkb.21.1519419693984; Fri, 23 Feb 2018 13:01:33 -0800 (PST) MIME-Version: 1.0 Received: by 10.237.33.148 with HTTP; Fri, 23 Feb 2018 13:01:33 -0800 (PST) In-Reply-To: <1217A168-BFB9-4D8F-9326-0D25C22957A8@apache.org> References: <1217A168-BFB9-4D8F-9326-0D25C22957A8@apache.org> From: Gary Gregory Date: Fri, 23 Feb 2018 14:01:33 -0700 Message-ID: Subject: Re: [text] Upper/Lower case enum To: Commons Developers List Content-Type: multipart/alternative; boundary="001a114a843e1ff0dd0565e777eb" --001a114a843e1ff0dd0565e777eb Content-Type: text/plain; charset="UTF-8" On Fri, Feb 23, 2018 at 12:53 PM, ajs6f wrote: > Perhaps ? > Try it, I do not think it is so nice, mostly because just like with char[] that means converting everything to a String to get to String#toUpper/LowerCase. Unless we reimplement the algorithm ourselves. Gary > ajs6f > > > On Feb 23, 2018, at 12:12 PM, Gary Gregory > wrote: > > > > On Fri, Feb 23, 2018 at 10:05 AM, Gary Gregory > > wrote: > > > >> > >> > >> On Fri, Feb 23, 2018 at 10:04 AM, Gary Gregory > >> wrote: > >> > >>> > >>> > >>> On Fri, Feb 23, 2018 at 7:03 AM, Matt Benson > wrote: > >>> > >>>> On Feb 23, 2018 4:26 AM, "sebb" wrote: > >>>> > >>>> On 23 February 2018 at 00:41, Gary Gregory > >>>> wrote: > >>>>> On Thu, Feb 22, 2018 at 4:27 PM, sebb wrote: > >>>>> > >>>>>> On 22 February 2018 at 23:15, Gary Gregory > >>>> wrote: > >>>>>>> On Thu, Feb 22, 2018 at 4:11 PM, sebb wrote: > >>>>>>> > >>>>>>>> On 22 February 2018 at 22:27, Gary Gregory < > garydgregory@gmail.com > >>>>> > >>>>>> wrote: > >>>>>>>>> Use your imagination ;-) > >>>>>>>> > >>>>>>>> What would the new code look like? > >>>>>> > >>>>>> I mean the user code before and after the enum is introduced. > >>>>>> > >>>>> > >>>>> I don't have code for the _before_ since I wrote the enum to avoid > it. > >>>>> > >>>>> I have a different util class that gets called like this: > >>>>> > >>>>> HexDump(byte[] data, LetterCase letterCase, more details...) > >>>> > >>>> The above is only using the enum as a way to provide the requested > >>>> type of transform. > >>>> > >>>> The important bit is the code that uses the enum to do the transform. > >>>> > >>>> > >>>> Obviously the method body would call #toCaseString() passing a String > and > >>>> Locale as arguments. This question feels like trolling, as does the > >>>> insinuation that true/false *might not* be less clear in intent than > >>>> UPPER/LOWER, or vice versa as, again, we don't know what the > hypothetical > >>>> API author was thinking in the case of boolean. WTH > >>>> > >>> > >>> Thanks Matt for pointing that out. The comment did feel trollish to me > as > >>> well but I choose not to engage. Aside from that I really like Sebb's > >>> contributions to our community, his diligence and attention to detail. > >>> I did not think I needed to make some pedantic point about an enum > being > >>> much better than a boolean to express letter case or toggles in > general. > >>> > >>> > >>>> The comment about Java 8 is fine as far as it goes, but doesn't really > >>>> invalidate this as the method supplied can easily be used as a > >>>> BiFunction. > >>>> Gary, I'm thinking you might as well "underload" the method to pass > the > >>>> default Locale to the two-argument variant so then you also implement > >>>> Function in the simple case. Then I'm sold. For a bonus you might > provide > >>>> char method variants as well. > >>>> > >>> > >>> OK, sounds good. Like this then: > >>> [https://pastebin.com/mJw2tDHj] > >>> > >> > >> Without the @author tag of course. > >> > > > > There is also CharBuffer... I only have use for String. > > > > Gary > > > > > >> > >> G > >> > >>> > >>> import java.util.Locale; > >>> > >>> /** > >>> * Enumerates letter cases and converts strings. > >>> * > >>> * @author Gary > Gregory > >>> */ > >>> public enum LetterCase { > >>> > >>> LOWER { > >>> @Override > >>> public char[] toCaseString(final char[] source, final Locale > >>> locale) { > >>> return String.valueOf(source).toLower > >>> Case(locale).toCharArray(); > >>> } > >>> > >>> @Override > >>> public String toCaseString(final String source, final Locale > >>> locale) { > >>> return source.toLowerCase(locale); > >>> } > >>> > >>> }, > >>> UPPER { > >>> @Override > >>> public char[] toCaseString(final char[] source, final Locale > >>> locale) { > >>> return String.valueOf(source).toUpper > >>> Case(locale).toCharArray(); > >>> } > >>> > >>> @Override > >>> public String toCaseString(final String source, final Locale > >>> locale) { > >>> return source.toUpperCase(locale); > >>> } > >>> }; > >>> > >>> /** > >>> * Converts from the given {@code source} string to the case > >>> specified by this enum using the default {@code locale}. > >>> * > >>> * @param source > >>> * the string to convert > >>> * @param locale > >>> * the locale to use for conversion. > >>> * @return a converted string. > >>> */ > >>> public char[] toCaseString(final char[] source) { > >>> return toCaseString(source, Locale.getDefault()); > >>> } > >>> > >>> /** > >>> * Converts from the given {@code source} char[] to the case > >>> specified by this enum using the given {@code locale}. > >>> * > >>> * @param source > >>> * the char[] to convert > >>> * @param locale > >>> * the locale to use for conversion. > >>> * @return a converted char[]. > >>> */ > >>> public abstract char[] toCaseString(char[] source, Locale locale); > >>> > >>> /** > >>> * Converts from the given {@code source} string to the case > >>> specified by this enum using the default {@code locale}. > >>> * > >>> * @param source > >>> * the string to convert > >>> * @param locale > >>> * the locale to use for conversion. > >>> * @return a converted string. > >>> */ > >>> public String toCaseString(final String source) { > >>> return toCaseString(source, Locale.getDefault()); > >>> } > >>> > >>> /** > >>> * Converts from the given {@code source} string to the case > >>> specified by this enum using the given {@code locale}. > >>> * > >>> * @param source > >>> * the string to convert > >>> * @param locale > >>> * the locale to use for conversion. > >>> * @return a converted string. > >>> */ > >>> public abstract String toCaseString(String source, Locale locale); > >>> > >>> } > >>> > >>> Gary > >>> > >>> > >>>> Matt > >>>> > >>>> > >>>>> This is much clearer than using a boolean for the letter case. > >>>> > >>>> YMMV > >>>> > >>>>> Gary > >>>>> > >>>>> > >>>>>> > >>>>>>>> > >>>>>>> > >>>>>>> I posted the code at the start of this thread... > >>>>>>> > >>>>>>> Gary > >>>>>>> > >>>>>>> > >>>>>>>> > >>>>>>>> How does it compare with code that does not have the enum? > >>>>>>>> > >>>>>>>>> I use it in the following contexts: > >>>>>>>>> - To pass to a hex dump method to configure where the alpha chars > >>>>>> should > >>>>>>>> be > >>>>>>>>> in lower case or upper case. > >>>>>>>>> - To configure a parameterized JUnit test class to configure the > >>>> case > >>>>>> of > >>>>>>>>> HTTP headers and values. > >>>>>>>>> - To normalize input > >>>>>>>>> > >>>>>>>>> Gary > >>>>>>>>> > >>>>>>>>> > >>>>>>>>> On Thu, Feb 22, 2018 at 3:14 PM, Otto Fowler < > >>>> ottobackwards@gmail.com > >>>>>>> > >>>>>>>>> wrote: > >>>>>>>>> > >>>>>>>>>> What problem does it solve? > >>>>>>>>>> > >>>>>>>>>> On February 22, 2018 at 17:02:34, Gary Gregory ( > >>>>>> garydgregory@gmail.com) > >>>>>>>>>> wrote: > >>>>>>>>>> > >>>>>>>>>> Does anyone think this is useful and general enough to add to > >>>> Commons > >>>>>>>>>> Text: > >>>>>>>>>> > >>>>>>>>>> /** > >>>>>>>>>> * Enumerates letter cases and converts strings. > >>>>>>>>>> * > >>>>>>>>>> * @author Gary > >>>>>> Gregory > >>>>>>>>>> */ > >>>>>>>>>> public enum LetterCase { > >>>>>>>>>> LOWER { > >>>>>>>>>> @Override > >>>>>>>>>> public String toCaseString(final String source, final Locale > >>>>>>>>>> locale) { > >>>>>>>>>> return source.toLowerCase(locale); > >>>>>>>>>> } > >>>>>>>>>> > >>>>>>>>>> }, > >>>>>>>>>> UPPER { > >>>>>>>>>> @Override > >>>>>>>>>> public String toCaseString(final String source, final Locale > >>>>>>>>>> locale) { > >>>>>>>>>> return source.toUpperCase(locale); > >>>>>>>>>> } > >>>>>>>>>> }; > >>>>>>>>>> > >>>>>>>>>> /** > >>>>>>>>>> * Converts from the given {@code source} string to the case > >>>> specified > >>>>>>>>>> by this enum using the given {@code locale}. > >>>>>>>>>> * > >>>>>>>>>> * @param source > >>>>>>>>>> * the string to convert > >>>>>>>>>> * @param locale > >>>>>>>>>> * the locale to use for conversion. > >>>>>>>>>> * @return a converted string. > >>>>>>>>>> */ > >>>>>>>>>> public abstract String toCaseString(String source, Locale > >>>> locale); > >>>>>>>>>> } > >>>>>>>>>> > >>>>>>>>>> ? > >>>>>>>>>> > >>>>>>>>>> Thank you, > >>>>>>>>>> Gary > >>>>>>>>>> > >>>>>>>>>> > >>>>>>>> > >>>>>>>> ------------------------------------------------------------ > >>>> --------- > >>>>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > >>>>>>>> For additional commands, e-mail: dev-help@commons.apache.org > >>>>>>>> > >>>>>>>> > >>>>>> > >>>>>> ------------------------------------------------------------ > --------- > >>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > >>>>>> For additional commands, e-mail: dev-help@commons.apache.org > >>>>>> > >>>>>> > >>>> > >>>> --------------------------------------------------------------------- > >>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > >>>> For additional commands, e-mail: dev-help@commons.apache.org > >>>> > >>> > >>> > >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > --001a114a843e1ff0dd0565e777eb--