/*
// Licensed to Julian Hyde under one or more contributor license
// agreements. See the NOTICE file distributed with this work for
// additional information regarding copyright ownership.
//
// Julian Hyde 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 net.hydromatic.linq4j;

import java.util.Iterator;

/**
 * Pair of an element and an ordinal.
 */
public class Ord<E> {
    public final int n;
    public final E e;

    private Ord(int n, E e) {
        this.n = n;
        this.e = e;
    }

    public static <E> Ord<E> of(int n, E e) {
        return new Ord<E>(n, e);
    }

    public static <E> Iterable<Ord<E>> of(final Iterable<E> iterable) {
        return new Iterable<Ord<E>>() {
            public Iterator<Ord<E>> iterator() {
                return of(iterable.iterator());
            }
        };
    }

    public static <E> Iterator<Ord<E>> of(final Iterator<E> iterator) {
        return new Iterator<Ord<E>>() {
            int n = 0;

            public boolean hasNext() {
                return iterator.hasNext();
            }

            public Ord<E> next() {
                return Ord.of(n++, iterator.next());
            }

            public void remove() {
                iterator.remove();
            }
        };
    }
}

// End Ord.java

@@ -820,24 +820,17 @@
 va.util.
-Iterator
+*
 ;%0A%0A/**%0A 
@@ -889,16 +889,49 @@
 s Ord%3CE%3E
+ implements Map.Entry%3CInteger, E%3E
  %7B%0A    p
@@ -946,17 +946,17 @@
 nal int 
-n
+i
 ;%0A    pu
@@ -980,15 +980,41 @@
     
-private
+/** Creates an Ord. */%0A    public
  Ord
@@ -1014,25 +1014,25 @@
 lic Ord(int 
-n
+i
 , E e) %7B%0A   
@@ -1045,13 +1045,13 @@
 his.
-n = n
+i = i
 ;%0A  
@@ -1067,32 +1067,59 @@
 s.e = e;%0A    %7D%0A%0A
+    /** Creates an Ord. */%0A
     public stati
@@ -1180,32 +1180,97 @@
 %3E(n, e);%0A    %7D%0A%0A
+    /** Creates an iterable of %7B@code Ord%7Ds over an iterable. */%0A
     public stati
@@ -1284,34 +1284,35 @@
 terable%3COrd%3CE%3E%3E 
-of
+zip
 (final Iterable%3C
@@ -1438,18 +1438,19 @@
  return 
-of
+zip
 (iterabl
@@ -1492,24 +1492,89 @@
   %7D;%0A    %7D%0A%0A
+    /** Creates an iterator of %7B@code Ord%7Ds over an iterator. */%0A
     public s
@@ -1600,18 +1600,19 @@
 Ord%3CE%3E%3E 
-of
+zip
 (final I
@@ -1998,16 +1998,768 @@
 %7D;%0A    %7D
+%0A%0A    /** Returns a numbered list based on an array. */%0A    public static %3CE%3E List%3COrd%3CE%3E%3E zip(%0A        final E%5B%5D elements)%0A    %7B%0A        return zip(Arrays.asList(elements));%0A    %7D%0A%0A    /** Returns a numbered list. */%0A    public static %3CE%3E List%3COrd%3CE%3E%3E zip(%0A        final List%3CE%3E elements)%0A    %7B%0A        return new AbstractList%3COrd%3CE%3E%3E() %7B%0A            public Ord%3CE%3E get(int index) %7B%0A                return of(index, elements.get(index));%0A            %7D%0A%0A            public int size() %7B%0A                return elements.size();%0A            %7D%0A        %7D;%0A    %7D%0A%0A    public Integer getKey() %7B%0A        return i;%0A    %7D%0A%0A    public E getValue() %7B%0A        return e;%0A    %7D%0A%0A    public E setValue(E value) %7B%0A        throw new UnsupportedOperationException();%0A    %7D
 %0A%7D%0A%0A// E

Rename fields and methods in Ord to match optiq/eigenbase version.