package ceylon.language;

import java.util.ArrayList;
import java.util.List;

import com.redhat.ceylon.compiler.java.metadata.Ceylon;
import com.redhat.ceylon.compiler.java.metadata.Method;
import com.redhat.ceylon.compiler.java.metadata.Name;
import com.redhat.ceylon.compiler.java.metadata.TypeInfo;
import com.redhat.ceylon.compiler.java.metadata.TypeParameter;
import com.redhat.ceylon.compiler.java.metadata.TypeParameters;

@Ceylon(major = 1)
@Method
public final class zip {
    
    private zip() {}
    
    @TypeParameters({@TypeParameter(value="Key", satisfies="ceylon.language.Object"),
                     @TypeParameter(value="Item", satisfies="ceylon.language.Object")})
    @TypeInfo("ceylon.language.Empty|ceylon.language.Sequence<ceylon.language.Entry<Key,Item>>")
    public static <Key,Item> Iterable<? extends Entry<? extends Key, ? extends Item>> zip(
    @Name("keys")
    @TypeInfo("ceylon.language.Empty|ceylon.language.Sequence<Key>")
    final ceylon.language.Iterable<? extends Key> keys,
    @Name("items")
    @TypeInfo("ceylon.language.Empty|ceylon.language.Sequence<Item>")
    final ceylon.language.Iterable<? extends Item> items) {
		List<Entry<? extends Key,? extends Item>> list = new ArrayList<Entry<? extends Key,? extends Item>>();
		Iterator<? extends Key> keyIter = keys.getIterator();
		Iterator<? extends Item> itemIter = items.getIterator();
		Key key = (Key) keyIter.next();
        Item item = (Item) itemIter.next();
		while (key != exhausted.getExhausted() && item != exhausted.getExhausted()) {
			list.add(new Entry<Key,Item>(key, item));
	        key = (Key) keyIter.next();
	        item = (Item) itemIter.next();
		}
        return new ArraySequence<Entry<? extends Key,? extends Item>>(list);
    }
}

@@ -921,37 +921,15 @@
 age.
-Empty%7Cceylon.language.Sequenc
+Iterabl
 e%3CKe
@@ -1043,37 +1043,15 @@
 age.
-Empty%7Cceylon.language.Sequenc
+Iterabl
 e%3CIt
@@ -1620,20 +1620,98 @@
 ();%0A%09%09%7D%0A
-    
+%09%09if (list.isEmpty()) %7B%0A%09%09    return (Iterable) $empty.getEmpty();%0A%09%09%7D%0A%09%09else %7B%0A%09%09
     retu
@@ -1775,16 +1775,20 @@
 (list);%0A
+%09%09%7D%0A
     %7D%0A%7D%0A

fix case where one arg is empty, and fix param types