Iterable Range Assignment

From CSE425S Wiki
Jump to navigation Jump to search

Java

Method Overloading

Nested Inner Classes

Anonymous Classes

Lambda Expressions

interface java.lang.Iterable<T>

iterator()

interface java.util.Iterator<T>

hasNext()
next()

Code To Implement

class: Iterables.java Java.png
methods: range
range
range
range
package: range.warmup
source folder: src/main/java

Integers

range(min, maxExclusive, step)

range(min, maxExclusive)

range with a step of 1

Doubles

range(min, maxExclusive, step)

range(min, maxExclusive)

range with a step of 1.0

Client

class: RangeClient.java Presentation icon-72a7cf.svg
package: range.client
source folder: src/main/java

The code:

for (int i : Iterables.range(4, 12)) {
	System.out.println(i);
}
System.out.println();
for (double d : Iterables.range(3.0, 7.1, 0.25)) {
	System.out.println(d);
}

produces the output:

4
5
6
7
8
9
10
11

3.0
3.25
3.5
3.75
4.0
4.25
4.5
4.75
5.0
5.25
5.5
5.75
6.0
6.25
6.5
6.75
7.0

Test

class: IterableRangesTestSuite.java Junit.png
package: range.warmup
source folder: src/test/java