Difference between revisions of "Iterable Immutable List Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 2: Line 2:
 
In this studio we will complete the <code>DefaultImmutableList</code> implementation from the [[ImmutableList_Assignment|ImmutableList studio]].  The ImmutableList interface extends Iterable which has one method: iterator().
 
In this studio we will complete the <code>DefaultImmutableList</code> implementation from the [[ImmutableList_Assignment|ImmutableList studio]].  The ImmutableList interface extends Iterable which has one method: iterator().
  
=References=
 
==Iterable==
 
:[https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html interface java.lang.Iterable<T>]
 
::[https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html#iterator-- Iterator<T> iterator()]
 
 
==Iterator==
 
:[https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html interface java.util.Iterator<T>]
 
::[https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html#hasNext-- boolean hasNext()]
 
::[https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html#next-- T next()]
 
 
==ImmutableList==
 
 
  <nowiki>public interface ImmutableList<E> extends Iterable<E> {
 
  <nowiki>public interface ImmutableList<E> extends Iterable<E> {
 
E head();
 
E head();
Line 18: Line 7:
 
boolean isEmpty();
 
boolean isEmpty();
 
}</nowiki>
 
}</nowiki>
 +
 +
==Iterable==
 +
*[https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html interface java.lang.Iterable<T>]
 +
**[https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html#iterator-- Iterator<T> iterator()]
 +
 +
==Iterator==
 +
*[https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html interface java.util.Iterator<T>]
 +
**[https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html#hasNext-- boolean hasNext()]
 +
**[https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html#next-- T next()]
  
 
=Code To Implement=
 
=Code To Implement=

Revision as of 16:32, 24 April 2020

Studio To Revisit

In this studio we will complete the DefaultImmutableList implementation from the ImmutableList studio. The ImmutableList interface extends Iterable which has one method: iterator().

public interface ImmutableList<E> extends Iterable<E> {
	E head();
	ImmutableList<E> tail();
	boolean isEmpty();
}

Iterable

Iterator

Code To Implement

DefaultImmutableList

class: DefaultImmutableList.java Java.png
methods: iterator
package: immutable.list.assignment
source folder: src/main/java

iterator

public Iterator<E> iterator()

Example

class: ListsExample.java Presentation icon-72a7cf.svg
package: immutable.list.example
source folder: src/main/java

The code:

ImmutableList<Integer> numbers = Lists.brackets(4, 66, 99);
for (int i : numbers) {
	System.out.println(i);
}

produces:

4
66
99

Test

class: IterableAssignmentTestSuite.java Junit.png
package: immutable.list.assignment
source folder: src/test/java