Changed as many duplicate file names as possible

This commit is contained in:
Bruce Eckel 2016-12-04 09:30:08 -08:00
parent 90563b9545
commit 50228968db
10 changed files with 43 additions and 44 deletions

View File

@ -1,4 +1,4 @@
// concurrent/Prime.java
// concurrent/ParallelPrime.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
@ -9,7 +9,7 @@ import java.io.*;
import java.nio.file.*;
import java.nio.charset.*;
public class Prime {
public class ParallelPrime {
static final int COUNT = 100_000;
public static boolean isPrime(long n) {
return rangeClosed(2, (long)Math.sqrt(n))
@ -21,7 +21,7 @@ public class Prime {
List<String> primes =
iterate(2, i -> i + 1)
.parallel() // [1]
.filter(Prime::isPrime)
.filter(ParallelPrime::isPrime)
.limit(COUNT)
.mapToObj(Long::toString)
.collect(Collectors.toList());

View File

@ -23,9 +23,8 @@ public class Summing {
public static final int SZ = 100_000_000;
// This even works:
// public static final int SZ = 1_000_000_000;
// Gauss's formula:
public static final long CHECK =
(long)SZ * ((long)SZ + 1)/2;
(long)SZ * ((long)SZ + 1)/2; // Gauss's formula
public static void main(String[] args) {
System.out.println(CHECK);
timeTest("Sum Stream", CHECK, () ->

View File

@ -1,14 +1,14 @@
// enums/Burrito.java
// enums/Burrito2.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {java enums.Burrito}
// {java enums.Burrito2}
package enums;
import static enums.Spiciness.*;
import static enums.SpicinessEnum.*;
public class Burrito {
Spiciness degree;
public Burrito(Spiciness degree) {
public class Burrito2 {
SpicinessEnum degree;
public Burrito2(SpicinessEnum degree) {
this.degree = degree;
}
@Override
@ -16,9 +16,9 @@ public class Burrito {
return "Burrito is "+ degree;
}
public static void main(String[] args) {
System.out.println(new Burrito(NOT));
System.out.println(new Burrito(MEDIUM));
System.out.println(new Burrito(HOT));
System.out.println(new Burrito2(NOT));
System.out.println(new Burrito2(MEDIUM));
System.out.println(new Burrito2(HOT));
}
}
/* Output:

View File

@ -1,9 +1,9 @@
// enums/Spiciness.java
// enums/SpicinessEnum.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
package enums;
public enum Spiciness {
public enum SpicinessEnum {
NOT, MILD, MEDIUM, HOT, FLAMING
}

View File

@ -3,29 +3,29 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;
import onjava.Operation;
import onjava.Operations;
class Bing implements Operation {
class Bing implements Operations {
public void execute() {
Operation.show("Bing");
Operations.show("Bing");
}
}
class Crack implements Operation {
class Crack implements Operations {
public void execute() {
Operation.show("Crack");
Operations.show("Crack");
}
}
class Twist implements Operation {
class Twist implements Operations {
public void execute() {
Operation.show("Twist");
Operations.show("Twist");
}
}
public class Machine {
public static void main(String[] args) {
Operation.runOps(
Operations.runOps(
new Bing(), new Crack(), new Twist());
}
}

View File

@ -1,4 +1,4 @@
// interfaces/RandomWords.java
// interfaces/RandomStrings.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
@ -6,7 +6,7 @@
import java.nio.*;
import java.util.*;
public class RandomWords implements Readable {
public class RandomStrings implements Readable {
private static Random rand = new Random(47);
private static final char[] CAPITALS =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
@ -15,7 +15,7 @@ public class RandomWords implements Readable {
private static final char[] VOWELS =
"aeiou".toCharArray();
private int count;
public RandomWords(int count) { this.count = count; }
public RandomStrings(int count) { this.count = count; }
@Override
public int read(CharBuffer cb) {
if(count-- == 0)
@ -29,7 +29,7 @@ public class RandomWords implements Readable {
return 10; // Number of characters appended
}
public static void main(String[] args) {
Scanner s = new Scanner(new RandomWords(10));
Scanner s = new Scanner(new RandomStrings(10));
while(s.hasNext())
System.out.println(s.next());
}

View File

@ -1,14 +1,14 @@
// onjava/Operation.java
// onjava/Operations.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
package onjava;
import java.util.*;
public interface Operation {
public interface Operations {
void execute();
static void runOps(Operation... ops) {
for(Operation op : ops)
static void runOps(Operations... ops) {
for(Operations op : ops)
op.execute();
}
static void show(String msg) {

View File

@ -1,15 +1,15 @@
// reuse/SpaceShip.java
// reuse/DerivedSpaceShip.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
public class SpaceShip extends SpaceShipControls {
public class DerivedSpaceShip extends SpaceShipControls {
private String name;
public SpaceShip(String name) { this.name = name; }
public DerivedSpaceShip(String name) { this.name = name; }
@Override
public String toString() { return name; }
public static void main(String[] args) {
SpaceShip protector = new SpaceShip("NSEA Protector");
DerivedSpaceShip protector = new DerivedSpaceShip("NSEA Protector");
protector.forward(100);
}
}

View File

@ -3,16 +3,16 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;
import onjava.Operation;
import onjava.Operations;
public class Machine2 {
public static void main(String[] args) {
Arrays.stream(new Operation[] {
() -> Operation.show("Bing"),
() -> Operation.show("Crack"),
() -> Operation.show("Twist"),
() -> Operation.show("Pop")
}).forEach(Operation::execute);
Arrays.stream(new Operations[] {
() -> Operations.show("Bing"),
() -> Operations.show("Crack"),
() -> Operations.show("Twist"),
() -> Operations.show("Pop")
}).forEach(Operations::execute);
}
}
/* Output:

View File

@ -8,7 +8,7 @@ public class Operation {
public final Supplier<String> description;
public final Runnable command;
public
Operation (Supplier<String> descr, Runnable cmd) {
Operation(Supplier<String> descr, Runnable cmd) {
description = descr;
command = cmd;
}