Browse Source

Correction suite ajout ConsEmptyList

Arthur Brandao 6 years ago
parent
commit
fa61691c82
1 changed files with 6 additions and 7 deletions
  1. 6 7
      src/migl/util/ConsListImpl.java

+ 6 - 7
src/migl/util/ConsListImpl.java

@@ -18,9 +18,6 @@ public class ConsListImpl<E> extends Cons<E, ConsList<E>> implements ConsList<E>
 			private ConsList<E> current = ConsListImpl.this;
 			@Override
 			public boolean hasNext() {
-				if(current == null) {
-					return false;
-				}
 				return !current.isEmpty();
 			}
 			
@@ -44,9 +41,7 @@ public class ConsListImpl<E> extends Cons<E, ConsList<E>> implements ConsList<E>
 	}
 	
 	private ConsList<E> appendRec(E e, ConsList<E> list) {
-		if(list == null) {
-			return new ConsListImpl<>(e, null);
-		} else if(list.isEmpty()) {
+		if(list.isEmpty()) {
 			return new ConsListImpl<>(e, list);
 		}
 		return new ConsListImpl<>(list.car(), this.appendRec(e, list.cdr()));
@@ -82,7 +77,11 @@ public class ConsListImpl<E> extends Cons<E, ConsList<E>> implements ConsList<E>
 	public String toString() {
 		String str = "(";
 		for(E e : this) {
-			str += e.toString() + " ";
+			if(e == null) {
+				str += "null ";
+			} else {
+				str += e.toString() + " ";
+			}
 		}
 		return str.trim() + ")";
 	}