[ 
https://issues.apache.org/jira/browse/JENA-1107?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15073019#comment-15073019
 ] 

ASF GitHub Bot commented on JENA-1107:
--------------------------------------

Github user ajs6f commented on a diff in the pull request:

    https://github.com/apache/jena/pull/115#discussion_r48498336
  
    --- Diff: 
jena-base/src/main/java/org/apache/jena/atlas/lib/tuple/Tuple.java ---
    @@ -0,0 +1,73 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.jena.atlas.lib.tuple;
    +
    +import java.util.List ;
    +import java.util.function.Consumer ;
    +import java.util.stream.Stream ;
    +
    +import org.apache.jena.atlas.lib.ArrayUtils ;
    +
    +/** A Tuple is the same class of item */
    +public interface Tuple<X> extends Iterable<X> {
    +    /** Get the i'th element, for i in the range 0 to len()-1 
    +     * @throws IndexOutOfBoundsException for i out of range 
    +     */
    +    public X get(int i) ;
    +
    +    /** length : elements are 0 to len()-1 */ 
    +    public int len() ;
    +
    +    /** Convert to a List */
    +    public default List<X> asList() {
    +        return new TupleList<>(this) ;
    +    }
    +
    +    /** stream */
    +    public default Stream<X> stream() { 
    +        return asList().stream() ;
    +    }
    +
    +    /** forEach */
    +    @Override
    +    public default void forEach(Consumer<? super X> action) { 
    +        asList().forEach(action) ;
    +    }
    +
    +    /** Copy the Tuple into the array */ 
    +    public default void copyInto(X[] array) {
    +        copyInto(array, 0, len());
    +    }
    +
    +    /** Copy the 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) ;
    --- End diff --
    
    Isn't there a really obvious `default` here? Maybe it would be good to have 
a comment here explaining why impls need to do their own thing here...?


> Improve jena-base lib.Tuple
> ---------------------------
>
>                 Key: JENA-1107
>                 URL: https://issues.apache.org/jira/browse/JENA-1107
>             Project: Apache Jena
>          Issue Type: Improvement
>            Reporter: Andy Seaborne
>            Assignee: Andy Seaborne
>            Priority: Minor
>
> Tuples, which are immutable, value-equality fixed length sequences of 
> instances of the same type, accessed by index.
> They are like {{T[]}} but immutable, with .equals based on contents, and 
> could be improved to work independently of their original use in TDB.
> Proposal:
> #  Make Tuple an interface (simpler than current), with special 
> implementations for low number of elements.
> # {{ColumnMap}} ==> {{TupleMap}} and sort out the naming as much as possible 
> to use as a way to manage index mapping, not just rewriting Tuples.
> An intermediate step is to move {{ColumnMap}} into TDB.
> This is not a proposal to add it to {{Triple}} or {{Quad}}.
> {{Triple}} is not the same as a 3-length {{Tuple<Node>}}.  Triple elements 
> are accessed by name ({{getSubject}} etc), not index.  SPO is just one 
> possible order in which to think about triples but it has no special status. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to