Return-Path: X-Original-To: apmail-jena-commits-archive@www.apache.org Delivered-To: apmail-jena-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3BB0E18CF7 for ; Tue, 29 Dec 2015 21:23:23 +0000 (UTC) Received: (qmail 11149 invoked by uid 500); 29 Dec 2015 21:23:23 -0000 Delivered-To: apmail-jena-commits-archive@jena.apache.org Received: (qmail 11065 invoked by uid 500); 29 Dec 2015 21:23:23 -0000 Mailing-List: contact commits-help@jena.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jena.apache.org Delivered-To: mailing list commits@jena.apache.org Received: (qmail 10962 invoked by uid 99); 29 Dec 2015 21:23:23 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Dec 2015 21:23:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C88B1E0ACA; Tue, 29 Dec 2015 21:23:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: andy@apache.org To: commits@jena.apache.org Date: Tue, 29 Dec 2015 21:23:32 -0000 Message-Id: <7f59d8411f934f109cc7fce58d31fb50@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [11/12] jena git commit: From review of Tuple PR >From review of Tuple PR Project: http://git-wip-us.apache.org/repos/asf/jena/repo Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/9b5aec9c Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/9b5aec9c Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/9b5aec9c Branch: refs/heads/master Commit: 9b5aec9c38110069cd2f33cdd0d7866e952902bb Parents: 068113e Author: Andy Seaborne Authored: Tue Dec 29 21:19:21 2015 +0000 Committer: Andy Seaborne Committed: Tue Dec 29 21:19:21 2015 +0000 ---------------------------------------------------------------------- .../org/apache/jena/atlas/lib/tuple/Tuple.java | 27 +++++++++++++++----- .../apache/jena/atlas/lib/tuple/TupleBase.java | 13 ---------- 2 files changed, 20 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jena/blob/9b5aec9c/jena-base/src/main/java/org/apache/jena/atlas/lib/tuple/Tuple.java ---------------------------------------------------------------------- diff --git a/jena-base/src/main/java/org/apache/jena/atlas/lib/tuple/Tuple.java b/jena-base/src/main/java/org/apache/jena/atlas/lib/tuple/Tuple.java index e3aa7e3..016e878d 100644 --- a/jena-base/src/main/java/org/apache/jena/atlas/lib/tuple/Tuple.java +++ b/jena-base/src/main/java/org/apache/jena/atlas/lib/tuple/Tuple.java @@ -18,13 +18,17 @@ package org.apache.jena.atlas.lib.tuple; +import java.util.Iterator ; import java.util.List ; import java.util.function.Consumer ; import java.util.stream.Stream ; +import java.util.stream.StreamSupport ; import org.apache.jena.atlas.lib.ArrayUtils ; -/** A Tuple is the same class of item */ +/** A Tuple is a sequence of items of the same class of item. + * Tuples are immutable. .equals is "by value". + */ public interface Tuple extends Iterable { /** Get the i'th element, for i in the range 0 to len()-1 * @throws IndexOutOfBoundsException for i out of range @@ -41,7 +45,7 @@ public interface Tuple extends Iterable { /** stream */ public default Stream stream() { - return asList().stream() ; + return StreamSupport.stream(spliterator(), false) ; } /** forEach */ @@ -50,20 +54,29 @@ public interface Tuple extends Iterable { asList().forEach(action) ; } - /** Copy the Tuple into the array */ + /** Iterable */ + @Override + public default Iterator iterator() { + return asList().iterator() ; + } + + /** Copy the elements of this Tuple into the array */ public default void copyInto(X[] array) { copyInto(array, 0, len()); } - /** Copy the Tuple into the array */ + /** Copy the elements of this Tuple into the array */ public default void copyInto(X[] array, int start) { copyInto(array, start, len()); } - /** Copy the Tuple into the array */ - public void copyInto(X[] array, int start, int length) ; + /** Copy the elements of this Tuple into the array */ + public default void copyInto(X[] array, int start, int length) { + for ( int i = 0 ; i < Math.min(length, len()) ; i++ ) + array[i+start] = get(i) ; + } - /** Copy the Tuple into the array */ + /** Copy the elements of this Tuple into a newly created array */ public default X[] asArray(Class cls) { X[] elts = ArrayUtils.alloc(cls, len()) ; for ( int i = 0 ; i < len() ; i++ ) http://git-wip-us.apache.org/repos/asf/jena/blob/9b5aec9c/jena-base/src/main/java/org/apache/jena/atlas/lib/tuple/TupleBase.java ---------------------------------------------------------------------- diff --git a/jena-base/src/main/java/org/apache/jena/atlas/lib/tuple/TupleBase.java b/jena-base/src/main/java/org/apache/jena/atlas/lib/tuple/TupleBase.java index 6e174ac..90cdbf3 100644 --- a/jena-base/src/main/java/org/apache/jena/atlas/lib/tuple/TupleBase.java +++ b/jena-base/src/main/java/org/apache/jena/atlas/lib/tuple/TupleBase.java @@ -18,24 +18,11 @@ package org.apache.jena.atlas.lib.tuple; -import java.util.Iterator ; import java.util.Objects ; abstract class TupleBase implements Tuple { protected TupleBase() {} - /** Iterable */ - @Override - public Iterator iterator() { - return asList().iterator() ; - } - - @Override - public void copyInto(X[] array, int start, int length) { - for ( int i = 0 ; i < Math.min(length, len()) ; i++ ) - array[i+start] = get(i) ; - } - @Override public final int hashCode() {