Skip to content

Commit 4f63623

Browse files
author
Bruce Eckel
committed
After "Arrays" chapter completed
1 parent de9c3fb commit 4f63623

File tree

689 files changed

+4449
-3059
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

689 files changed

+4449
-3059
lines changed

annotations/AtUnitComposition.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5-
// Creating non-embedded tests.
5+
// Creating non-embedded tests
66
package annotations;
77
import onjava.atunit.*;
88
import onjava.*;
@@ -16,7 +16,8 @@ public class AtUnitComposition {
1616
@Test boolean _methodTwo() {
1717
return testObject.methodTwo() == 2;
1818
}
19-
public static void main(String[] args) throws Exception {
19+
public static void
20+
main(String[] args) throws Exception {
2021
OSExecute.command("java -cp .. " +
2122
"onjava.atunit.AtUnit AtUnitComposition.class");
2223
}

annotations/AtUnitExample1.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public int methodTwo() {
2222
// Shows output for failure:
2323
@Test boolean failureTest() { return false; }
2424
@Test boolean anotherDisappointment() { return false; }
25-
public static void main(String[] args) throws Exception {
25+
public static void
26+
main(String[] args) throws Exception {
2627
OSExecute.command("java -cp .. " +
2728
"onjava.atunit.AtUnit AtUnitExample1.class");
2829
}

annotations/AtUnitExample2.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5-
// Assertions and exceptions can be used in @Tests.
5+
// Assertions and exceptions can be used in @Tests
66
package annotations;
77
import java.io.*;
88
import onjava.atunit.*;
@@ -30,7 +30,8 @@ public int methodTwo() {
3030
assert methodTwo() == 2: "methodTwo must equal 2";
3131
return methodOne().equals("This is methodOne");
3232
}
33-
public static void main(String[] args) throws Exception {
33+
public static void
34+
main(String[] args) throws Exception {
3435
OSExecute.command("java -cp .. " +
3536
"onjava.atunit.AtUnit AtUnitExample2.class");
3637
}

annotations/AtUnitExample3.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public int methodTwo() {
2525
return methodOne().equals("This is methodOne");
2626
}
2727
@Test boolean m2() { return methodTwo() == 2; }
28-
public static void main(String[] args) throws Exception {
28+
public static void
29+
main(String[] args) throws Exception {
2930
OSExecute.command("java -cp .. " +
3031
"onjava.atunit.AtUnit AtUnitExample3.class");
3132
}

annotations/AtUnitExample4.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ public class AtUnitExample4 {
1616
public AtUnitExample4(String word) { this.word = word; }
1717
public String getWord() { return word; }
1818
public String scrambleWord() {
19-
// <* Improve this: *>
20-
List<Character> chars = new ArrayList<>();
21-
for(Character c : word.toCharArray())
22-
chars.add(c);
19+
List<Character> chars =
20+
Arrays.asList(ConvertTo.boxed(word.toCharArray()));
2321
Collections.shuffle(chars, rand);
2422
StringBuilder result = new StringBuilder();
2523
for(char ch : chars)
@@ -41,7 +39,7 @@ public String scrambleWord() {
4139
return getWord().equals("are");
4240
}
4341
@Test boolean scramble1() {
44-
// Change to a specific seed to get verifiable results:
42+
// Change to specific seed to get verifiable results:
4543
rand = new Random(47);
4644
System.out.println("'" + getWord() + "'");
4745
String scrambled = scrambleWord();
@@ -55,7 +53,8 @@ public String scrambleWord() {
5553
System.out.println(scrambled);
5654
return scrambled.equals("tsaeborornussu");
5755
}
58-
public static void main(String[] args) throws Exception {
56+
public static void
57+
main(String[] args) throws Exception {
5958
System.out.println("starting");
6059
OSExecute.command("java -cp .. " +
6160
"onjava.atunit.AtUnit AtUnitExample4.class");
@@ -64,17 +63,13 @@ public static void main(String[] args) throws Exception {
6463
/* Output:
6564
starting
6665
annotations.AtUnitExample4
67-
. words 'All'
68-
(failed)
66+
. scramble1 'All'
67+
lAl
68+
6969
. scramble2 'brontosauruses'
7070
tsaeborornussu
7171
72-
. scramble1 'are'
73-
rae
74-
(failed)
75-
(3 tests)
72+
. words 'are'
7673
77-
>>> 2 FAILURES <<<
78-
annotations.AtUnitExample4: words
79-
annotations.AtUnitExample4: scramble1
74+
OK (3 tests)
8075
*/

annotations/AtUnitExample5.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public class AtUnitExample5 {
4040
output.print("test3");
4141
return true;
4242
}
43-
public static void main(String[] args) throws Exception {
43+
public static void
44+
main(String[] args) throws Exception {
4445
OSExecute.command("java -cp .. " +
4546
"onjava.atunit.AtUnit AtUnitExample5.class");
4647
}

annotations/AtUnitExternalTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5-
// Creating non-embedded tests.
5+
// Creating non-embedded tests
66
package annotations;
77
import onjava.atunit.*;
88
import onjava.*;
@@ -12,7 +12,8 @@ public class AtUnitExternalTest extends AtUnitExample1 {
1212
return methodOne().equals("This is methodOne");
1313
}
1414
@Test boolean _methodTwo() { return methodTwo() == 2; }
15-
public static void main(String[] args) throws Exception{
15+
public static void
16+
main(String[] args) throws Exception {
1617
OSExecute.command("java -cp .. " +
1718
"onjava.atunit.AtUnit AtUnitExternalTest.class");
1819
}

annotations/HashSetTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public class HashSetTest {
2121
testObject.remove("one");
2222
assert testObject.isEmpty();
2323
}
24-
public static void main(String[] args) throws Exception {
24+
public static void
25+
main(String[] args) throws Exception {
2526
OSExecute.command("java -cp .. " +
2627
"onjava.atunit.AtUnit HashSetTest.class");
2728
}

annotations/PasswordUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
public class PasswordUtils {
88
@UseCase(id = 47, description =
99
"Passwords must contain at least one numeric")
10-
public boolean validatePassword(String password) {
11-
return (password.matches("\\w*\\d\\w*"));
10+
public boolean validatePassword(String passwd) {
11+
return (passwd.matches("\\w*\\d\\w*"));
1212
}
1313
@UseCase(id = 48)
14-
public String encryptPassword(String password) {
15-
return new StringBuilder(password).reverse().toString();
14+
public String encryptPassword(String passwd) {
15+
return new StringBuilder(passwd).reverse().toString();
1616
}
1717
@UseCase(id = 49, description =
1818
"New passwords can't equal previously used ones")
1919
public boolean checkForNewPassword(
20-
List<String> prevPasswords, String password) {
21-
return !prevPasswords.contains(password);
20+
List<String> prevPasswords, String passwd) {
21+
return !prevPasswords.contains(passwd);
2222
}
2323
}

annotations/StackL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5-
// A stack built on a linkedList.
5+
// A stack built on a linkedList
66
package annotations;
77
import java.util.*;
88

0 commit comments

Comments
 (0)