Checkstyle passing
This commit is contained in:
parent
b2f63b666c
commit
97dcdebc0c
@ -9,7 +9,7 @@ import static onjava.ArrayShow.*;
|
|||||||
|
|
||||||
class Sup { // Superclass
|
class Sup { // Superclass
|
||||||
private int id;
|
private int id;
|
||||||
public Sup(int n) { id = n; }
|
Sup(int n) { id = n; }
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getClass().getSimpleName() + id;
|
return getClass().getSimpleName() + id;
|
||||||
@ -17,7 +17,7 @@ class Sup { // Superclass
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Sub extends Sup { // Subclass
|
class Sub extends Sup { // Subclass
|
||||||
public Sub(int n) { super(n); }
|
Sub(int n) { super(n); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ArrayCopying {
|
public class ArrayCopying {
|
||||||
|
@ -7,7 +7,7 @@ import static onjava.ArrayShow.*;
|
|||||||
|
|
||||||
class Bob {
|
class Bob {
|
||||||
final int id;
|
final int id;
|
||||||
public Bob(int n) { id = n; }
|
Bob(int n) { id = n; }
|
||||||
@Override
|
@Override
|
||||||
public String toString() { return "Bob" + id; }
|
public String toString() { return "Bob" + id; }
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
cp ..\..\OnJava-Tools\verify_output.py .
|
cp ..\..\OnJava-Tools\verify_output.py .
|
||||||
python verify_output.py
|
py -3 verify_output.py
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
gradlew clean
|
@echo run gradlew clean first!
|
||||||
gradlew checkstyleMain 1> checkstyleout.txt 2>&1
|
gradlew checkstyleMain 1> checkstyleout.txt 2>&1
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
class ReversibleArrayList<T> extends ArrayList<T> {
|
class ReversibleArrayList<T> extends ArrayList<T> {
|
||||||
public ReversibleArrayList(Collection<T> c) {
|
ReversibleArrayList(Collection<T> c) {
|
||||||
super(c);
|
super(c);
|
||||||
}
|
}
|
||||||
public Iterable<T> reversed() {
|
public Iterable<T> reversed() {
|
||||||
|
@ -7,7 +7,7 @@ import java.util.*;
|
|||||||
|
|
||||||
class Element {
|
class Element {
|
||||||
private String ident;
|
private String ident;
|
||||||
public Element(String id) { ident = id; }
|
Element(String id) { ident = id; }
|
||||||
@Override
|
@Override
|
||||||
public String toString() { return ident; }
|
public String toString() { return ident; }
|
||||||
@Override
|
@Override
|
||||||
@ -27,11 +27,11 @@ class Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Key extends Element {
|
class Key extends Element {
|
||||||
public Key(String id) { super(id); }
|
Key(String id) { super(id); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Value extends Element {
|
class Value extends Element {
|
||||||
public Value(String id) { super(id); }
|
Value(String id) { super(id); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CanonicalMapping {
|
public class CanonicalMapping {
|
||||||
|
@ -7,7 +7,7 @@ import java.util.*;
|
|||||||
|
|
||||||
class StringAddress {
|
class StringAddress {
|
||||||
private String s;
|
private String s;
|
||||||
public StringAddress(String s) { this.s = s; }
|
StringAddress(String s) { this.s = s; }
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString() + " " + s;
|
return super.toString() + " " + s;
|
||||||
|
@ -10,7 +10,7 @@ class VeryBig {
|
|||||||
private static final int SIZE = 10000;
|
private static final int SIZE = 10000;
|
||||||
private long[] la = new long[SIZE];
|
private long[] la = new long[SIZE];
|
||||||
private String ident;
|
private String ident;
|
||||||
public VeryBig(String id) { ident = id; }
|
VeryBig(String id) { ident = id; }
|
||||||
@Override
|
@Override
|
||||||
public String toString() { return ident; }
|
public String toString() { return ident; }
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,8 +9,8 @@ import java.util.function.*;
|
|||||||
|
|
||||||
class CountString implements Supplier<String> {
|
class CountString implements Supplier<String> {
|
||||||
private int n = 0;
|
private int n = 0;
|
||||||
public CountString() {}
|
CountString() {}
|
||||||
public CountString(int start) { n = start; }
|
CountString(int start) { n = start; }
|
||||||
@Override
|
@Override
|
||||||
public String get() {
|
public String get() {
|
||||||
return Integer.toString(n++);
|
return Integer.toString(n++);
|
||||||
|
@ -9,7 +9,7 @@ class ToDoItem implements Comparable<ToDoItem> {
|
|||||||
private char primary;
|
private char primary;
|
||||||
private int secondary;
|
private int secondary;
|
||||||
private String item;
|
private String item;
|
||||||
public ToDoItem(String td, char pri, int sec) {
|
ToDoItem(String td, char pri, int sec) {
|
||||||
primary = pri;
|
primary = pri;
|
||||||
secondary = sec;
|
secondary = sec;
|
||||||
item = td;
|
item = td;
|
||||||
|
@ -6,11 +6,10 @@
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import onjava.CountMap;
|
|
||||||
|
|
||||||
class SetType {
|
class SetType {
|
||||||
protected int i;
|
protected int i;
|
||||||
public SetType(int n) { i = n; }
|
SetType(int n) { i = n; }
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
return o instanceof SetType &&
|
return o instanceof SetType &&
|
||||||
@ -23,7 +22,7 @@ class SetType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class HashType extends SetType {
|
class HashType extends SetType {
|
||||||
public HashType(int n) { super(n); }
|
HashType(int n) { super(n); }
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(i);
|
return Objects.hashCode(i);
|
||||||
@ -32,7 +31,7 @@ class HashType extends SetType {
|
|||||||
|
|
||||||
class TreeType extends SetType
|
class TreeType extends SetType
|
||||||
implements Comparable<TreeType> {
|
implements Comparable<TreeType> {
|
||||||
public TreeType(int n) { super(n); }
|
TreeType(int n) { super(n); }
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(TreeType arg) {
|
public int compareTo(TreeType arg) {
|
||||||
return Integer.compare(arg.i, i);
|
return Integer.compare(arg.i, i);
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://OnJava8.com for more book information.
|
// Visit http://OnJava8.com for more book information.
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import onjava.Nap;
|
|
||||||
|
|
||||||
public class CatchCompletableExceptions {
|
public class CatchCompletableExceptions {
|
||||||
static void handleException(int failcount) {
|
static void handleException(int failcount) {
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://OnJava8.com for more book information.
|
// Visit http://OnJava8.com for more book information.
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import onjava.Nap;
|
|
||||||
|
|
||||||
public class CompletableExceptions {
|
public class CompletableExceptions {
|
||||||
static CompletableFuture<Breakable>
|
static CompletableFuture<Breakable>
|
||||||
|
@ -8,7 +8,7 @@ import java.util.stream.*;
|
|||||||
import onjava.Timer;
|
import onjava.Timer;
|
||||||
|
|
||||||
public class CompletablePizza {
|
public class CompletablePizza {
|
||||||
static int QUANTITY = 5;
|
static final int QUANTITY = 5;
|
||||||
public static CompletableFuture<Pizza>
|
public static CompletableFuture<Pizza>
|
||||||
makeCF(Pizza za) {
|
makeCF(Pizza za) {
|
||||||
return CompletableFuture
|
return CompletableFuture
|
||||||
|
@ -6,7 +6,7 @@ import java.util.concurrent.*;
|
|||||||
import java.util.stream.*;
|
import java.util.stream.*;
|
||||||
import onjava.Nap;
|
import onjava.Nap;
|
||||||
|
|
||||||
class Frosting {
|
final class Frosting {
|
||||||
private Frosting() {}
|
private Frosting() {}
|
||||||
static CompletableFuture<Frosting> make() {
|
static CompletableFuture<Frosting> make() {
|
||||||
new Nap(0.1);
|
new Nap(0.1);
|
||||||
|
@ -9,11 +9,11 @@ import java.util.concurrent.*;
|
|||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
public class IDChecker {
|
public class IDChecker {
|
||||||
public static int SIZE = 100_000;
|
public static final int SIZE = 100_000;
|
||||||
static class MakeObjects
|
static class MakeObjects
|
||||||
implements Supplier<List<Integer>> {
|
implements Supplier<List<Integer>> {
|
||||||
private Supplier<HasID> gen;
|
private Supplier<HasID> gen;
|
||||||
public MakeObjects(Supplier<HasID> gen) {
|
MakeObjects(Supplier<HasID> gen) {
|
||||||
this.gen = gen;
|
this.gen = gen;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,7 +7,7 @@ import java.util.stream.*;
|
|||||||
import onjava.Timer;
|
import onjava.Timer;
|
||||||
|
|
||||||
public class PizzaParallelSteps {
|
public class PizzaParallelSteps {
|
||||||
static int QUANTITY = 5;
|
static final int QUANTITY = 5;
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Timer timer = new Timer();
|
Timer timer = new Timer();
|
||||||
IntStream.range(0, QUANTITY)
|
IntStream.range(0, QUANTITY)
|
||||||
|
@ -7,7 +7,7 @@ import java.util.stream.*;
|
|||||||
import onjava.Timer;
|
import onjava.Timer;
|
||||||
|
|
||||||
public class PizzaStreams {
|
public class PizzaStreams {
|
||||||
static int QUANTITY = 5;
|
static final int QUANTITY = 5;
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Timer timer = new Timer();
|
Timer timer = new Timer();
|
||||||
IntStream.range(0, QUANTITY)
|
IntStream.range(0, QUANTITY)
|
||||||
|
@ -23,7 +23,7 @@ class Safe implements SharedArg {
|
|||||||
|
|
||||||
class SharedUser implements HasID {
|
class SharedUser implements HasID {
|
||||||
private final int id;
|
private final int id;
|
||||||
public SharedUser(SharedArg sa) {
|
SharedUser(SharedArg sa) {
|
||||||
id = sa.get();
|
id = sa.get();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
// Visit http://OnJava8.com for more book information.
|
// Visit http://OnJava8.com for more book information.
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.stream.*;
|
import java.util.stream.*;
|
||||||
import onjava.Nap;
|
|
||||||
|
|
||||||
public class StreamExceptions {
|
public class StreamExceptions {
|
||||||
static Stream<Breakable>
|
static Stream<Breakable>
|
||||||
|
@ -8,7 +8,7 @@ class SyncConstructor implements HasID {
|
|||||||
private final int id;
|
private final int id;
|
||||||
private static Object
|
private static Object
|
||||||
constructorLock = new Object();
|
constructorLock = new Object();
|
||||||
public SyncConstructor(SharedArg sa) {
|
SyncConstructor(SharedArg sa) {
|
||||||
synchronized(constructorLock) {
|
synchronized(constructorLock) {
|
||||||
id = sa.get();
|
id = sa.get();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
// Visit http://OnJava8.com for more book information.
|
// Visit http://OnJava8.com for more book information.
|
||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
|
|
||||||
class SyncFactory implements HasID {
|
final class SyncFactory implements HasID {
|
||||||
private final int id;
|
private final int id;
|
||||||
private SyncFactory(SharedArg sa) {
|
private SyncFactory(SharedArg sa) {
|
||||||
id = sa.get();
|
id = sa.get();
|
||||||
|
@ -133,7 +133,7 @@ class RandomInputSupplier implements Supplier<Input> {
|
|||||||
// Create Inputs from a file of ';'-separated strings:
|
// Create Inputs from a file of ';'-separated strings:
|
||||||
class FileInputSupplier implements Supplier<Input> {
|
class FileInputSupplier implements Supplier<Input> {
|
||||||
private Iterator<String> input;
|
private Iterator<String> input;
|
||||||
public FileInputSupplier(String fileName) {
|
FileInputSupplier(String fileName) {
|
||||||
try {
|
try {
|
||||||
input = Files.lines(Paths.get(fileName))
|
input = Files.lines(Paths.get(fileName))
|
||||||
.skip(1) // Skip the comment line
|
.skip(1) // Skip the comment line
|
||||||
|
@ -7,7 +7,7 @@ import java.util.*;
|
|||||||
class Part {
|
class Part {
|
||||||
String ss;
|
String ss;
|
||||||
double dd;
|
double dd;
|
||||||
public Part(String ss, double dd) {
|
Part(String ss, double dd) {
|
||||||
this.ss = ss;
|
this.ss = ss;
|
||||||
this.dd = dd;
|
this.dd = dd;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
class DefaultComparison {
|
class DefaultComparison {
|
||||||
private int i, j, k;
|
private int i, j, k;
|
||||||
public DefaultComparison(int i, int j, int k) {
|
DefaultComparison(int i, int j, int k) {
|
||||||
this.i = i;
|
this.i = i;
|
||||||
this.j = j;
|
this.j = j;
|
||||||
this.k = k;
|
this.k = k;
|
||||||
|
@ -11,7 +11,7 @@ class Animal {
|
|||||||
private final int id = counter++;
|
private final int id = counter++;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Size size;
|
private final Size size;
|
||||||
public Animal(String name, Size size) {
|
Animal(String name, Size size) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
@ -36,13 +36,13 @@ class Animal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Dog extends Animal {
|
class Dog extends Animal {
|
||||||
public Dog(String name, Size size) {
|
Dog(String name, Size size) {
|
||||||
super(name, size);
|
super(name, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Pig extends Animal {
|
class Pig extends Animal {
|
||||||
public Pig(String name, Size size) {
|
Pig(String name, Size size) {
|
||||||
super(name, size);
|
super(name, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
class Dog2 extends Animal {
|
class Dog2 extends Animal {
|
||||||
public Dog2(String name, Size size) {
|
Dog2(String name, Size size) {
|
||||||
super(name, size);
|
super(name, size);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@ -16,7 +16,7 @@ class Dog2 extends Animal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Pig2 extends Animal {
|
class Pig2 extends Animal {
|
||||||
public Pig2(String name, Size size) {
|
Pig2(String name, Size size) {
|
||||||
super(name, size);
|
super(name, size);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
class Reporter implements AutoCloseable {
|
class Reporter implements AutoCloseable {
|
||||||
String name = getClass().getSimpleName();
|
String name = getClass().getSimpleName();
|
||||||
public Reporter() {
|
Reporter() {
|
||||||
System.out.println("Creating " + name);
|
System.out.println("Creating " + name);
|
||||||
}
|
}
|
||||||
public void close() {
|
public void close() {
|
||||||
|
@ -17,7 +17,7 @@ class ConstructionException extends Exception {}
|
|||||||
|
|
||||||
class NeedsCleanup2 extends NeedsCleanup {
|
class NeedsCleanup2 extends NeedsCleanup {
|
||||||
// Construction can fail:
|
// Construction can fail:
|
||||||
public NeedsCleanup2() throws ConstructionException {}
|
NeedsCleanup2() throws ConstructionException {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CleanupIdiom {
|
public class CleanupIdiom {
|
||||||
|
@ -7,7 +7,7 @@ class CloseException extends Exception {}
|
|||||||
|
|
||||||
class Reporter2 implements AutoCloseable {
|
class Reporter2 implements AutoCloseable {
|
||||||
String name = getClass().getSimpleName();
|
String name = getClass().getSimpleName();
|
||||||
public Reporter2() {
|
Reporter2() {
|
||||||
System.out.println("Creating " + name);
|
System.out.println("Creating " + name);
|
||||||
}
|
}
|
||||||
public void close() throws CloseException {
|
public void close() throws CloseException {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
class CE extends Exception {}
|
class CE extends Exception {}
|
||||||
|
|
||||||
class SecondExcept extends Reporter {
|
class SecondExcept extends Reporter {
|
||||||
public SecondExcept() throws CE {
|
SecondExcept() throws CE {
|
||||||
super();
|
super();
|
||||||
throw new CE();
|
throw new CE();
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
class MyException2 extends Exception {
|
class MyException2 extends Exception {
|
||||||
private int x;
|
private int x;
|
||||||
public MyException2() {}
|
MyException2() {}
|
||||||
public MyException2(String msg) { super(msg); }
|
MyException2(String msg) { super(msg); }
|
||||||
public MyException2(String msg, int x) {
|
MyException2(String msg, int x) {
|
||||||
super(msg);
|
super(msg);
|
||||||
this.x = x;
|
this.x = x;
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
// Visit http://OnJava8.com for more book information.
|
// Visit http://OnJava8.com for more book information.
|
||||||
|
|
||||||
class MyException extends Exception {
|
class MyException extends Exception {
|
||||||
public MyException() {}
|
MyException() {}
|
||||||
public MyException(String msg) { super(msg); }
|
MyException(String msg) { super(msg); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FullConstructors {
|
public class FullConstructors {
|
||||||
|
@ -10,7 +10,7 @@ import java.io.*;
|
|||||||
class LoggingException extends Exception {
|
class LoggingException extends Exception {
|
||||||
private static Logger logger =
|
private static Logger logger =
|
||||||
Logger.getLogger("LoggingException");
|
Logger.getLogger("LoggingException");
|
||||||
public LoggingException() {
|
LoggingException() {
|
||||||
StringWriter trace = new StringWriter();
|
StringWriter trace = new StringWriter();
|
||||||
printStackTrace(new PrintWriter(trace));
|
printStackTrace(new PrintWriter(trace));
|
||||||
logger.severe(trace.toString());
|
logger.severe(trace.toString());
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
// Rethrow a different object from the one you caught
|
// Rethrow a different object from the one you caught
|
||||||
|
|
||||||
class OneException extends Exception {
|
class OneException extends Exception {
|
||||||
public OneException(String s) { super(s); }
|
OneException(String s) { super(s); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class TwoException extends Exception {
|
class TwoException extends Exception {
|
||||||
public TwoException(String s) { super(s); }
|
TwoException(String s) { super(s); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RethrowNew {
|
public class RethrowNew {
|
||||||
|
@ -11,7 +11,7 @@ class Foul extends BaseballException {}
|
|||||||
class Strike extends BaseballException {}
|
class Strike extends BaseballException {}
|
||||||
|
|
||||||
abstract class Inning {
|
abstract class Inning {
|
||||||
public Inning() throws BaseballException {}
|
Inning() throws BaseballException {}
|
||||||
public void event() throws BaseballException {
|
public void event() throws BaseballException {
|
||||||
// Doesn't actually have to throw anything
|
// Doesn't actually have to throw anything
|
||||||
}
|
}
|
||||||
|
@ -8,26 +8,26 @@ class Foo {}
|
|||||||
|
|
||||||
class Bar {
|
class Bar {
|
||||||
Foo f;
|
Foo f;
|
||||||
public Bar(Foo f) { this.f = f; }
|
Bar(Foo f) { this.f = f; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class IBaz {
|
class IBaz {
|
||||||
int i;
|
int i;
|
||||||
public IBaz(int i) {
|
IBaz(int i) {
|
||||||
this.i = i;
|
this.i = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LBaz {
|
class LBaz {
|
||||||
long l;
|
long l;
|
||||||
public LBaz(long l) {
|
LBaz(long l) {
|
||||||
this.l = l;
|
this.l = l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DBaz {
|
class DBaz {
|
||||||
double d;
|
double d;
|
||||||
public DBaz(double d) {
|
DBaz(double d) {
|
||||||
this.d = d;
|
this.d = d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class MethodReferences {
|
|||||||
}
|
}
|
||||||
static class Description {
|
static class Description {
|
||||||
String about;
|
String about;
|
||||||
public Description(String desc) { about = desc; }
|
Description(String desc) { about = desc; }
|
||||||
void help(String msg) { // [4]
|
void help(String msg) { // [4]
|
||||||
System.out.println(about + " " + msg);
|
System.out.println(about + " " + msg);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import static onjava.Tuple.*;
|
|||||||
class MixinProxy implements InvocationHandler {
|
class MixinProxy implements InvocationHandler {
|
||||||
Map<String, Object> delegatesByMethod;
|
Map<String, Object> delegatesByMethod;
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public MixinProxy(Tuple2<Object, Class<?>>... pairs) {
|
MixinProxy(Tuple2<Object, Class<?>>... pairs) {
|
||||||
delegatesByMethod = new HashMap<>();
|
delegatesByMethod = new HashMap<>();
|
||||||
for(Tuple2<Object, Class<?>> pair : pairs) {
|
for(Tuple2<Object, Class<?>> pair : pairs) {
|
||||||
for(Method method : pair.a2.getMethods()) {
|
for(Method method : pair.a2.getMethods()) {
|
||||||
|
@ -16,7 +16,7 @@ class IntegerFactory implements Supplier<Integer> {
|
|||||||
|
|
||||||
class Widget {
|
class Widget {
|
||||||
private int id;
|
private int id;
|
||||||
public Widget(int n) { id = n; }
|
Widget(int n) { id = n; }
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Widget " + id;
|
return "Widget " + id;
|
||||||
@ -38,7 +38,7 @@ class Fudge {
|
|||||||
|
|
||||||
class Foo2<T> {
|
class Foo2<T> {
|
||||||
private List<T> x = new ArrayList<>();
|
private List<T> x = new ArrayList<>();
|
||||||
public Foo2(Supplier<T> factory) {
|
Foo2(Supplier<T> factory) {
|
||||||
Suppliers.fill(x, factory, 5);
|
Suppliers.fill(x, factory, 5);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,8 +6,8 @@ import java.util.*;
|
|||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import onjava.*;
|
import onjava.*;
|
||||||
|
|
||||||
class FilledList<T> extends ArrayList<T> {
|
public class FilledList<T> extends ArrayList<T> {
|
||||||
public FilledList(Supplier<T> gen, int size) {
|
FilledList(Supplier<T> gen, int size) {
|
||||||
Suppliers.fill(this, gen, size);
|
Suppliers.fill(this, gen, size);
|
||||||
}
|
}
|
||||||
public FilledList(T t, int size) {
|
public FilledList(T t, int size) {
|
||||||
|
@ -9,7 +9,7 @@ class FixedSizeStack<T> {
|
|||||||
private final int size;
|
private final int size;
|
||||||
private Object[] storage;
|
private Object[] storage;
|
||||||
private int index = 0;
|
private int index = 0;
|
||||||
public FixedSizeStack(int size) {
|
FixedSizeStack(int size) {
|
||||||
this.size = size;
|
this.size = size;
|
||||||
storage = new Object[size];
|
storage = new Object[size];
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import java.util.function.*;
|
|||||||
|
|
||||||
class ClassAsFactory<T> implements Supplier<T> {
|
class ClassAsFactory<T> implements Supplier<T> {
|
||||||
Class<T> kind;
|
Class<T> kind;
|
||||||
public ClassAsFactory(Class<T> kind) {
|
ClassAsFactory(Class<T> kind) {
|
||||||
this.kind = kind;
|
this.kind = kind;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
class Manipulator<T> {
|
class Manipulator<T> {
|
||||||
private T obj;
|
private T obj;
|
||||||
public Manipulator(T x) { obj = x; }
|
Manipulator(T x) { obj = x; }
|
||||||
// Error: cannot find symbol: method f():
|
// Error: cannot find symbol: method f():
|
||||||
public void manipulate() { obj.f(); }
|
public void manipulate() { obj.f(); }
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,6 @@
|
|||||||
|
|
||||||
class Manipulator2<T extends HasF> {
|
class Manipulator2<T extends HasF> {
|
||||||
private T obj;
|
private T obj;
|
||||||
public Manipulator2(T x) { obj = x; }
|
Manipulator2(T x) { obj = x; }
|
||||||
public void manipulate() { obj.f(); }
|
public void manipulate() { obj.f(); }
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,6 @@
|
|||||||
|
|
||||||
class Manipulator3 {
|
class Manipulator3 {
|
||||||
private HasF obj;
|
private HasF obj;
|
||||||
public Manipulator3(HasF x) { obj = x; }
|
Manipulator3(HasF x) { obj = x; }
|
||||||
public void manipulate() { obj.f(); }
|
public void manipulate() { obj.f(); }
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ interface TimeStamped { long getStamp(); }
|
|||||||
|
|
||||||
class TimeStampedImp implements TimeStamped {
|
class TimeStampedImp implements TimeStamped {
|
||||||
private final long timeStamp;
|
private final long timeStamp;
|
||||||
public TimeStampedImp() {
|
TimeStampedImp() {
|
||||||
timeStamp = new Date().getTime();
|
timeStamp = new Date().getTime();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,6 +5,6 @@
|
|||||||
|
|
||||||
class ReturnGenericType<T extends HasF> {
|
class ReturnGenericType<T extends HasF> {
|
||||||
private T obj;
|
private T obj;
|
||||||
public ReturnGenericType(T x) { obj = x; }
|
ReturnGenericType(T x) { obj = x; }
|
||||||
public T get() { return obj; }
|
public T get() { return obj; }
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ class Product {
|
|||||||
private final int id;
|
private final int id;
|
||||||
private String description;
|
private String description;
|
||||||
private double price;
|
private double price;
|
||||||
public
|
|
||||||
Product(int idNumber, String descr, double price) {
|
Product(int idNumber, String descr, double price) {
|
||||||
id = idNumber;
|
id = idNumber;
|
||||||
description = descr;
|
description = descr;
|
||||||
@ -37,13 +36,13 @@ class Product {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Shelf extends ArrayList<Product> {
|
class Shelf extends ArrayList<Product> {
|
||||||
public Shelf(int nProducts) {
|
Shelf(int nProducts) {
|
||||||
Suppliers.fill(this, Product.generator, nProducts);
|
Suppliers.fill(this, Product.generator, nProducts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Aisle extends ArrayList<Shelf> {
|
class Aisle extends ArrayList<Shelf> {
|
||||||
public Aisle(int nShelves, int nProducts) {
|
Aisle(int nShelves, int nProducts) {
|
||||||
for(int i = 0; i < nShelves; i++)
|
for(int i = 0; i < nShelves; i++)
|
||||||
add(new Shelf(nProducts));
|
add(new Shelf(nProducts));
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ class Basic {
|
|||||||
|
|
||||||
class Decorator extends Basic {
|
class Decorator extends Basic {
|
||||||
protected Basic basic;
|
protected Basic basic;
|
||||||
public Decorator(Basic basic) { this.basic = basic; }
|
Decorator(Basic basic) { this.basic = basic; }
|
||||||
@Override
|
@Override
|
||||||
public void set(String val) { basic.set(val); }
|
public void set(String val) { basic.set(val); }
|
||||||
@Override
|
@Override
|
||||||
@ -23,7 +23,7 @@ class Decorator extends Basic {
|
|||||||
|
|
||||||
class TimeStamped extends Decorator {
|
class TimeStamped extends Decorator {
|
||||||
private final long timeStamp;
|
private final long timeStamp;
|
||||||
public TimeStamped(Basic basic) {
|
TimeStamped(Basic basic) {
|
||||||
super(basic);
|
super(basic);
|
||||||
timeStamp = new Date().getTime();
|
timeStamp = new Date().getTime();
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ class TimeStamped extends Decorator {
|
|||||||
class SerialNumbered extends Decorator {
|
class SerialNumbered extends Decorator {
|
||||||
private static long counter = 1;
|
private static long counter = 1;
|
||||||
private final long serialNumber = counter++;
|
private final long serialNumber = counter++;
|
||||||
public SerialNumbered(Basic basic) { super(basic); }
|
SerialNumbered(Basic basic) { super(basic); }
|
||||||
public long getSerialNumber() { return serialNumber; }
|
public long getSerialNumber() { return serialNumber; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
// Creating a constructor for an anonymous inner class
|
// Creating a constructor for an anonymous inner class
|
||||||
|
|
||||||
abstract class Base {
|
abstract class Base {
|
||||||
public Base(int i) {
|
Base(int i) {
|
||||||
System.out.println("Base constructor, i = " + i);
|
System.out.println("Base constructor, i = " + i);
|
||||||
}
|
}
|
||||||
public abstract void f();
|
public abstract void f();
|
||||||
|
@ -11,7 +11,7 @@ class Egg {
|
|||||||
System.out.println("Egg.Yolk()");
|
System.out.println("Egg.Yolk()");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Egg() {
|
Egg() {
|
||||||
System.out.println("New Egg()");
|
System.out.println("New Egg()");
|
||||||
y = new Yolk();
|
y = new Yolk();
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ class Egg2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private Yolk y = new Yolk();
|
private Yolk y = new Yolk();
|
||||||
public Egg2() { System.out.println("New Egg2()"); }
|
Egg2() { System.out.println("New Egg2()"); }
|
||||||
public void insertYolk(Yolk yy) { y = yy; }
|
public void insertYolk(Yolk yy) { y = yy; }
|
||||||
public void g() { y.f(); }
|
public void g() { y.f(); }
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public class LocalInnerClass {
|
|||||||
Counter getCounter(final String name) {
|
Counter getCounter(final String name) {
|
||||||
// A local inner class:
|
// A local inner class:
|
||||||
class LocalCounter implements Counter {
|
class LocalCounter implements Counter {
|
||||||
public LocalCounter() {
|
LocalCounter() {
|
||||||
// Local inner class can have a constructor
|
// Local inner class can have a constructor
|
||||||
System.out.println("LocalCounter()");
|
System.out.println("LocalCounter()");
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,8 @@ public class Applicator {
|
|||||||
System.out.println("Using Processor " + p.name());
|
System.out.println("Using Processor " + p.name());
|
||||||
System.out.println(p.process(s));
|
System.out.println(p.process(s));
|
||||||
}
|
}
|
||||||
public static final String s =
|
|
||||||
"Disagreement with beliefs is by definition incorrect";
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
String s = "We are such stuff as dreams are made on";
|
||||||
apply(new Upcase(), s);
|
apply(new Upcase(), s);
|
||||||
apply(new Downcase(), s);
|
apply(new Downcase(), s);
|
||||||
apply(new Splitter(), s);
|
apply(new Splitter(), s);
|
||||||
@ -50,10 +49,9 @@ public class Applicator {
|
|||||||
}
|
}
|
||||||
/* Output:
|
/* Output:
|
||||||
Using Processor Upcase
|
Using Processor Upcase
|
||||||
DISAGREEMENT WITH BELIEFS IS BY DEFINITION INCORRECT
|
WE ARE SUCH STUFF AS DREAMS ARE MADE ON
|
||||||
Using Processor Downcase
|
Using Processor Downcase
|
||||||
disagreement with beliefs is by definition incorrect
|
we are such stuff as dreams are made on
|
||||||
Using Processor Splitter
|
Using Processor Splitter
|
||||||
[Disagreement, with, beliefs, is, by, definition,
|
[We, are, such, stuff, as, dreams, are, made, on]
|
||||||
incorrect]
|
|
||||||
*/
|
*/
|
||||||
|
@ -8,7 +8,7 @@ import interfaces.filters.*;
|
|||||||
|
|
||||||
class FilterAdapter implements Processor {
|
class FilterAdapter implements Processor {
|
||||||
Filter filter;
|
Filter filter;
|
||||||
public FilterAdapter(Filter filter) {
|
FilterAdapter(Filter filter) {
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,7 +14,7 @@ class DelayedTask implements Runnable, Delayed {
|
|||||||
private final long trigger;
|
private final long trigger;
|
||||||
protected static List<DelayedTask> sequence =
|
protected static List<DelayedTask> sequence =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
public DelayedTask(int delayInMilliseconds) {
|
DelayedTask(int delayInMilliseconds) {
|
||||||
delta = delayInMilliseconds;
|
delta = delayInMilliseconds;
|
||||||
trigger = System.nanoTime() +
|
trigger = System.nanoTime() +
|
||||||
NANOSECONDS.convert(delta, MILLISECONDS);
|
NANOSECONDS.convert(delta, MILLISECONDS);
|
||||||
@ -45,7 +45,7 @@ class DelayedTask implements Runnable, Delayed {
|
|||||||
return String.format("(%d:%d)", id, delta);
|
return String.format("(%d:%d)", id, delta);
|
||||||
}
|
}
|
||||||
public static class EndTask extends DelayedTask {
|
public static class EndTask extends DelayedTask {
|
||||||
public EndTask(int delay) { super(delay); }
|
EndTask(int delay) { super(delay); }
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
sequence.forEach(dt ->
|
sequence.forEach(dt ->
|
||||||
|
@ -15,7 +15,7 @@ class Prioritized implements Comparable<Prioritized> {
|
|||||||
private final int priority;
|
private final int priority;
|
||||||
private static List<Prioritized> sequence =
|
private static List<Prioritized> sequence =
|
||||||
new CopyOnWriteArrayList<>();
|
new CopyOnWriteArrayList<>();
|
||||||
public Prioritized(int priority) {
|
Prioritized(int priority) {
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
sequence.add(this);
|
sequence.add(this);
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ class Prioritized implements Comparable<Prioritized> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class EndSentinel extends Prioritized {
|
public static class EndSentinel extends Prioritized {
|
||||||
public EndSentinel() { super(-1); }
|
EndSentinel() { super(-1); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ class Producer implements Runnable {
|
|||||||
private SplittableRandom rand =
|
private SplittableRandom rand =
|
||||||
new SplittableRandom(seed.getAndAdd(10));
|
new SplittableRandom(seed.getAndAdd(10));
|
||||||
private Queue<Prioritized> queue;
|
private Queue<Prioritized> queue;
|
||||||
public Producer(Queue<Prioritized> q) {
|
Producer(Queue<Prioritized> q) {
|
||||||
queue = q;
|
queue = q;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@ -65,7 +65,6 @@ class Consumer implements Runnable {
|
|||||||
private PriorityBlockingQueue<Prioritized> q;
|
private PriorityBlockingQueue<Prioritized> q;
|
||||||
private SplittableRandom rand =
|
private SplittableRandom rand =
|
||||||
new SplittableRandom(47);
|
new SplittableRandom(47);
|
||||||
public
|
|
||||||
Consumer(PriorityBlockingQueue<Prioritized> q) {
|
Consumer(PriorityBlockingQueue<Prioritized> q) {
|
||||||
this.q = q;
|
this.q = q;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
// Visit http://OnJava8.com for more book information.
|
// Visit http://OnJava8.com for more book information.
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import onjava.TimedAbort;
|
|
||||||
|
|
||||||
public class SafeReturn extends IntTestable {
|
public class SafeReturn extends IntTestable {
|
||||||
private int i = 0;
|
private int i = 0;
|
||||||
|
@ -38,7 +38,7 @@ class CriticalSection extends Guarded {
|
|||||||
|
|
||||||
class Caller implements Runnable {
|
class Caller implements Runnable {
|
||||||
private Guarded g;
|
private Guarded g;
|
||||||
public Caller(Guarded g) { this.g = g; }
|
Caller(Guarded g) { this.g = g; }
|
||||||
private AtomicLong successfulCalls =
|
private AtomicLong successfulCalls =
|
||||||
new AtomicLong();
|
new AtomicLong();
|
||||||
private AtomicBoolean stop =
|
private AtomicBoolean stop =
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
// Visit http://OnJava8.com for more book information.
|
// Visit http://OnJava8.com for more book information.
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import onjava.TimedAbort;
|
|
||||||
|
|
||||||
public class UnsafeReturn extends IntTestable {
|
public class UnsafeReturn extends IntTestable {
|
||||||
private int i = 0;
|
private int i = 0;
|
||||||
|
@ -12,7 +12,7 @@ public class MappedIO {
|
|||||||
private static int numOfUbuffInts = 100_000;
|
private static int numOfUbuffInts = 100_000;
|
||||||
private abstract static class Tester {
|
private abstract static class Tester {
|
||||||
private String name;
|
private String name;
|
||||||
public Tester(String name) {
|
Tester(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
public void runTest() {
|
public void runTest() {
|
||||||
|
@ -9,7 +9,7 @@ import java.util.function.*;
|
|||||||
import static onjava.ConvertTo.*;
|
import static onjava.ConvertTo.*;
|
||||||
|
|
||||||
public interface Count {
|
public interface Count {
|
||||||
public static class Boolean
|
class Boolean
|
||||||
implements Supplier<java.lang.Boolean> {
|
implements Supplier<java.lang.Boolean> {
|
||||||
private boolean b = true;
|
private boolean b = true;
|
||||||
@Override
|
@Override
|
||||||
@ -27,7 +27,7 @@ public interface Count {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Pboolean {
|
class Pboolean {
|
||||||
private boolean b = true;
|
private boolean b = true;
|
||||||
public boolean get() {
|
public boolean get() {
|
||||||
b = !b;
|
b = !b;
|
||||||
@ -38,7 +38,7 @@ public interface Count {
|
|||||||
return primitive(new Boolean().array(sz));
|
return primitive(new Boolean().array(sz));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Byte
|
class Byte
|
||||||
implements Supplier<java.lang.Byte> {
|
implements Supplier<java.lang.Byte> {
|
||||||
private byte b;
|
private byte b;
|
||||||
@Override
|
@Override
|
||||||
@ -53,7 +53,7 @@ public interface Count {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Pbyte {
|
class Pbyte {
|
||||||
private byte b;
|
private byte b;
|
||||||
public byte get() { return b++; }
|
public byte get() { return b++; }
|
||||||
public byte get(int n) { return get(); }
|
public byte get(int n) { return get(); }
|
||||||
@ -63,7 +63,7 @@ public interface Count {
|
|||||||
}
|
}
|
||||||
char[] CHARS =
|
char[] CHARS =
|
||||||
"abcdefghijklmnopqrstuvwxyz".toCharArray();
|
"abcdefghijklmnopqrstuvwxyz".toCharArray();
|
||||||
public static class Character
|
class Character
|
||||||
implements Supplier<java.lang.Character> {
|
implements Supplier<java.lang.Character> {
|
||||||
private int i;
|
private int i;
|
||||||
@Override
|
@Override
|
||||||
@ -81,7 +81,7 @@ public interface Count {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Pchar {
|
class Pchar {
|
||||||
private int i;
|
private int i;
|
||||||
public char get() {
|
public char get() {
|
||||||
i = (i + 1) % CHARS.length;
|
i = (i + 1) % CHARS.length;
|
||||||
@ -92,7 +92,7 @@ public interface Count {
|
|||||||
return primitive(new Character().array(sz));
|
return primitive(new Character().array(sz));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Short
|
class Short
|
||||||
implements Supplier<java.lang.Short> {
|
implements Supplier<java.lang.Short> {
|
||||||
short s;
|
short s;
|
||||||
@Override
|
@Override
|
||||||
@ -107,7 +107,7 @@ public interface Count {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Pshort {
|
class Pshort {
|
||||||
short s;
|
short s;
|
||||||
public short get() { return s++; }
|
public short get() { return s++; }
|
||||||
public short get(int n) { return get(); }
|
public short get(int n) { return get(); }
|
||||||
@ -115,7 +115,7 @@ public interface Count {
|
|||||||
return primitive(new Short().array(sz));
|
return primitive(new Short().array(sz));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Integer
|
class Integer
|
||||||
implements Supplier<java.lang.Integer> {
|
implements Supplier<java.lang.Integer> {
|
||||||
int i;
|
int i;
|
||||||
@Override
|
@Override
|
||||||
@ -130,7 +130,7 @@ public interface Count {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Pint implements IntSupplier {
|
class Pint implements IntSupplier {
|
||||||
int i;
|
int i;
|
||||||
public int get() { return i++; }
|
public int get() { return i++; }
|
||||||
public int get(int n) { return get(); }
|
public int get(int n) { return get(); }
|
||||||
@ -140,7 +140,7 @@ public interface Count {
|
|||||||
return primitive(new Integer().array(sz));
|
return primitive(new Integer().array(sz));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Long
|
class Long
|
||||||
implements Supplier<java.lang.Long> {
|
implements Supplier<java.lang.Long> {
|
||||||
private long l;
|
private long l;
|
||||||
@Override
|
@Override
|
||||||
@ -155,7 +155,6 @@ public interface Count {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static
|
|
||||||
class Plong implements LongSupplier {
|
class Plong implements LongSupplier {
|
||||||
private long l;
|
private long l;
|
||||||
public long get() { return l++; }
|
public long get() { return l++; }
|
||||||
@ -166,7 +165,7 @@ public interface Count {
|
|||||||
return primitive(new Long().array(sz));
|
return primitive(new Long().array(sz));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class Float
|
class Float
|
||||||
implements Supplier<java.lang.Float> {
|
implements Supplier<java.lang.Float> {
|
||||||
private int i;
|
private int i;
|
||||||
@Override
|
@Override
|
||||||
@ -183,7 +182,7 @@ public interface Count {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class Pfloat {
|
class Pfloat {
|
||||||
private int i;
|
private int i;
|
||||||
public float get() { return i++; }
|
public float get() { return i++; }
|
||||||
public float get(int n) { return get(); }
|
public float get(int n) { return get(); }
|
||||||
@ -191,7 +190,7 @@ public interface Count {
|
|||||||
return primitive(new Float().array(sz));
|
return primitive(new Float().array(sz));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class Double
|
class Double
|
||||||
implements Supplier<java.lang.Double> {
|
implements Supplier<java.lang.Double> {
|
||||||
private int i;
|
private int i;
|
||||||
@Override
|
@Override
|
||||||
@ -208,7 +207,7 @@ public interface Count {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class Pdouble implements DoubleSupplier {
|
class Pdouble implements DoubleSupplier {
|
||||||
private int i;
|
private int i;
|
||||||
public double get() { return i++; }
|
public double get() { return i++; }
|
||||||
public double get(int n) { return get(); }
|
public double get(int n) { return get(); }
|
||||||
|
@ -58,15 +58,15 @@ extends AbstractMap<Integer,String> {
|
|||||||
.toCollection(LinkedHashSet::new));
|
.toCollection(LinkedHashSet::new));
|
||||||
}
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
final int LIM = 6;
|
final int size = 6;
|
||||||
CountMap cm = new CountMap(60);
|
CountMap cm = new CountMap(60);
|
||||||
System.out.println(cm);
|
System.out.println(cm);
|
||||||
System.out.println(cm.get(500));
|
System.out.println(cm.get(500));
|
||||||
cm.values().stream()
|
cm.values().stream()
|
||||||
.limit(LIM)
|
.limit(size)
|
||||||
.forEach(System.out::println);
|
.forEach(System.out::println);
|
||||||
System.out.println();
|
System.out.println();
|
||||||
new Random(47).ints(LIM, 0, 1000)
|
new Random(47).ints(size, 0, 1000)
|
||||||
.mapToObj(cm::get)
|
.mapToObj(cm::get)
|
||||||
.forEach(System.out::println);
|
.forEach(System.out::println);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import static onjava.ConvertTo.*;
|
|||||||
|
|
||||||
public interface Rand {
|
public interface Rand {
|
||||||
int MOD = 10_000;
|
int MOD = 10_000;
|
||||||
public static class Boolean
|
class Boolean
|
||||||
implements Supplier<java.lang.Boolean> {
|
implements Supplier<java.lang.Boolean> {
|
||||||
SplittableRandom r = new SplittableRandom(47);
|
SplittableRandom r = new SplittableRandom(47);
|
||||||
@Override
|
@Override
|
||||||
@ -27,12 +27,12 @@ public interface Rand {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Pboolean {
|
class Pboolean {
|
||||||
public boolean[] array(int sz) {
|
public boolean[] array(int sz) {
|
||||||
return primitive(new Boolean().array(sz));
|
return primitive(new Boolean().array(sz));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Byte
|
class Byte
|
||||||
implements Supplier<java.lang.Byte> {
|
implements Supplier<java.lang.Byte> {
|
||||||
SplittableRandom r = new SplittableRandom(47);
|
SplittableRandom r = new SplittableRandom(47);
|
||||||
@Override
|
@Override
|
||||||
@ -49,12 +49,12 @@ public interface Rand {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Pbyte {
|
class Pbyte {
|
||||||
public byte[] array(int sz) {
|
public byte[] array(int sz) {
|
||||||
return primitive(new Byte().array(sz));
|
return primitive(new Byte().array(sz));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Character
|
class Character
|
||||||
implements Supplier<java.lang.Character> {
|
implements Supplier<java.lang.Character> {
|
||||||
SplittableRandom r = new SplittableRandom(47);
|
SplittableRandom r = new SplittableRandom(47);
|
||||||
@Override
|
@Override
|
||||||
@ -71,12 +71,12 @@ public interface Rand {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Pchar {
|
class Pchar {
|
||||||
public char[] array(int sz) {
|
public char[] array(int sz) {
|
||||||
return primitive(new Character().array(sz));
|
return primitive(new Character().array(sz));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Short
|
class Short
|
||||||
implements Supplier<java.lang.Short> {
|
implements Supplier<java.lang.Short> {
|
||||||
SplittableRandom r = new SplittableRandom(47);
|
SplittableRandom r = new SplittableRandom(47);
|
||||||
@Override
|
@Override
|
||||||
@ -93,12 +93,12 @@ public interface Rand {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Pshort {
|
class Pshort {
|
||||||
public short[] array(int sz) {
|
public short[] array(int sz) {
|
||||||
return primitive(new Short().array(sz));
|
return primitive(new Short().array(sz));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Integer
|
class Integer
|
||||||
implements Supplier<java.lang.Integer> {
|
implements Supplier<java.lang.Integer> {
|
||||||
SplittableRandom r = new SplittableRandom(47);
|
SplittableRandom r = new SplittableRandom(47);
|
||||||
@Override
|
@Override
|
||||||
@ -117,7 +117,7 @@ public interface Rand {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Pint implements IntSupplier {
|
class Pint implements IntSupplier {
|
||||||
SplittableRandom r = new SplittableRandom(47);
|
SplittableRandom r = new SplittableRandom(47);
|
||||||
@Override
|
@Override
|
||||||
public int getAsInt() {
|
public int getAsInt() {
|
||||||
@ -128,7 +128,7 @@ public interface Rand {
|
|||||||
return r.ints(sz, 0, MOD).toArray();
|
return r.ints(sz, 0, MOD).toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Long
|
class Long
|
||||||
implements Supplier<java.lang.Long> {
|
implements Supplier<java.lang.Long> {
|
||||||
SplittableRandom r = new SplittableRandom(47);
|
SplittableRandom r = new SplittableRandom(47);
|
||||||
@Override
|
@Override
|
||||||
@ -147,7 +147,6 @@ public interface Rand {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static
|
|
||||||
class Plong implements LongSupplier {
|
class Plong implements LongSupplier {
|
||||||
SplittableRandom r = new SplittableRandom(47);
|
SplittableRandom r = new SplittableRandom(47);
|
||||||
@Override
|
@Override
|
||||||
@ -159,7 +158,7 @@ public interface Rand {
|
|||||||
return r.longs(sz, 0, MOD).toArray();
|
return r.longs(sz, 0, MOD).toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Float
|
class Float
|
||||||
implements Supplier<java.lang.Float> {
|
implements Supplier<java.lang.Float> {
|
||||||
SplittableRandom r = new SplittableRandom(47);
|
SplittableRandom r = new SplittableRandom(47);
|
||||||
@Override
|
@Override
|
||||||
@ -176,7 +175,7 @@ public interface Rand {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class Pfloat {
|
class Pfloat {
|
||||||
public float[] array(int sz) {
|
public float[] array(int sz) {
|
||||||
return primitive(new Float().array(sz));
|
return primitive(new Float().array(sz));
|
||||||
}
|
}
|
||||||
@ -185,7 +184,7 @@ public interface Rand {
|
|||||||
return
|
return
|
||||||
((double)Math.round(d * 1000.0)) / 100.0;
|
((double)Math.round(d * 1000.0)) / 100.0;
|
||||||
}
|
}
|
||||||
public static class Double
|
class Double
|
||||||
implements Supplier<java.lang.Double> {
|
implements Supplier<java.lang.Double> {
|
||||||
SplittableRandom r = new SplittableRandom(47);
|
SplittableRandom r = new SplittableRandom(47);
|
||||||
@Override
|
@Override
|
||||||
@ -205,7 +204,6 @@ public interface Rand {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static
|
|
||||||
class Pdouble implements DoubleSupplier {
|
class Pdouble implements DoubleSupplier {
|
||||||
SplittableRandom r = new SplittableRandom(47);
|
SplittableRandom r = new SplittableRandom(47);
|
||||||
@Override
|
@Override
|
||||||
@ -222,7 +220,7 @@ public interface Rand {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class String
|
class String
|
||||||
implements Supplier<java.lang.String> {
|
implements Supplier<java.lang.String> {
|
||||||
SplittableRandom r = new SplittableRandom(47);
|
SplittableRandom r = new SplittableRandom(47);
|
||||||
private int strlen = 7; // Default length
|
private int strlen = 7; // Default length
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://OnJava8.com for more book information.
|
// Visit http://OnJava8.com for more book information.
|
||||||
|
|
||||||
class A { public A(int x) {} }
|
class A { A(int x) {} }
|
||||||
class B { public B(long x) {} }
|
class B { B(long x) {} }
|
||||||
class C { public C(double x) {} }
|
class C { C(double x) {} }
|
||||||
|
|
||||||
// Other classes that aren't exposed by the
|
// Other classes that aren't exposed by the
|
||||||
// facade go here ...
|
// facade go here ...
|
||||||
|
@ -12,7 +12,7 @@ interface ProxyBase {
|
|||||||
|
|
||||||
class Proxy implements ProxyBase {
|
class Proxy implements ProxyBase {
|
||||||
private ProxyBase implementation;
|
private ProxyBase implementation;
|
||||||
public Proxy() {
|
Proxy() {
|
||||||
implementation = new Implementation();
|
implementation = new Implementation();
|
||||||
}
|
}
|
||||||
// Pass method calls to the implementation:
|
// Pass method calls to the implementation:
|
||||||
|
@ -15,7 +15,6 @@ interface PolymorphicFactory {
|
|||||||
class RandomShapes implements Supplier<Shape> {
|
class RandomShapes implements Supplier<Shape> {
|
||||||
private final PolymorphicFactory[] factories;
|
private final PolymorphicFactory[] factories;
|
||||||
private Random rand = new Random(42);
|
private Random rand = new Random(42);
|
||||||
public
|
|
||||||
RandomShapes(PolymorphicFactory... factories) {
|
RandomShapes(PolymorphicFactory... factories) {
|
||||||
this.factories = factories;
|
this.factories = factories;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ interface Resource {
|
|||||||
// implements thread-safe lazy initialization:
|
// implements thread-safe lazy initialization:
|
||||||
|
|
||||||
final class Singleton {
|
final class Singleton {
|
||||||
private static class
|
private static final class
|
||||||
ResourceImpl implements Resource {
|
ResourceImpl implements Resource {
|
||||||
private int i;
|
private int i;
|
||||||
private ResourceImpl(int i) {
|
private ResourceImpl(int i) {
|
||||||
|
@ -13,7 +13,7 @@ interface StateBase {
|
|||||||
|
|
||||||
class State implements StateBase {
|
class State implements StateBase {
|
||||||
private StateBase implementation;
|
private StateBase implementation;
|
||||||
public State(StateBase imp) {
|
State(StateBase imp) {
|
||||||
implementation = imp;
|
implementation = imp;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
import java.util.stream.*;
|
import java.util.stream.*;
|
||||||
|
|
||||||
abstract class ApplicationFramework {
|
abstract class ApplicationFramework {
|
||||||
public ApplicationFramework() {
|
ApplicationFramework() {
|
||||||
templateMethod();
|
templateMethod();
|
||||||
}
|
}
|
||||||
abstract void customize1();
|
abstract void customize1();
|
||||||
|
@ -17,7 +17,7 @@ interface WhatIWant {
|
|||||||
|
|
||||||
class ProxyAdapter implements WhatIWant {
|
class ProxyAdapter implements WhatIWant {
|
||||||
WhatIHave whatIHave;
|
WhatIHave whatIHave;
|
||||||
public ProxyAdapter(WhatIHave wih) {
|
ProxyAdapter(WhatIHave wih) {
|
||||||
whatIHave = wih;
|
whatIHave = wih;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,11 +11,11 @@ import java.util.function.*;
|
|||||||
class Result {
|
class Result {
|
||||||
boolean success;
|
boolean success;
|
||||||
List<Double> line;
|
List<Double> line;
|
||||||
public Result(List<Double> data) {
|
Result(List<Double> data) {
|
||||||
success = true;
|
success = true;
|
||||||
line = data;
|
line = data;
|
||||||
}
|
}
|
||||||
public Result() {
|
Result() {
|
||||||
success = false;
|
success = false;
|
||||||
line = Collections.<Double>emptyList();
|
line = Collections.<Double>emptyList();
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class TypeMap<T> {
|
|||||||
// from ParseTrash.fillBin():
|
// from ParseTrash.fillBin():
|
||||||
class TypeMapAdapter implements Fillable {
|
class TypeMapAdapter implements Fillable {
|
||||||
TypeMap<Trash> map;
|
TypeMap<Trash> map;
|
||||||
public TypeMapAdapter(TypeMap<Trash> tm) {
|
TypeMapAdapter(TypeMap<Trash> tm) {
|
||||||
map = tm;
|
map = tm;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,7 +11,7 @@ class Flower {
|
|||||||
private boolean isOpen;
|
private boolean isOpen;
|
||||||
private boolean alreadyOpen;
|
private boolean alreadyOpen;
|
||||||
private boolean alreadyClosed;
|
private boolean alreadyClosed;
|
||||||
public Flower() { isOpen = false; }
|
Flower() { isOpen = false; }
|
||||||
OpenNotifier opening = new OpenNotifier();
|
OpenNotifier opening = new OpenNotifier();
|
||||||
CloseNotifier closing = new CloseNotifier();
|
CloseNotifier closing = new CloseNotifier();
|
||||||
public void open() { // Opens its petals
|
public void open() { // Opens its petals
|
||||||
@ -48,7 +48,7 @@ class Flower {
|
|||||||
|
|
||||||
class Bee {
|
class Bee {
|
||||||
private String name;
|
private String name;
|
||||||
public Bee(String nm) { name = nm; }
|
Bee(String nm) { name = nm; }
|
||||||
// Observe openings:
|
// Observe openings:
|
||||||
public Observer openObserver() {
|
public Observer openObserver() {
|
||||||
return (ob, a) -> System.out.println(
|
return (ob, a) -> System.out.println(
|
||||||
@ -63,7 +63,7 @@ class Bee {
|
|||||||
|
|
||||||
class Hummingbird {
|
class Hummingbird {
|
||||||
private String name;
|
private String name;
|
||||||
public Hummingbird(String nm) { name = nm; }
|
Hummingbird(String nm) { name = nm; }
|
||||||
public Observer openObserver() {
|
public Observer openObserver() {
|
||||||
return (ob, a) -> System.out.println(
|
return (ob, a) -> System.out.println(
|
||||||
"Hummingbird " + name +
|
"Hummingbird " + name +
|
||||||
|
@ -54,7 +54,7 @@ class Washer extends StateMachine {
|
|||||||
new Wash(), new Spin(),
|
new Wash(), new Spin(),
|
||||||
new Rinse(), new Spin(),
|
new Rinse(), new Spin(),
|
||||||
};
|
};
|
||||||
public Washer() { runAll(); }
|
Washer() { runAll(); }
|
||||||
@Override
|
@Override
|
||||||
public boolean changeState() {
|
public boolean changeState() {
|
||||||
if(i < states.length) {
|
if(i < states.length) {
|
||||||
|
@ -35,7 +35,7 @@ class Bisection extends FindMinima {
|
|||||||
// The "Context" controls the strategy:
|
// The "Context" controls the strategy:
|
||||||
class MinimaSolver {
|
class MinimaSolver {
|
||||||
private FindMinima strategy;
|
private FindMinima strategy;
|
||||||
public MinimaSolver(FindMinima strat) {
|
MinimaSolver(FindMinima strat) {
|
||||||
strategy = strat;
|
strategy = strat;
|
||||||
}
|
}
|
||||||
List<Double> minima(List<Double> line) {
|
List<Double> minima(List<Double> line) {
|
||||||
|
@ -8,7 +8,7 @@ class Shared {
|
|||||||
private int refcount = 0;
|
private int refcount = 0;
|
||||||
private static long counter = 0;
|
private static long counter = 0;
|
||||||
private final long id = counter++;
|
private final long id = counter++;
|
||||||
public Shared() {
|
Shared() {
|
||||||
System.out.println("Creating " + this);
|
System.out.println("Creating " + this);
|
||||||
}
|
}
|
||||||
public void addRef() { refcount++; }
|
public void addRef() { refcount++; }
|
||||||
@ -26,7 +26,7 @@ class Composing {
|
|||||||
private Shared shared;
|
private Shared shared;
|
||||||
private static long counter = 0;
|
private static long counter = 0;
|
||||||
private final long id = counter++;
|
private final long id = counter++;
|
||||||
public Composing(Shared shared) {
|
Composing(Shared shared) {
|
||||||
System.out.println("Creating " + this);
|
System.out.println("Creating " + this);
|
||||||
this.shared = shared;
|
this.shared = shared;
|
||||||
this.shared.addRef();
|
this.shared.addRef();
|
||||||
|
@ -9,7 +9,7 @@ import java.util.stream.*;
|
|||||||
|
|
||||||
class Int2 implements Cloneable {
|
class Int2 implements Cloneable {
|
||||||
private int i;
|
private int i;
|
||||||
public Int2(int ii) { i = ii; }
|
Int2(int ii) { i = ii; }
|
||||||
public void increment() { i++; }
|
public void increment() { i++; }
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
@ -28,7 +28,7 @@ class Int2 implements Cloneable {
|
|||||||
// Inheritance doesn't remove cloneability:
|
// Inheritance doesn't remove cloneability:
|
||||||
class Int3 extends Int2 {
|
class Int3 extends Int2 {
|
||||||
private int j; // Automatically duplicated
|
private int j; // Automatically duplicated
|
||||||
public Int3(int i) { super(i); }
|
Int3(int i) { super(i); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AddingClone {
|
public class AddingClone {
|
||||||
|
@ -9,7 +9,7 @@ import java.util.stream.*;
|
|||||||
|
|
||||||
class Int {
|
class Int {
|
||||||
private int i;
|
private int i;
|
||||||
public Int(int ii) { i = ii; }
|
Int(int ii) { i = ii; }
|
||||||
public void increment() { i++; }
|
public void increment() { i++; }
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -14,13 +14,13 @@ class FruitQualities {
|
|||||||
private int smell;
|
private int smell;
|
||||||
// etc.
|
// etc.
|
||||||
// No-arg constructor:
|
// No-arg constructor:
|
||||||
public FruitQualities() {
|
FruitQualities() {
|
||||||
// Do something meaningful...
|
// Do something meaningful...
|
||||||
}
|
}
|
||||||
// Other constructors:
|
// Other constructors:
|
||||||
// ...
|
// ...
|
||||||
// Copy constructor:
|
// Copy constructor:
|
||||||
public FruitQualities(FruitQualities f) {
|
FruitQualities(FruitQualities f) {
|
||||||
weight = f.weight;
|
weight = f.weight;
|
||||||
color = f.color;
|
color = f.color;
|
||||||
firmness = f.firmness;
|
firmness = f.firmness;
|
||||||
@ -32,15 +32,15 @@ class FruitQualities {
|
|||||||
|
|
||||||
class Seed {
|
class Seed {
|
||||||
// Members...
|
// Members...
|
||||||
public Seed() { /* No-arg constructor */ }
|
Seed() { /* No-arg constructor */ }
|
||||||
public Seed(Seed s) { /* Copy constructor */ }
|
Seed(Seed s) { /* Copy constructor */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Fruit {
|
class Fruit {
|
||||||
private FruitQualities fq;
|
private FruitQualities fq;
|
||||||
private int seeds;
|
private int seeds;
|
||||||
private Seed[] s;
|
private Seed[] s;
|
||||||
public Fruit(FruitQualities q, int seedCount) {
|
Fruit(FruitQualities q, int seedCount) {
|
||||||
fq = q;
|
fq = q;
|
||||||
seeds = seedCount;
|
seeds = seedCount;
|
||||||
s = new Seed[seeds];
|
s = new Seed[seeds];
|
||||||
@ -50,7 +50,7 @@ class Fruit {
|
|||||||
// Other constructors:
|
// Other constructors:
|
||||||
// ...
|
// ...
|
||||||
// Copy constructor:
|
// Copy constructor:
|
||||||
public Fruit(Fruit f) {
|
Fruit(Fruit f) {
|
||||||
fq = new FruitQualities(f.fq);
|
fq = new FruitQualities(f.fq);
|
||||||
seeds = f.seeds;
|
seeds = f.seeds;
|
||||||
s = new Seed[seeds];
|
s = new Seed[seeds];
|
||||||
@ -70,10 +70,10 @@ class Fruit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Tomato extends Fruit {
|
class Tomato extends Fruit {
|
||||||
public Tomato() {
|
Tomato() {
|
||||||
super(new FruitQualities(), 100);
|
super(new FruitQualities(), 100);
|
||||||
}
|
}
|
||||||
public Tomato(Tomato t) { // Copy-constructor
|
Tomato(Tomato t) { // Copy-constructor
|
||||||
super(t); // Upcast to base copy-constructor
|
super(t); // Upcast to base copy-constructor
|
||||||
// Other copy-construction activities...
|
// Other copy-construction activities...
|
||||||
}
|
}
|
||||||
@ -82,21 +82,21 @@ class Tomato extends Fruit {
|
|||||||
class ZebraQualities extends FruitQualities {
|
class ZebraQualities extends FruitQualities {
|
||||||
private int stripedness;
|
private int stripedness;
|
||||||
// No-arg constructor:
|
// No-arg constructor:
|
||||||
public ZebraQualities() {
|
ZebraQualities() {
|
||||||
super();
|
super();
|
||||||
// do something meaningful...
|
// do something meaningful...
|
||||||
}
|
}
|
||||||
public ZebraQualities(ZebraQualities z) {
|
ZebraQualities(ZebraQualities z) {
|
||||||
super(z);
|
super(z);
|
||||||
stripedness = z.stripedness;
|
stripedness = z.stripedness;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GreenZebra extends Tomato {
|
class GreenZebra extends Tomato {
|
||||||
public GreenZebra() {
|
GreenZebra() {
|
||||||
addQualities(new ZebraQualities());
|
addQualities(new ZebraQualities());
|
||||||
}
|
}
|
||||||
public GreenZebra(GreenZebra g) {
|
GreenZebra(GreenZebra g) {
|
||||||
super(g); // Calls Tomato(Tomato)
|
super(g); // Calls Tomato(Tomato)
|
||||||
// Restore the right qualities:
|
// Restore the right qualities:
|
||||||
addQualities(new ZebraQualities());
|
addQualities(new ZebraQualities());
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
class Mutable {
|
class Mutable {
|
||||||
private int data;
|
private int data;
|
||||||
public Mutable(int initVal) {
|
Mutable(int initVal) {
|
||||||
data = initVal;
|
data = initVal;
|
||||||
}
|
}
|
||||||
public Mutable add(int x) {
|
public Mutable add(int x) {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
class Duplo implements Cloneable {
|
class Duplo implements Cloneable {
|
||||||
private int n;
|
private int n;
|
||||||
public Duplo(int n) { this.n = n; }
|
Duplo(int n) { this.n = n; }
|
||||||
@Override
|
@Override
|
||||||
public Duplo clone() { // [1]
|
public Duplo clone() { // [1]
|
||||||
try {
|
try {
|
||||||
|
@ -8,7 +8,7 @@ import java.util.stream.*;
|
|||||||
|
|
||||||
class IntValue {
|
class IntValue {
|
||||||
private int n;
|
private int n;
|
||||||
public IntValue(int x) { n = x; }
|
IntValue(int x) { n = x; }
|
||||||
public int getValue() { return n; }
|
public int getValue() { return n; }
|
||||||
public void setValue(int n) { this.n = n; }
|
public void setValue(int n) { this.n = n; }
|
||||||
public void increment() { n++; }
|
public void increment() { n++; }
|
||||||
|
@ -8,7 +8,7 @@ import java.util.stream.*;
|
|||||||
|
|
||||||
class IntValue2 {
|
class IntValue2 {
|
||||||
public int n;
|
public int n;
|
||||||
public IntValue2(int n) { this.n = n; }
|
IntValue2(int n) { this.n = n; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SimplerMutableInteger {
|
public class SimplerMutableInteger {
|
||||||
|
@ -7,7 +7,7 @@ import java.util.*;
|
|||||||
|
|
||||||
class Value {
|
class Value {
|
||||||
int i; // Package access
|
int i; // Package access
|
||||||
public Value(int i) { this.i = i; }
|
Value(int i) { this.i = i; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FinalData {
|
public class FinalData {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
class Villain {
|
class Villain {
|
||||||
private String name;
|
private String name;
|
||||||
protected void set(String nm) { name = nm; }
|
protected void set(String nm) { name = nm; }
|
||||||
public Villain(String name) { this.name = name; }
|
Villain(String name) { this.name = name; }
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "I'm a Villain and my name is " + name;
|
return "I'm a Villain and my name is " + name;
|
||||||
|
@ -15,7 +15,7 @@ abstract class Shape implements Serializable {
|
|||||||
private static int counter = 0;
|
private static int counter = 0;
|
||||||
public abstract void setColor(Color newColor);
|
public abstract void setColor(Color newColor);
|
||||||
public abstract Color getColor();
|
public abstract Color getColor();
|
||||||
public Shape(int xVal, int yVal, int dim) {
|
Shape(int xVal, int yVal, int dim) {
|
||||||
xPos = xVal;
|
xPos = xVal;
|
||||||
yPos = yVal;
|
yPos = yVal;
|
||||||
dimension = dim;
|
dimension = dim;
|
||||||
@ -40,7 +40,7 @@ abstract class Shape implements Serializable {
|
|||||||
|
|
||||||
class Circle extends Shape {
|
class Circle extends Shape {
|
||||||
private static Color color = Color.RED;
|
private static Color color = Color.RED;
|
||||||
public Circle(int xVal, int yVal, int dim) {
|
Circle(int xVal, int yVal, int dim) {
|
||||||
super(xVal, yVal, dim);
|
super(xVal, yVal, dim);
|
||||||
}
|
}
|
||||||
public void setColor(Color newColor) {
|
public void setColor(Color newColor) {
|
||||||
@ -51,7 +51,7 @@ class Circle extends Shape {
|
|||||||
|
|
||||||
class Square extends Shape {
|
class Square extends Shape {
|
||||||
private static Color color = Color.RED;
|
private static Color color = Color.RED;
|
||||||
public Square(int xVal, int yVal, int dim) {
|
Square(int xVal, int yVal, int dim) {
|
||||||
super(xVal, yVal, dim);
|
super(xVal, yVal, dim);
|
||||||
}
|
}
|
||||||
public void setColor(Color newColor) {
|
public void setColor(Color newColor) {
|
||||||
@ -70,7 +70,7 @@ class Line extends Shape {
|
|||||||
throws IOException, ClassNotFoundException {
|
throws IOException, ClassNotFoundException {
|
||||||
color = (Color)os.readObject();
|
color = (Color)os.readObject();
|
||||||
}
|
}
|
||||||
public Line(int xVal, int yVal, int dim) {
|
Line(int xVal, int yVal, int dim) {
|
||||||
super(xVal, yVal, dim);
|
super(xVal, yVal, dim);
|
||||||
}
|
}
|
||||||
public void setColor(Color newColor) {
|
public void setColor(Color newColor) {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
class Blip1 implements Externalizable {
|
class Blip1 implements Externalizable {
|
||||||
public Blip1() {
|
Blip1() {
|
||||||
System.out.println("Blip1 Constructor");
|
System.out.println("Blip1 Constructor");
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -8,7 +8,7 @@ import java.util.*;
|
|||||||
|
|
||||||
class Data implements Serializable {
|
class Data implements Serializable {
|
||||||
private int n;
|
private int n;
|
||||||
public Data(int n) { this.n = n; }
|
Data(int n) { this.n = n; }
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return Integer.toString(n);
|
return Integer.toString(n);
|
||||||
|
@ -8,7 +8,7 @@ import java.util.stream.*;
|
|||||||
class Pair {
|
class Pair {
|
||||||
public final Character c;
|
public final Character c;
|
||||||
public final Integer i;
|
public final Integer i;
|
||||||
public Pair(Character c, Integer i) {
|
Pair(Character c, Integer i) {
|
||||||
this.c = c;
|
this.c = c;
|
||||||
this.i = i;
|
this.i = i;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ class Person {
|
|||||||
public final Optional<String> address;
|
public final Optional<String> address;
|
||||||
// etc.
|
// etc.
|
||||||
public final boolean empty;
|
public final boolean empty;
|
||||||
public
|
|
||||||
Person(String first, String last, String address) {
|
Person(String first, String last, String address) {
|
||||||
this.first = Optional.ofNullable(first);
|
this.first = Optional.ofNullable(first);
|
||||||
this.last = Optional.ofNullable(last);
|
this.last = Optional.ofNullable(last);
|
||||||
@ -21,11 +20,11 @@ class Person {
|
|||||||
&& !this.last.isPresent()
|
&& !this.last.isPresent()
|
||||||
&& !this.address.isPresent();
|
&& !this.address.isPresent();
|
||||||
}
|
}
|
||||||
public Person(String first, String last) {
|
Person(String first, String last) {
|
||||||
this(first, last, null);
|
this(first, last, null);
|
||||||
}
|
}
|
||||||
public Person(String last) { this(null, last, null); }
|
Person(String last) { this(null, last, null); }
|
||||||
public Person() { this(null, null, null); }
|
Person() { this(null, null, null); }
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if(empty)
|
if(empty)
|
||||||
|
@ -11,7 +11,7 @@ import typeinfo.pets.*;
|
|||||||
public class PetCount3 {
|
public class PetCount3 {
|
||||||
static class Counter extends
|
static class Counter extends
|
||||||
LinkedHashMap<Class<? extends Pet>, Integer> {
|
LinkedHashMap<Class<? extends Pet>, Integer> {
|
||||||
public Counter() {
|
Counter() {
|
||||||
super(LiteralPetCreator.ALL_TYPES.stream()
|
super(LiteralPetCreator.ALL_TYPES.stream()
|
||||||
.map(lpc -> Pair.make(lpc, 0))
|
.map(lpc -> Pair.make(lpc, 0))
|
||||||
.collect(
|
.collect(
|
||||||
|
@ -9,11 +9,11 @@ class EmptyTitleException extends RuntimeException {}
|
|||||||
class Position {
|
class Position {
|
||||||
private String title;
|
private String title;
|
||||||
private Person person;
|
private Person person;
|
||||||
public Position(String jobTitle, Person employee) {
|
Position(String jobTitle, Person employee) {
|
||||||
setTitle(jobTitle);
|
setTitle(jobTitle);
|
||||||
setPerson(employee);
|
setPerson(employee);
|
||||||
}
|
}
|
||||||
public Position(String jobTitle) {
|
Position(String jobTitle) {
|
||||||
this(jobTitle, null);
|
this(jobTitle, null);
|
||||||
}
|
}
|
||||||
public String getTitle() { return title; }
|
public String getTitle() { return title; }
|
||||||
|
@ -7,7 +7,7 @@ import java.lang.reflect.*;
|
|||||||
|
|
||||||
class MethodSelector implements InvocationHandler {
|
class MethodSelector implements InvocationHandler {
|
||||||
private Object proxied;
|
private Object proxied;
|
||||||
public MethodSelector(Object proxied) {
|
MethodSelector(Object proxied) {
|
||||||
this.proxied = proxied;
|
this.proxied = proxied;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,7 +6,7 @@ import java.lang.reflect.*;
|
|||||||
|
|
||||||
class DynamicProxyHandler implements InvocationHandler {
|
class DynamicProxyHandler implements InvocationHandler {
|
||||||
private Object proxied;
|
private Object proxied;
|
||||||
public DynamicProxyHandler(Object proxied) {
|
DynamicProxyHandler(Object proxied) {
|
||||||
this.proxied = proxied;
|
this.proxied = proxied;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,7 +21,7 @@ class RealObject implements Interface {
|
|||||||
|
|
||||||
class SimpleProxy implements Interface {
|
class SimpleProxy implements Interface {
|
||||||
private Interface proxied;
|
private Interface proxied;
|
||||||
public SimpleProxy(Interface proxied) {
|
SimpleProxy(Interface proxied) {
|
||||||
this.proxied = proxied;
|
this.proxied = proxied;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user