Skip to content

Commit 9490c8b

Browse files
committed
cleanup turtle, wheel
1 parent d156cdb commit 9490c8b

2 files changed

Lines changed: 56 additions & 62 deletions

File tree

src/main/java/org/teachingextensions/logo/Turtle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.teachingextensions.approvals.lite.util.persistence.SavingException;
1919

2020
/**
21-
* <img src="https://lh5.googleusercontent.com/-B3Q59gpYW8o/T4tA2k_TYUI/AAAAAAAAAjo/WiqdoXjbkb0/s65/Tortoise.png" align="left" alt="A turtle drawing a line" >
21+
* <img src="https://lh5.googleusercontent.com/-B3Q59gpYW8o/T4tA2k_TYUI/AAAAAAAAAjo/WiqdoXjbkb0/s65/Tortoise.png" style="text-align: left" alt="A turtle drawing a line" >
2222
* The Turtle allows you to draw lines and shapes by moving it around on the window, and you can put more than one turtle on the same window...
2323
*/
2424
public class Turtle
Lines changed: 55 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,67 @@
11
package org.teachingextensions.logo;
22

3+
import org.teachingextensions.approvals.lite.util.NumberUtils;
4+
35
import java.util.ArrayList;
46
import java.util.List;
57

6-
import org.teachingextensions.approvals.lite.util.NumberUtils;
7-
88
/**
9-
* A Wheel is a List with no ending on beginning <br>
10-
*
11-
* <b>Example:</b> {@code
12-
* Wheel<String> names = new Wheel<String>();
13-
* names.add("Chocolate");
14-
* names.add("Peanut Butter");
15-
* for(int i = 0; i < 6; i++) > {
16-
* String name = names.next();
17-
* System.out.print(name + " ");
18-
* }
19-
* }
20-
* Would result in : <br>
9+
* A Wheel is a List with no ending on beginning <p>
10+
* <b>Example:</b><pre>{@code
11+
* Wheel<String> names = new Wheel<String>();
12+
* names.add("Chocolate");
13+
* names.add("Peanut Butter");
14+
* for(int i = 0; i < 6; i++){
15+
* String name = names.next();
16+
* System.out.print(name + " ");
17+
* }
18+
* }</pre>
19+
* Would result in:<p>
2120
* Chocolate Peanut Butter Chocolate Peanut Butter Chocolate Peanut Butter
22-
*
23-
* @param <T>
21+
*
22+
* @param <T> The kind of things that are in the wheel
2423
*/
25-
public class Wheel<T>
26-
{
27-
private List<T> list = new ArrayList<T>();
28-
private int index = 0;
29-
@SafeVarargs
30-
public Wheel(T... loadWith)
31-
{
32-
for (T t : loadWith)
33-
{
34-
add(t);
24+
public class Wheel<T> {
25+
private List<T> list = new ArrayList<>();
26+
private int index = 0;
27+
28+
@SafeVarargs
29+
public Wheel(T... loadWith) {
30+
for (T t : loadWith) {
31+
add(t);
32+
}
33+
}
34+
35+
public Wheel() {
3536
}
36-
}
37-
public Wheel()
38-
{
39-
}
40-
public void add(T i)
41-
{
42-
list.add(i);
43-
}
44-
public T next()
45-
{
46-
assertNonEmpty();
47-
if (index >= list.size())
48-
{
49-
index = 0;
37+
38+
public void add(T i) {
39+
list.add(i);
5040
}
51-
T t = list.get(index++);
52-
return t;
53-
}
54-
private void assertNonEmpty()
55-
{
56-
if (list.isEmpty())
57-
{
58-
String message = "I call shenanigans!!!\nThis Wheel is empty\nYou can NOT get something from the Wheel before you've added anything to it.";
59-
throw new RuntimeException(message);
41+
42+
public T next() {
43+
assertNonEmpty();
44+
if (index >= list.size()) {
45+
index = 0;
46+
}
47+
return list.get(index++);
48+
}
49+
50+
private void assertNonEmpty() {
51+
if (list.isEmpty()) {
52+
String message = "I call shenanigans!!!\nThis Wheel is empty\nYou can NOT get something from the Wheel before you've added anything to it.";
53+
throw new RuntimeException(message);
54+
}
55+
}
56+
57+
public T getRandomFrom() {
58+
assertNonEmpty();
59+
int index = NumberUtils.getRandomInt(0, list.size());
60+
return list.get(index);
61+
}
62+
63+
public void empty() {
64+
list.clear();
65+
index = 0;
6066
}
61-
}
62-
public T getRandomFrom()
63-
{
64-
assertNonEmpty();
65-
int index = NumberUtils.getRandomInt(0, list.size());
66-
return list.get(index);
67-
}
68-
public void empty()
69-
{
70-
list.clear();
71-
index = 0;
72-
}
7367
}

0 commit comments

Comments
 (0)