Difference between revisions of "ImmutableList Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 14: Line 14:
 
====nil====
 
====nil====
 
<pre>public static <E> ImmutableList<E> nil()</pre>
 
<pre>public static <E> ImmutableList<E> nil()</pre>
 +
 +
constructs a new empty list, analogous to the [http://sml-family.org/Basis/list.html#SIG:LIST.nil:TY nil constructor] for SML [http://sml-family.org/Basis/list.html List].
  
 
====cons====
 
====cons====

Revision as of 22:54, 17 January 2020

Code To Implement

Utilities

DefaultImmutableList<E>

class: DefaultImmutableList.java Java.png
methods: constructors
head
tail
isEmpty
package: immutable.list.assignment
source folder: src/main/java

class DefaultImmutableList implements ImmutableList<E>

Note: consider using java.util.Optional

Note: you need not implement iterator() now. That will be the subject of a future studio.

Lists

class: Lists.java Java.png
methods: nil
cons
brackets
package: immutable.list.assignment
source folder: src/main/java

nil

public static <E> ImmutableList<E> nil()

constructs a new empty list, analogous to the nil constructor for SML List.

cons

public static <E> ImmutableList<E> cons(E head, ImmutableList<E> tail)

brackets

public static <E> ImmutableList<E> brackets(E... elements)

Apps

Length

class: Length.java Java.png
methods: length
package: immutable.list.apps.assignment
source folder: src/main/java

public static <E> int length(ImmutableList<E> list)

SumProductCountdownFactorial

class: SumProductCountdownFactorial.java Java.png
methods: sum
product
countdown
factorial
package: immutable.list.apps.assignment
source folder: src/main/java

sum

public static int sum(ImmutableList<Integer> xs)

product

public static int product(ImmutableList<Integer> xs)

countdown

public static ImmutableList<Integer> countdown(int n)

factorial

public static int factorial(int n)

Concat

class: Concat.java Java.png
methods: concat
package: immutable.list.apps.assignment
source folder: src/main/java

public static <E> ImmutableList<E> concat(ImmutableList<E> xs, ImmutableList<E> ys)

Test

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