Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6BABA200CDE for ; Mon, 24 Jul 2017 19:36:09 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 69DB5163B2F; Mon, 24 Jul 2017 17:36:09 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B71A4163B27 for ; Mon, 24 Jul 2017 19:36:08 +0200 (CEST) Received: (qmail 60810 invoked by uid 500); 24 Jul 2017 17:36:07 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 60798 invoked by uid 99); 24 Jul 2017 17:36:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Jul 2017 17:36:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 620FB1805D0 for ; Mon, 24 Jul 2017 17:36:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id i-k85jfgsAmM for ; Mon, 24 Jul 2017 17:36:05 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 1413C5FD7C for ; Mon, 24 Jul 2017 17:36:03 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 87E31E0BCB for ; Mon, 24 Jul 2017 17:36:02 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 6668C23F1D for ; Mon, 24 Jul 2017 17:36:00 +0000 (UTC) Date: Mon, 24 Jul 2017 17:36:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (TEXT-98) Remove isDelimiter() and use HashSets for delimiter check MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 24 Jul 2017 17:36:09 -0000 [ https://issues.apache.org/jira/browse/TEXT-98?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16098884#comment-16098884 ] ASF GitHub Bot commented on TEXT-98: ------------------------------------ Github user ameyjadiye commented on a diff in the pull request: https://github.com/apache/commons-text/pull/57#discussion_r129102692 --- Diff: src/main/java/org/apache/commons/text/WordUtils.java --- @@ -747,45 +750,29 @@ public static boolean containsAllWords(final CharSequence word, final CharSequen return true; } - //----------------------------------------------------------------------- + // ----------------------------------------------------------------------- /** - * Is the character a delimiter. + *

+ * Converts an array of delimiters to a hash set of code points. Code point of space(32) is added as the default + * value if delimiters is null. The generated hash set provides O(1) lookup time. + *

* - * @param ch the character to check - * @param delimiters the delimiters - * @return true if it is a delimiter + * @param delimiters set of characters to determine capitalization, null means whitespace + * @return Set */ - public static boolean isDelimiter(final char ch, final char[] delimiters) { - if (delimiters == null) { - return Character.isWhitespace(ch); - } - for (final char delimiter : delimiters) { - if (ch == delimiter) { - return true; + private static Set generateDelimiterSet(final char[] delimiters) { + Set delimiterHashSet = new HashSet<>(); + if (delimiters == null || delimiters.length == 0) { + if (delimiters == null) { + delimiterHashSet.add(Character.codePointAt(new char[] {' '}, 0)); } + return delimiterHashSet; } - return false; - } - //----------------------------------------------------------------------- - /** - * Is the codePoint a delimiter. - * - * @param codePoint the codePint to check - * @param delimiters the delimiters - * @return true if it is a delimiter - */ - public static boolean isDelimiter(final int codePoint, final char[] delimiters) { --- End diff -- Rather removing we should keep this method. > Remove isDelimiter() and use HashSets for delimiter check > --------------------------------------------------------- > > Key: TEXT-98 > URL: https://issues.apache.org/jira/browse/TEXT-98 > Project: Commons Text > Issue Type: Improvement > Affects Versions: 1.1 > Reporter: Arun Vinud > Priority: Minor > Fix For: 1.2 > > > The current implementation of *capitalize*, *uncapitalize* and *initials* in *WordUtils* calls *isDelimiter* for every character and/or codepoint and isDelimiter loops through the array of delimiters to check for the occurrence. This is a bit inefficient and results in O(nk) complexity and it can be reduced to O( n )[if n>k] or O( k ) [if k>n]. -- This message was sent by Atlassian JIRA (v6.4.14#64029)