From commons-dev-return-97610-apmail-jakarta-commons-dev-archive=jakarta.apache.org@jakarta.apache.org Tue Jan 02 04:16:52 2007 Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 90370 invoked from network); 2 Jan 2007 04:16:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Jan 2007 04:16:50 -0000 Received: (qmail 56193 invoked by uid 500); 2 Jan 2007 04:16:55 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 56086 invoked by uid 500); 2 Jan 2007 04:16:55 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 56020 invoked by uid 99); 2 Jan 2007 04:16:55 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Jan 2007 20:16:55 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Jan 2007 20:16:47 -0800 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 86FBA7142D0 for ; Mon, 1 Jan 2007 20:16:27 -0800 (PST) Message-ID: <4199052.1167711387534.JavaMail.jira@brutus> Date: Mon, 1 Jan 2007 20:16:27 -0800 (PST) From: "Simon Kitching (JIRA)" To: commons-dev@jakarta.apache.org Subject: [jira] Commented: (LANG-238) [lang] Add equals(type[]) to NumberUtils MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ http://issues.apache.org/jira/browse/LANG-238?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12461664 ] Simon Kitching commented on LANG-238: ------------------------------------- I would agree with Stephen that an "allEquals(a)" method isn't likely to be widely used. And besides, it can be implemented for non-floating-point as: Set aSet = new HashSet(Arrays.asList(a)); boolean allEq = (aSet.size() <= 1); which doesn't seem to me sufficiently complicated to deserve inclusion in lang. A "containsOnly(a,b)" method would be more generally useful but can be implemented as: Set aSet = new HashSet(Arrays.asList(a)); Set bSet = new HashSet(Arrays.asList(b)); // or if b has one element, bSet = Collections.singleton(val); boolean contained = bSet.containsAll(aSet); which again doesn't seem terribly complicated. However if a more generic method is being considered, then how about: T[] notIn(T[] a, T[] b); which returns the elements in a that are not in b? I'm not a mathematician but I believe this is written in set operations as "a - b", or in words as "the complement of a with respect to b", so this method could also be called: T[] subtract(T[] a, T[] b); or T[] complement(T[] a, T[] b); though I think "notIn" is more obvious for most users. Actually, this operation is the array equivalent of Collections.removeAll, so that's an alternative name: T[] removeAll(T[] a, T[] b); The test "allEquals(a, b)" is then: boolean allEq = NumberUtils.notIn(a, b).length == 0; and the test "allEquals(a)" is: boolean allEq = NumberUtils.notIn(a, new Integer[] {a[0]}).length == 0; BTW, the "a" parameter is really an array representation of a bag, not a set so maybe this set terminology could be misleading. If such a set/bag operation is provided, then intersection and union could also reasonably be provided for arrays: T[] intersection(T[] a, T[] b); T[] union(T[] a, T[] b); Not sure whether union should treat its params as bags (in which case union would be equivalent to concat) or sets (only one occurrence for elements in both a and b). At this point, this appears to be bordering on commons-collections or commons-math functionality but as this is only for arrays I think a good argument could be made for including this in lang.. > [lang] Add equals(type[]) to NumberUtils > ---------------------------------------- > > Key: LANG-238 > URL: http://issues.apache.org/jira/browse/LANG-238 > Project: Commons Lang > Issue Type: Improvement > Affects Versions: Nightly Builds > Environment: Operating System: other > Platform: Other > Reporter: Paul Benedict > Priority: Minor > Fix For: 3.0 > > > It would be useful to add an equals() method like the current min and max > methods which take an array type and determine if all the values are equal. > I have found myself in need of this often. I have to retrieve objects from > multiple data sources in parallel to build an array of complex object. To ensure > validity, I always compare that my sub-retrievals returned the same number of > objects as expected. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org