Iterable Immutable List Assignment

From CSE425S Wiki
Revision as of 16:28, 24 April 2020 by Dennis.cosgrove (talk | contribs)
Jump to navigation Jump to search

Code To Revisit

DefaultImmutableList

ImmutableList_Assignment

References

Iterable

interface java.lang.Iterable<T>
Iterator<T> iterator()

Iterator

interface java.util.Iterator<T>
boolean hasNext()
T next()

ImmutableList

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

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