/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * JavaWorld Library, Copyright 2011 Bryan Chadwick * * * * FILE: ./universe/Empty.java * * * * This file is part of JavaWorld. * * * * JavaWorld is free software: you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation, either version * * 3 of the License, or (at your option) any later version. * * * * JavaWorld is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with JavaWorld. If not, see . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ package universe; /** Represents the Empty List. You should not use the constructor. To create an * empty list please use List.create(). You Can usually get away without * the type parameter depending on the context. */ public class Empty extends List { private static final long serialVersionUID = 1; public Empty(){ super(0); } public X top(){ throw new RuntimeException("Bad Top"); } public List pop(){ throw new RuntimeException("Bad Pop"); } public boolean isEmpty(){ return true; } public boolean equals(Object o){ return (o instanceof Empty); } public int hashCode(){ return 11314233; } public List append(List l){ return l; } public List append(X t){ return this.push(t); } public boolean contains(X t){ return false; } public boolean contains(Pred p){ return false; } public boolean containsAny(List l){ return false; } public boolean containsAll(List l){ return l.isEmpty(); } public boolean containsAll(List l, Comp c){ return l.isEmpty(); } public X find(X t){ throw new RuntimeException("Not Found: "+t); } public X find(Pred p){ throw new RuntimeException("No Match Found"); } public List remove(X t){ return this; } public List remove(Pred p){ return this; } public int length(){ return 0; } public X lookup(int i){ throw new RuntimeException("Bad Lookup"); } public String toString(String sep, String pre){ return ""; } public String toString(Stringer s){ return ""; } public List filter(Pred p){ return this; } public Y foldl(Fold f, Y b){ return b; } public Y foldr(Fold f, Y b){ return b; } public List map(Map m){ return new Empty(); } public List add(X t, int i){ if(i == 0)return push(t); throw new RuntimeException("Bad Add"); } public List remove(int i){ throw new RuntimeException("Bad Remove"); } public List insert(X a, Comp c){ return push(a); } public List sort(Comp c){ return this; } public List zip(Zip z, List l){ return List.create(); } public List replace(X t, X s){ throw new RuntimeException("Bad Replace"); } public List replace(Pred p, X t){ throw new RuntimeException("Bad Replace"); } public List replace(int t, X s){ throw new RuntimeException("Bad Replace"); } public List replaceAll(X t, X s){ return this; } public List replaceAll(Pred p, X t){ return this; } }