package common;

import java.util.*;

public class Universe<E> {
	
	private final List<E> ie;
	private final Map<E,Integer> ei;
	
	public Universe(Collection<? extends E> c){
		this.ie = new ArrayList<E>(c);
		this.ei = new HashMap<>();
		for(int i=0; i<ei.size(); ++i){
			ei.put(ie.get(i), i);
		}
	}
	
	public boolean contains(Object o){
		return ei.containsKey(o);
	}
	
	public int size(){
		return ie.size();
	}
	
	public E get(int i){
		return ie.get(i);
	}
	
	public int index(E e){
		return ei.get(e);
	}
	
	public BackedSet<E> set(Collection<? extends E> c){
		return new BackedSet<E>(this,c);
	}
	
	@Override
	public int hashCode(){
		if(hash==null){
			hash = ie.hashCode();
		}
		return hash;
	}
	
	private Integer hash = null;
	
	@Override
	public boolean equals(Object o){
		if(o instanceof Universe<?>){
			Universe<?> u = (Universe<?>) o;
			return ie.equals(u.ie) && ei.equals(u.ei); 
		}
		return false;
	}
	
	/**
	 * <p>A convenience method returning an empty BackedSet backed 
	 * by this Universe.</p>
	 * @return an empty BackedSet backed by this Universe
	 */
	public BackedSet<E> back(){
		return new BackedSet<>(this);
	}
	
	/**
	 * <p>A convenience method returning a BackedSet backed by this 
	 * Universe, containing the contents of {@code c}.</p>
	 * @return a BackedSet backed by this Universe, containing the 
	 * contents of {@code c}
	 */
	public BackedSet<E> back(Collection<? extends E> c){
		return new BackedSet<>(this, c);
	}
}

@@ -27,17 +27,193 @@
 va.util.
-*
+ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.stream.Collectors;%0Aimport java.util.stream.Stream
 ;%0A%0Apubli
@@ -423,18 +423,200 @@
  i=0; i%3C
-e
 i
+e.size(); ++i)%7B%0A%09%09%09ei.put(ie.get(i), i);%0A%09%09%7D%0A%09%7D%0A%09%0A%09public Universe(Stream%3C? extends E%3E s)%7B%0A%09%09this.ie = s.collect(Collectors.toList());%0A%09%09this.ei = new HashMap%3C%3E();%0A%09%09for(int i=0; i%3Cie
 .size();

add Stream constructor, fix bug, import explicit