diff --git a/arrays/ArrayCopying.java b/arrays/ArrayCopying.java index 01022e24..8d4ae37e 100644 --- a/arrays/ArrayCopying.java +++ b/arrays/ArrayCopying.java @@ -9,7 +9,7 @@ import static onjava.ArrayShow.*; class Sup { // Superclass private int id; - public Sup(int n) { id = n; } + Sup(int n) { id = n; } @Override public String toString() { return getClass().getSimpleName() + id; @@ -17,7 +17,7 @@ class Sup { // Superclass } class Sub extends Sup { // Subclass - public Sub(int n) { super(n); } + Sub(int n) { super(n); } } public class ArrayCopying { diff --git a/arrays/SimpleSetAll.java b/arrays/SimpleSetAll.java index 060a986d..ce281c97 100644 --- a/arrays/SimpleSetAll.java +++ b/arrays/SimpleSetAll.java @@ -7,7 +7,7 @@ import static onjava.ArrayShow.*; class Bob { final int id; - public Bob(int n) { id = n; } + Bob(int n) { id = n; } @Override public String toString() { return "Bob" + id; } } diff --git a/check.bat b/check.bat index c250560b..25446ee4 100644 --- a/check.bat +++ b/check.bat @@ -1,2 +1,2 @@ cp ..\..\OnJava-Tools\verify_output.py . -python verify_output.py +py -3 verify_output.py diff --git a/chkstyle.bat b/chkstyle.bat index f389e5b7..24838fc0 100644 --- a/chkstyle.bat +++ b/chkstyle.bat @@ -1,2 +1,2 @@ -gradlew clean +@echo run gradlew clean first! gradlew checkstyleMain 1> checkstyleout.txt 2>&1 diff --git a/collections/AdapterMethodIdiom.java b/collections/AdapterMethodIdiom.java index 528cb829..a7ebc616 100644 --- a/collections/AdapterMethodIdiom.java +++ b/collections/AdapterMethodIdiom.java @@ -7,7 +7,7 @@ import java.util.*; class ReversibleArrayList extends ArrayList { - public ReversibleArrayList(Collection c) { + ReversibleArrayList(Collection c) { super(c); } public Iterable reversed() { diff --git a/collectiontopics/CanonicalMapping.java b/collectiontopics/CanonicalMapping.java index f81d0bb8..f3bbdae2 100644 --- a/collectiontopics/CanonicalMapping.java +++ b/collectiontopics/CanonicalMapping.java @@ -7,7 +7,7 @@ import java.util.*; class Element { private String ident; - public Element(String id) { ident = id; } + Element(String id) { ident = id; } @Override public String toString() { return ident; } @Override @@ -27,11 +27,11 @@ class Element { } class Key extends Element { - public Key(String id) { super(id); } + Key(String id) { super(id); } } class Value extends Element { - public Value(String id) { super(id); } + Value(String id) { super(id); } } public class CanonicalMapping { diff --git a/collectiontopics/FillingLists.java b/collectiontopics/FillingLists.java index f8fe104e..e29fd456 100644 --- a/collectiontopics/FillingLists.java +++ b/collectiontopics/FillingLists.java @@ -7,7 +7,7 @@ import java.util.*; class StringAddress { private String s; - public StringAddress(String s) { this.s = s; } + StringAddress(String s) { this.s = s; } @Override public String toString() { return super.toString() + " " + s; diff --git a/collectiontopics/References.java b/collectiontopics/References.java index 68e9ec52..ea99741f 100644 --- a/collectiontopics/References.java +++ b/collectiontopics/References.java @@ -10,7 +10,7 @@ class VeryBig { private static final int SIZE = 10000; private long[] la = new long[SIZE]; private String ident; - public VeryBig(String id) { ident = id; } + VeryBig(String id) { ident = id; } @Override public String toString() { return ident; } @Override diff --git a/collectiontopics/SimpleDeques.java b/collectiontopics/SimpleDeques.java index 1600178e..c938ec00 100644 --- a/collectiontopics/SimpleDeques.java +++ b/collectiontopics/SimpleDeques.java @@ -9,8 +9,8 @@ import java.util.function.*; class CountString implements Supplier { private int n = 0; - public CountString() {} - public CountString(int start) { n = start; } + CountString() {} + CountString(int start) { n = start; } @Override public String get() { return Integer.toString(n++); diff --git a/collectiontopics/ToDoList.java b/collectiontopics/ToDoList.java index 8b5cb856..1da979ba 100644 --- a/collectiontopics/ToDoList.java +++ b/collectiontopics/ToDoList.java @@ -9,7 +9,7 @@ class ToDoItem implements Comparable { private char primary; private int secondary; private String item; - public ToDoItem(String td, char pri, int sec) { + ToDoItem(String td, char pri, int sec) { primary = pri; secondary = sec; item = td; diff --git a/collectiontopics/TypesForSets.java b/collectiontopics/TypesForSets.java index cd672c9d..b7840f64 100644 --- a/collectiontopics/TypesForSets.java +++ b/collectiontopics/TypesForSets.java @@ -6,11 +6,10 @@ import java.util.*; import java.util.function.*; import java.util.Objects; -import onjava.CountMap; class SetType { protected int i; - public SetType(int n) { i = n; } + SetType(int n) { i = n; } @Override public boolean equals(Object o) { return o instanceof SetType && @@ -23,7 +22,7 @@ class SetType { } class HashType extends SetType { - public HashType(int n) { super(n); } + HashType(int n) { super(n); } @Override public int hashCode() { return Objects.hashCode(i); @@ -32,7 +31,7 @@ class HashType extends SetType { class TreeType extends SetType implements Comparable { - public TreeType(int n) { super(n); } + TreeType(int n) { super(n); } @Override public int compareTo(TreeType arg) { return Integer.compare(arg.i, i); diff --git a/concurrent/CatchCompletableExceptions.java b/concurrent/CatchCompletableExceptions.java index f0e39d89..3f4036be 100644 --- a/concurrent/CatchCompletableExceptions.java +++ b/concurrent/CatchCompletableExceptions.java @@ -3,7 +3,6 @@ // We make no guarantees that this code is fit for any purpose. // Visit http://OnJava8.com for more book information. import java.util.concurrent.*; -import onjava.Nap; public class CatchCompletableExceptions { static void handleException(int failcount) { diff --git a/concurrent/CompletableExceptions.java b/concurrent/CompletableExceptions.java index b035c5cf..e7bac94b 100644 --- a/concurrent/CompletableExceptions.java +++ b/concurrent/CompletableExceptions.java @@ -3,7 +3,6 @@ // We make no guarantees that this code is fit for any purpose. // Visit http://OnJava8.com for more book information. import java.util.concurrent.*; -import onjava.Nap; public class CompletableExceptions { static CompletableFuture diff --git a/concurrent/CompletablePizza.java b/concurrent/CompletablePizza.java index 6072e81a..fb800abe 100644 --- a/concurrent/CompletablePizza.java +++ b/concurrent/CompletablePizza.java @@ -8,7 +8,7 @@ import java.util.stream.*; import onjava.Timer; public class CompletablePizza { - static int QUANTITY = 5; + static final int QUANTITY = 5; public static CompletableFuture makeCF(Pizza za) { return CompletableFuture diff --git a/concurrent/FrostedCake.java b/concurrent/FrostedCake.java index 0203e722..0d5a84b4 100644 --- a/concurrent/FrostedCake.java +++ b/concurrent/FrostedCake.java @@ -6,7 +6,7 @@ import java.util.concurrent.*; import java.util.stream.*; import onjava.Nap; -class Frosting { +final class Frosting { private Frosting() {} static CompletableFuture make() { new Nap(0.1); diff --git a/concurrent/IDChecker.java b/concurrent/IDChecker.java index e4f7cac5..f21a63d3 100644 --- a/concurrent/IDChecker.java +++ b/concurrent/IDChecker.java @@ -9,11 +9,11 @@ import java.util.concurrent.*; import com.google.common.collect.Sets; public class IDChecker { - public static int SIZE = 100_000; + public static final int SIZE = 100_000; static class MakeObjects implements Supplier> { private Supplier gen; - public MakeObjects(Supplier gen) { + MakeObjects(Supplier gen) { this.gen = gen; } @Override diff --git a/concurrent/PizzaParallelSteps.java b/concurrent/PizzaParallelSteps.java index 32e53360..26f5e9a8 100644 --- a/concurrent/PizzaParallelSteps.java +++ b/concurrent/PizzaParallelSteps.java @@ -7,7 +7,7 @@ import java.util.stream.*; import onjava.Timer; public class PizzaParallelSteps { - static int QUANTITY = 5; + static final int QUANTITY = 5; public static void main(String[] args) { Timer timer = new Timer(); IntStream.range(0, QUANTITY) diff --git a/concurrent/PizzaStreams.java b/concurrent/PizzaStreams.java index d16fc13f..58f81d6f 100644 --- a/concurrent/PizzaStreams.java +++ b/concurrent/PizzaStreams.java @@ -7,7 +7,7 @@ import java.util.stream.*; import onjava.Timer; public class PizzaStreams { - static int QUANTITY = 5; + static final int QUANTITY = 5; public static void main(String[] args) { Timer timer = new Timer(); IntStream.range(0, QUANTITY) diff --git a/concurrent/SharedConstructorArgument.java b/concurrent/SharedConstructorArgument.java index b49f857a..0d987088 100644 --- a/concurrent/SharedConstructorArgument.java +++ b/concurrent/SharedConstructorArgument.java @@ -23,7 +23,7 @@ class Safe implements SharedArg { class SharedUser implements HasID { private final int id; - public SharedUser(SharedArg sa) { + SharedUser(SharedArg sa) { id = sa.get(); } @Override diff --git a/concurrent/StreamExceptions.java b/concurrent/StreamExceptions.java index 372e53fc..facae761 100644 --- a/concurrent/StreamExceptions.java +++ b/concurrent/StreamExceptions.java @@ -4,7 +4,6 @@ // Visit http://OnJava8.com for more book information. import java.util.concurrent.*; import java.util.stream.*; -import onjava.Nap; public class StreamExceptions { static Stream diff --git a/concurrent/SynchronizedConstructor.java b/concurrent/SynchronizedConstructor.java index 0533f8bb..520829ee 100644 --- a/concurrent/SynchronizedConstructor.java +++ b/concurrent/SynchronizedConstructor.java @@ -8,7 +8,7 @@ class SyncConstructor implements HasID { private final int id; private static Object constructorLock = new Object(); - public SyncConstructor(SharedArg sa) { + SyncConstructor(SharedArg sa) { synchronized(constructorLock) { id = sa.get(); } diff --git a/concurrent/SynchronizedFactory.java b/concurrent/SynchronizedFactory.java index d16d3a3e..4f682082 100644 --- a/concurrent/SynchronizedFactory.java +++ b/concurrent/SynchronizedFactory.java @@ -4,7 +4,7 @@ // Visit http://OnJava8.com for more book information. import java.util.concurrent.atomic.*; -class SyncFactory implements HasID { +final class SyncFactory implements HasID { private final int id; private SyncFactory(SharedArg sa) { id = sa.get(); diff --git a/enums/VendingMachine.java b/enums/VendingMachine.java index d5d7bf4d..d1027e22 100644 --- a/enums/VendingMachine.java +++ b/enums/VendingMachine.java @@ -133,7 +133,7 @@ class RandomInputSupplier implements Supplier { // Create Inputs from a file of ';'-separated strings: class FileInputSupplier implements Supplier { private Iterator input; - public FileInputSupplier(String fileName) { + FileInputSupplier(String fileName) { try { input = Files.lines(Paths.get(fileName)) .skip(1) // Skip the comment line diff --git a/equalshashcode/ComposedEquality.java b/equalshashcode/ComposedEquality.java index b9931a66..f9faf933 100644 --- a/equalshashcode/ComposedEquality.java +++ b/equalshashcode/ComposedEquality.java @@ -7,7 +7,7 @@ import java.util.*; class Part { String ss; double dd; - public Part(String ss, double dd) { + Part(String ss, double dd) { this.ss = ss; this.dd = dd; } diff --git a/equalshashcode/DefaultComparison.java b/equalshashcode/DefaultComparison.java index a702d4da..541e918e 100644 --- a/equalshashcode/DefaultComparison.java +++ b/equalshashcode/DefaultComparison.java @@ -5,7 +5,7 @@ class DefaultComparison { private int i, j, k; - public DefaultComparison(int i, int j, int k) { + DefaultComparison(int i, int j, int k) { this.i = i; this.j = j; this.k = k; diff --git a/equalshashcode/SubtypeEquality.java b/equalshashcode/SubtypeEquality.java index 50cf361b..4dc1d060 100644 --- a/equalshashcode/SubtypeEquality.java +++ b/equalshashcode/SubtypeEquality.java @@ -11,7 +11,7 @@ class Animal { private final int id = counter++; private final String name; private final Size size; - public Animal(String name, Size size) { + Animal(String name, Size size) { this.name = name; this.size = size; } @@ -36,13 +36,13 @@ class Animal { } class Dog extends Animal { - public Dog(String name, Size size) { + Dog(String name, Size size) { super(name, size); } } class Pig extends Animal { - public Pig(String name, Size size) { + Pig(String name, Size size) { super(name, size); } } diff --git a/equalshashcode/SubtypeEquality2.java b/equalshashcode/SubtypeEquality2.java index 990ddf76..88174929 100644 --- a/equalshashcode/SubtypeEquality2.java +++ b/equalshashcode/SubtypeEquality2.java @@ -5,7 +5,7 @@ import java.util.*; class Dog2 extends Animal { - public Dog2(String name, Size size) { + Dog2(String name, Size size) { super(name, size); } @Override @@ -16,7 +16,7 @@ class Dog2 extends Animal { } class Pig2 extends Animal { - public Pig2(String name, Size size) { + Pig2(String name, Size size) { super(name, size); } @Override diff --git a/exceptions/AutoCloseableDetails.java b/exceptions/AutoCloseableDetails.java index 23f8a172..e6f8f77d 100644 --- a/exceptions/AutoCloseableDetails.java +++ b/exceptions/AutoCloseableDetails.java @@ -5,7 +5,7 @@ class Reporter implements AutoCloseable { String name = getClass().getSimpleName(); - public Reporter() { + Reporter() { System.out.println("Creating " + name); } public void close() { diff --git a/exceptions/CleanupIdiom.java b/exceptions/CleanupIdiom.java index 48ce0d45..e4727258 100644 --- a/exceptions/CleanupIdiom.java +++ b/exceptions/CleanupIdiom.java @@ -17,7 +17,7 @@ class ConstructionException extends Exception {} class NeedsCleanup2 extends NeedsCleanup { // Construction can fail: - public NeedsCleanup2() throws ConstructionException {} + NeedsCleanup2() throws ConstructionException {} } public class CleanupIdiom { diff --git a/exceptions/CloseExceptions.java b/exceptions/CloseExceptions.java index 9ad598b4..6a1a51b0 100644 --- a/exceptions/CloseExceptions.java +++ b/exceptions/CloseExceptions.java @@ -7,7 +7,7 @@ class CloseException extends Exception {} class Reporter2 implements AutoCloseable { String name = getClass().getSimpleName(); - public Reporter2() { + Reporter2() { System.out.println("Creating " + name); } public void close() throws CloseException { diff --git a/exceptions/ConstructorException.java b/exceptions/ConstructorException.java index d3342b38..3c48ecf7 100644 --- a/exceptions/ConstructorException.java +++ b/exceptions/ConstructorException.java @@ -6,7 +6,7 @@ class CE extends Exception {} class SecondExcept extends Reporter { - public SecondExcept() throws CE { + SecondExcept() throws CE { super(); throw new CE(); } diff --git a/exceptions/ExtraFeatures.java b/exceptions/ExtraFeatures.java index b45c27e3..6cf69f42 100644 --- a/exceptions/ExtraFeatures.java +++ b/exceptions/ExtraFeatures.java @@ -6,9 +6,9 @@ class MyException2 extends Exception { private int x; - public MyException2() {} - public MyException2(String msg) { super(msg); } - public MyException2(String msg, int x) { + MyException2() {} + MyException2(String msg) { super(msg); } + MyException2(String msg, int x) { super(msg); this.x = x; } diff --git a/exceptions/FullConstructors.java b/exceptions/FullConstructors.java index 1851d2d6..80c04657 100644 --- a/exceptions/FullConstructors.java +++ b/exceptions/FullConstructors.java @@ -4,8 +4,8 @@ // Visit http://OnJava8.com for more book information. class MyException extends Exception { - public MyException() {} - public MyException(String msg) { super(msg); } + MyException() {} + MyException(String msg) { super(msg); } } public class FullConstructors { diff --git a/exceptions/LoggingExceptions.java b/exceptions/LoggingExceptions.java index ebdd809d..c28510f8 100644 --- a/exceptions/LoggingExceptions.java +++ b/exceptions/LoggingExceptions.java @@ -10,7 +10,7 @@ import java.io.*; class LoggingException extends Exception { private static Logger logger = Logger.getLogger("LoggingException"); - public LoggingException() { + LoggingException() { StringWriter trace = new StringWriter(); printStackTrace(new PrintWriter(trace)); logger.severe(trace.toString()); diff --git a/exceptions/RethrowNew.java b/exceptions/RethrowNew.java index cc2601b0..e03f7509 100644 --- a/exceptions/RethrowNew.java +++ b/exceptions/RethrowNew.java @@ -5,11 +5,11 @@ // Rethrow a different object from the one you caught class OneException extends Exception { - public OneException(String s) { super(s); } + OneException(String s) { super(s); } } class TwoException extends Exception { - public TwoException(String s) { super(s); } + TwoException(String s) { super(s); } } public class RethrowNew { diff --git a/exceptions/StormyInning.java b/exceptions/StormyInning.java index 5b2b727c..1656d062 100644 --- a/exceptions/StormyInning.java +++ b/exceptions/StormyInning.java @@ -11,7 +11,7 @@ class Foul extends BaseballException {} class Strike extends BaseballException {} abstract class Inning { - public Inning() throws BaseballException {} + Inning() throws BaseballException {} public void event() throws BaseballException { // Doesn't actually have to throw anything } diff --git a/functional/FunctionVariants.java b/functional/FunctionVariants.java index 976f7f28..d09476ca 100644 --- a/functional/FunctionVariants.java +++ b/functional/FunctionVariants.java @@ -8,26 +8,26 @@ class Foo {} class Bar { Foo f; - public Bar(Foo f) { this.f = f; } + Bar(Foo f) { this.f = f; } } class IBaz { int i; - public IBaz(int i) { + IBaz(int i) { this.i = i; } } class LBaz { long l; - public LBaz(long l) { + LBaz(long l) { this.l = l; } } class DBaz { double d; - public DBaz(double d) { + DBaz(double d) { this.d = d; } } diff --git a/functional/MethodReferences.java b/functional/MethodReferences.java index 85a4f0b9..dde6ba0e 100644 --- a/functional/MethodReferences.java +++ b/functional/MethodReferences.java @@ -20,7 +20,7 @@ public class MethodReferences { } static class Description { String about; - public Description(String desc) { about = desc; } + Description(String desc) { about = desc; } void help(String msg) { // [4] System.out.println(about + " " + msg); } diff --git a/generics/DynamicProxyMixin.java b/generics/DynamicProxyMixin.java index 337ab3e8..75e162b9 100644 --- a/generics/DynamicProxyMixin.java +++ b/generics/DynamicProxyMixin.java @@ -10,7 +10,7 @@ import static onjava.Tuple.*; class MixinProxy implements InvocationHandler { Map delegatesByMethod; @SuppressWarnings("unchecked") - public MixinProxy(Tuple2>... pairs) { + MixinProxy(Tuple2>... pairs) { delegatesByMethod = new HashMap<>(); for(Tuple2> pair : pairs) { for(Method method : pair.a2.getMethods()) { diff --git a/generics/FactoryConstraint.java b/generics/FactoryConstraint.java index 36957a86..734eabec 100644 --- a/generics/FactoryConstraint.java +++ b/generics/FactoryConstraint.java @@ -16,7 +16,7 @@ class IntegerFactory implements Supplier { class Widget { private int id; - public Widget(int n) { id = n; } + Widget(int n) { id = n; } @Override public String toString() { return "Widget " + id; @@ -38,7 +38,7 @@ class Fudge { class Foo2 { private List x = new ArrayList<>(); - public Foo2(Supplier factory) { + Foo2(Supplier factory) { Suppliers.fill(x, factory, 5); } @Override diff --git a/generics/FilledList.java b/generics/FilledList.java index b9e1cb28..064715f0 100644 --- a/generics/FilledList.java +++ b/generics/FilledList.java @@ -6,8 +6,8 @@ import java.util.*; import java.util.function.*; import onjava.*; -class FilledList extends ArrayList { - public FilledList(Supplier gen, int size) { +public class FilledList extends ArrayList { + FilledList(Supplier gen, int size) { Suppliers.fill(this, gen, size); } public FilledList(T t, int size) { diff --git a/generics/GenericCast.java b/generics/GenericCast.java index 9c1ca282..ddf5deae 100644 --- a/generics/GenericCast.java +++ b/generics/GenericCast.java @@ -9,7 +9,7 @@ class FixedSizeStack { private final int size; private Object[] storage; private int index = 0; - public FixedSizeStack(int size) { + FixedSizeStack(int size) { this.size = size; storage = new Object[size]; } diff --git a/generics/InstantiateGenericType.java b/generics/InstantiateGenericType.java index 627e17bc..4c46b04b 100644 --- a/generics/InstantiateGenericType.java +++ b/generics/InstantiateGenericType.java @@ -6,7 +6,7 @@ import java.util.function.*; class ClassAsFactory implements Supplier { Class kind; - public ClassAsFactory(Class kind) { + ClassAsFactory(Class kind) { this.kind = kind; } @Override diff --git a/generics/Manipulation.java b/generics/Manipulation.java index 855bb301..ff9cb384 100644 --- a/generics/Manipulation.java +++ b/generics/Manipulation.java @@ -6,7 +6,7 @@ class Manipulator { private T obj; - public Manipulator(T x) { obj = x; } + Manipulator(T x) { obj = x; } // Error: cannot find symbol: method f(): public void manipulate() { obj.f(); } } diff --git a/generics/Manipulator2.java b/generics/Manipulator2.java index c705b84e..7d044ef8 100644 --- a/generics/Manipulator2.java +++ b/generics/Manipulator2.java @@ -5,6 +5,6 @@ class Manipulator2 { private T obj; - public Manipulator2(T x) { obj = x; } + Manipulator2(T x) { obj = x; } public void manipulate() { obj.f(); } } diff --git a/generics/Manipulator3.java b/generics/Manipulator3.java index e2a9878e..7b7b833f 100644 --- a/generics/Manipulator3.java +++ b/generics/Manipulator3.java @@ -5,6 +5,6 @@ class Manipulator3 { private HasF obj; - public Manipulator3(HasF x) { obj = x; } + Manipulator3(HasF x) { obj = x; } public void manipulate() { obj.f(); } } diff --git a/generics/Mixins.java b/generics/Mixins.java index a5216675..e272f1c0 100644 --- a/generics/Mixins.java +++ b/generics/Mixins.java @@ -8,7 +8,7 @@ interface TimeStamped { long getStamp(); } class TimeStampedImp implements TimeStamped { private final long timeStamp; - public TimeStampedImp() { + TimeStampedImp() { timeStamp = new Date().getTime(); } @Override diff --git a/generics/ReturnGenericType.java b/generics/ReturnGenericType.java index 4f66b7e7..3d159679 100644 --- a/generics/ReturnGenericType.java +++ b/generics/ReturnGenericType.java @@ -5,6 +5,6 @@ class ReturnGenericType { private T obj; - public ReturnGenericType(T x) { obj = x; } + ReturnGenericType(T x) { obj = x; } public T get() { return obj; } } diff --git a/generics/Store.java b/generics/Store.java index 3ce69729..3460bc15 100644 --- a/generics/Store.java +++ b/generics/Store.java @@ -11,7 +11,6 @@ class Product { private final int id; private String description; private double price; - public Product(int idNumber, String descr, double price) { id = idNumber; description = descr; @@ -37,13 +36,13 @@ class Product { } class Shelf extends ArrayList { - public Shelf(int nProducts) { + Shelf(int nProducts) { Suppliers.fill(this, Product.generator, nProducts); } } class Aisle extends ArrayList { - public Aisle(int nShelves, int nProducts) { + Aisle(int nShelves, int nProducts) { for(int i = 0; i < nShelves; i++) add(new Shelf(nProducts)); } diff --git a/generics/decorator/Decoration.java b/generics/decorator/Decoration.java index 7693c8aa..d7f96325 100644 --- a/generics/decorator/Decoration.java +++ b/generics/decorator/Decoration.java @@ -14,7 +14,7 @@ class Basic { class Decorator extends Basic { protected Basic basic; - public Decorator(Basic basic) { this.basic = basic; } + Decorator(Basic basic) { this.basic = basic; } @Override public void set(String val) { basic.set(val); } @Override @@ -23,7 +23,7 @@ class Decorator extends Basic { class TimeStamped extends Decorator { private final long timeStamp; - public TimeStamped(Basic basic) { + TimeStamped(Basic basic) { super(basic); timeStamp = new Date().getTime(); } @@ -33,7 +33,7 @@ class TimeStamped extends Decorator { class SerialNumbered extends Decorator { private static long counter = 1; private final long serialNumber = counter++; - public SerialNumbered(Basic basic) { super(basic); } + SerialNumbered(Basic basic) { super(basic); } public long getSerialNumber() { return serialNumber; } } diff --git a/innerclasses/AnonymousConstructor.java b/innerclasses/AnonymousConstructor.java index 25de92a5..7395a335 100644 --- a/innerclasses/AnonymousConstructor.java +++ b/innerclasses/AnonymousConstructor.java @@ -5,7 +5,7 @@ // Creating a constructor for an anonymous inner class abstract class Base { - public Base(int i) { + Base(int i) { System.out.println("Base constructor, i = " + i); } public abstract void f(); diff --git a/innerclasses/BigEgg.java b/innerclasses/BigEgg.java index a510ddda..c1572c59 100644 --- a/innerclasses/BigEgg.java +++ b/innerclasses/BigEgg.java @@ -11,7 +11,7 @@ class Egg { System.out.println("Egg.Yolk()"); } } - public Egg() { + Egg() { System.out.println("New Egg()"); y = new Yolk(); } diff --git a/innerclasses/BigEgg2.java b/innerclasses/BigEgg2.java index 6f8cf4aa..0eb0abce 100644 --- a/innerclasses/BigEgg2.java +++ b/innerclasses/BigEgg2.java @@ -14,7 +14,7 @@ class Egg2 { } } 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 g() { y.f(); } } diff --git a/innerclasses/LocalInnerClass.java b/innerclasses/LocalInnerClass.java index 119c1ca9..533a25d0 100644 --- a/innerclasses/LocalInnerClass.java +++ b/innerclasses/LocalInnerClass.java @@ -13,7 +13,7 @@ public class LocalInnerClass { Counter getCounter(final String name) { // A local inner class: class LocalCounter implements Counter { - public LocalCounter() { + LocalCounter() { // Local inner class can have a constructor System.out.println("LocalCounter()"); } diff --git a/interfaces/Applicator.java b/interfaces/Applicator.java index 33edd1cf..c7ad4da0 100644 --- a/interfaces/Applicator.java +++ b/interfaces/Applicator.java @@ -40,9 +40,8 @@ public class Applicator { System.out.println("Using Processor " + p.name()); System.out.println(p.process(s)); } - public static final String s = - "Disagreement with beliefs is by definition incorrect"; public static void main(String[] args) { + String s = "We are such stuff as dreams are made on"; apply(new Upcase(), s); apply(new Downcase(), s); apply(new Splitter(), s); @@ -50,10 +49,9 @@ public class Applicator { } /* Output: Using Processor Upcase -DISAGREEMENT WITH BELIEFS IS BY DEFINITION INCORRECT +WE ARE SUCH STUFF AS DREAMS ARE MADE ON Using Processor Downcase -disagreement with beliefs is by definition incorrect +we are such stuff as dreams are made on Using Processor Splitter -[Disagreement, with, beliefs, is, by, definition, -incorrect] +[We, are, such, stuff, as, dreams, are, made, on] */ diff --git a/interfaces/interfaceprocessor/FilterProcessor.java b/interfaces/interfaceprocessor/FilterProcessor.java index 95f977a0..45b2ef75 100644 --- a/interfaces/interfaceprocessor/FilterProcessor.java +++ b/interfaces/interfaceprocessor/FilterProcessor.java @@ -8,7 +8,7 @@ import interfaces.filters.*; class FilterAdapter implements Processor { Filter filter; - public FilterAdapter(Filter filter) { + FilterAdapter(Filter filter) { this.filter = filter; } @Override diff --git a/lowlevel/DelayQueueDemo.java b/lowlevel/DelayQueueDemo.java index d845bf36..c805d738 100644 --- a/lowlevel/DelayQueueDemo.java +++ b/lowlevel/DelayQueueDemo.java @@ -14,7 +14,7 @@ class DelayedTask implements Runnable, Delayed { private final long trigger; protected static List sequence = new ArrayList<>(); - public DelayedTask(int delayInMilliseconds) { + DelayedTask(int delayInMilliseconds) { delta = delayInMilliseconds; trigger = System.nanoTime() + NANOSECONDS.convert(delta, MILLISECONDS); @@ -45,7 +45,7 @@ class DelayedTask implements Runnable, Delayed { return String.format("(%d:%d)", id, delta); } public static class EndTask extends DelayedTask { - public EndTask(int delay) { super(delay); } + EndTask(int delay) { super(delay); } @Override public void run() { sequence.forEach(dt -> diff --git a/lowlevel/PriorityBlockingQueueDemo.java b/lowlevel/PriorityBlockingQueueDemo.java index 93664a66..c006981b 100644 --- a/lowlevel/PriorityBlockingQueueDemo.java +++ b/lowlevel/PriorityBlockingQueueDemo.java @@ -15,7 +15,7 @@ class Prioritized implements Comparable { private final int priority; private static List sequence = new CopyOnWriteArrayList<>(); - public Prioritized(int priority) { + Prioritized(int priority) { this.priority = priority; sequence.add(this); } @@ -38,7 +38,7 @@ class Prioritized implements Comparable { } } public static class EndSentinel extends Prioritized { - public EndSentinel() { super(-1); } + EndSentinel() { super(-1); } } } @@ -48,7 +48,7 @@ class Producer implements Runnable { private SplittableRandom rand = new SplittableRandom(seed.getAndAdd(10)); private Queue queue; - public Producer(Queue q) { + Producer(Queue q) { queue = q; } @Override @@ -65,7 +65,6 @@ class Consumer implements Runnable { private PriorityBlockingQueue q; private SplittableRandom rand = new SplittableRandom(47); - public Consumer(PriorityBlockingQueue q) { this.q = q; } diff --git a/lowlevel/SafeReturn.java b/lowlevel/SafeReturn.java index 19e82ca7..829a1f98 100644 --- a/lowlevel/SafeReturn.java +++ b/lowlevel/SafeReturn.java @@ -4,7 +4,6 @@ // Visit http://OnJava8.com for more book information. import java.util.function.*; import java.util.concurrent.*; -import onjava.TimedAbort; public class SafeReturn extends IntTestable { private int i = 0; diff --git a/lowlevel/SynchronizedComparison.java b/lowlevel/SynchronizedComparison.java index a76a62b5..f497e518 100644 --- a/lowlevel/SynchronizedComparison.java +++ b/lowlevel/SynchronizedComparison.java @@ -38,7 +38,7 @@ class CriticalSection extends Guarded { class Caller implements Runnable { private Guarded g; - public Caller(Guarded g) { this.g = g; } + Caller(Guarded g) { this.g = g; } private AtomicLong successfulCalls = new AtomicLong(); private AtomicBoolean stop = diff --git a/lowlevel/UnsafeReturn.java b/lowlevel/UnsafeReturn.java index 42a76357..e8e9df3c 100644 --- a/lowlevel/UnsafeReturn.java +++ b/lowlevel/UnsafeReturn.java @@ -4,7 +4,6 @@ // Visit http://OnJava8.com for more book information. import java.util.function.*; import java.util.concurrent.*; -import onjava.TimedAbort; public class UnsafeReturn extends IntTestable { private int i = 0; diff --git a/newio/MappedIO.java b/newio/MappedIO.java index 367f56b5..6b146a21 100644 --- a/newio/MappedIO.java +++ b/newio/MappedIO.java @@ -12,7 +12,7 @@ public class MappedIO { private static int numOfUbuffInts = 100_000; private abstract static class Tester { private String name; - public Tester(String name) { + Tester(String name) { this.name = name; } public void runTest() { diff --git a/onjava/Count.java b/onjava/Count.java index f8c32649..1e2f90b5 100644 --- a/onjava/Count.java +++ b/onjava/Count.java @@ -9,7 +9,7 @@ import java.util.function.*; import static onjava.ConvertTo.*; public interface Count { - public static class Boolean + class Boolean implements Supplier { private boolean b = true; @Override @@ -27,7 +27,7 @@ public interface Count { return result; } } - public static class Pboolean { + class Pboolean { private boolean b = true; public boolean get() { b = !b; @@ -38,7 +38,7 @@ public interface Count { return primitive(new Boolean().array(sz)); } } - public static class Byte + class Byte implements Supplier { private byte b; @Override @@ -53,7 +53,7 @@ public interface Count { return result; } } - public static class Pbyte { + class Pbyte { private byte b; public byte get() { return b++; } public byte get(int n) { return get(); } @@ -63,7 +63,7 @@ public interface Count { } char[] CHARS = "abcdefghijklmnopqrstuvwxyz".toCharArray(); - public static class Character + class Character implements Supplier { private int i; @Override @@ -81,7 +81,7 @@ public interface Count { return result; } } - public static class Pchar { + class Pchar { private int i; public char get() { i = (i + 1) % CHARS.length; @@ -92,7 +92,7 @@ public interface Count { return primitive(new Character().array(sz)); } } - public static class Short + class Short implements Supplier { short s; @Override @@ -107,7 +107,7 @@ public interface Count { return result; } } - public static class Pshort { + class Pshort { short s; public short get() { return s++; } public short get(int n) { return get(); } @@ -115,7 +115,7 @@ public interface Count { return primitive(new Short().array(sz)); } } - public static class Integer + class Integer implements Supplier { int i; @Override @@ -130,7 +130,7 @@ public interface Count { return result; } } - public static class Pint implements IntSupplier { + class Pint implements IntSupplier { int i; public int get() { return i++; } public int get(int n) { return get(); } @@ -140,7 +140,7 @@ public interface Count { return primitive(new Integer().array(sz)); } } - public static class Long + class Long implements Supplier { private long l; @Override @@ -155,7 +155,6 @@ public interface Count { return result; } } - public static class Plong implements LongSupplier { private long l; public long get() { return l++; } @@ -166,7 +165,7 @@ public interface Count { return primitive(new Long().array(sz)); } } - public class Float + class Float implements Supplier { private int i; @Override @@ -183,7 +182,7 @@ public interface Count { return result; } } - public class Pfloat { + class Pfloat { private int i; public float get() { return i++; } public float get(int n) { return get(); } @@ -191,7 +190,7 @@ public interface Count { return primitive(new Float().array(sz)); } } - public class Double + class Double implements Supplier { private int i; @Override @@ -208,7 +207,7 @@ public interface Count { return result; } } - public class Pdouble implements DoubleSupplier { + class Pdouble implements DoubleSupplier { private int i; public double get() { return i++; } public double get(int n) { return get(); } diff --git a/onjava/CountMap.java b/onjava/CountMap.java index 71fe527c..c3208e71 100644 --- a/onjava/CountMap.java +++ b/onjava/CountMap.java @@ -58,15 +58,15 @@ extends AbstractMap { .toCollection(LinkedHashSet::new)); } public static void main(String[] args) { - final int LIM = 6; + final int size = 6; CountMap cm = new CountMap(60); System.out.println(cm); System.out.println(cm.get(500)); cm.values().stream() - .limit(LIM) + .limit(size) .forEach(System.out::println); System.out.println(); - new Random(47).ints(LIM, 0, 1000) + new Random(47).ints(size, 0, 1000) .mapToObj(cm::get) .forEach(System.out::println); } diff --git a/onjava/Rand.java b/onjava/Rand.java index 79d42ce6..019bac40 100644 --- a/onjava/Rand.java +++ b/onjava/Rand.java @@ -10,7 +10,7 @@ import static onjava.ConvertTo.*; public interface Rand { int MOD = 10_000; - public static class Boolean + class Boolean implements Supplier { SplittableRandom r = new SplittableRandom(47); @Override @@ -27,12 +27,12 @@ public interface Rand { return result; } } - public static class Pboolean { + class Pboolean { public boolean[] array(int sz) { return primitive(new Boolean().array(sz)); } } - public static class Byte + class Byte implements Supplier { SplittableRandom r = new SplittableRandom(47); @Override @@ -49,12 +49,12 @@ public interface Rand { return result; } } - public static class Pbyte { + class Pbyte { public byte[] array(int sz) { return primitive(new Byte().array(sz)); } } - public static class Character + class Character implements Supplier { SplittableRandom r = new SplittableRandom(47); @Override @@ -71,12 +71,12 @@ public interface Rand { return result; } } - public static class Pchar { + class Pchar { public char[] array(int sz) { return primitive(new Character().array(sz)); } } - public static class Short + class Short implements Supplier { SplittableRandom r = new SplittableRandom(47); @Override @@ -93,12 +93,12 @@ public interface Rand { return result; } } - public static class Pshort { + class Pshort { public short[] array(int sz) { return primitive(new Short().array(sz)); } } - public static class Integer + class Integer implements Supplier { SplittableRandom r = new SplittableRandom(47); @Override @@ -117,7 +117,7 @@ public interface Rand { return result; } } - public static class Pint implements IntSupplier { + class Pint implements IntSupplier { SplittableRandom r = new SplittableRandom(47); @Override public int getAsInt() { @@ -128,7 +128,7 @@ public interface Rand { return r.ints(sz, 0, MOD).toArray(); } } - public static class Long + class Long implements Supplier { SplittableRandom r = new SplittableRandom(47); @Override @@ -147,7 +147,6 @@ public interface Rand { return result; } } - public static class Plong implements LongSupplier { SplittableRandom r = new SplittableRandom(47); @Override @@ -159,7 +158,7 @@ public interface Rand { return r.longs(sz, 0, MOD).toArray(); } } - public static class Float + class Float implements Supplier { SplittableRandom r = new SplittableRandom(47); @Override @@ -176,7 +175,7 @@ public interface Rand { return result; } } - public static class Pfloat { + class Pfloat { public float[] array(int sz) { return primitive(new Float().array(sz)); } @@ -185,7 +184,7 @@ public interface Rand { return ((double)Math.round(d * 1000.0)) / 100.0; } - public static class Double + class Double implements Supplier { SplittableRandom r = new SplittableRandom(47); @Override @@ -205,7 +204,6 @@ public interface Rand { return result; } } - public static class Pdouble implements DoubleSupplier { SplittableRandom r = new SplittableRandom(47); @Override @@ -222,7 +220,7 @@ public interface Rand { return result; } } - public static class String + class String implements Supplier { SplittableRandom r = new SplittableRandom(47); private int strlen = 7; // Default length diff --git a/patterns/Facade.java b/patterns/Facade.java index 4a042d17..005acf13 100644 --- a/patterns/Facade.java +++ b/patterns/Facade.java @@ -3,9 +3,9 @@ // We make no guarantees that this code is fit for any purpose. // Visit http://OnJava8.com for more book information. -class A { public A(int x) {} } -class B { public B(long x) {} } -class C { public C(double x) {} } +class A { A(int x) {} } +class B { B(long x) {} } +class C { C(double x) {} } // Other classes that aren't exposed by the // facade go here ... diff --git a/patterns/ProxyDemo.java b/patterns/ProxyDemo.java index d673a3e6..198117ad 100644 --- a/patterns/ProxyDemo.java +++ b/patterns/ProxyDemo.java @@ -12,7 +12,7 @@ interface ProxyBase { class Proxy implements ProxyBase { private ProxyBase implementation; - public Proxy() { + Proxy() { implementation = new Implementation(); } // Pass method calls to the implementation: diff --git a/patterns/ShapeFactory3.java b/patterns/ShapeFactory3.java index c9c8a79a..123d27fa 100644 --- a/patterns/ShapeFactory3.java +++ b/patterns/ShapeFactory3.java @@ -15,7 +15,6 @@ interface PolymorphicFactory { class RandomShapes implements Supplier { private final PolymorphicFactory[] factories; private Random rand = new Random(42); - public RandomShapes(PolymorphicFactory... factories) { this.factories = factories; } diff --git a/patterns/SingletonPattern.java b/patterns/SingletonPattern.java index 83163982..f2e46e30 100644 --- a/patterns/SingletonPattern.java +++ b/patterns/SingletonPattern.java @@ -15,7 +15,7 @@ interface Resource { // implements thread-safe lazy initialization: final class Singleton { - private static class + private static final class ResourceImpl implements Resource { private int i; private ResourceImpl(int i) { diff --git a/patterns/StateDemo.java b/patterns/StateDemo.java index 976c8dbc..041b4b98 100644 --- a/patterns/StateDemo.java +++ b/patterns/StateDemo.java @@ -13,7 +13,7 @@ interface StateBase { class State implements StateBase { private StateBase implementation; - public State(StateBase imp) { + State(StateBase imp) { implementation = imp; } @Override diff --git a/patterns/TemplateMethod.java b/patterns/TemplateMethod.java index ef255916..0efbd71c 100644 --- a/patterns/TemplateMethod.java +++ b/patterns/TemplateMethod.java @@ -6,7 +6,7 @@ import java.util.stream.*; abstract class ApplicationFramework { - public ApplicationFramework() { + ApplicationFramework() { templateMethod(); } abstract void customize1(); diff --git a/patterns/adapt/Adapter.java b/patterns/adapt/Adapter.java index 609ba862..956740e5 100644 --- a/patterns/adapt/Adapter.java +++ b/patterns/adapt/Adapter.java @@ -17,7 +17,7 @@ interface WhatIWant { class ProxyAdapter implements WhatIWant { WhatIHave whatIHave; - public ProxyAdapter(WhatIHave wih) { + ProxyAdapter(WhatIHave wih) { whatIHave = wih; } @Override diff --git a/patterns/chain/ChainOfResponsibility.java b/patterns/chain/ChainOfResponsibility.java index 140b4dff..61fa8faa 100644 --- a/patterns/chain/ChainOfResponsibility.java +++ b/patterns/chain/ChainOfResponsibility.java @@ -11,11 +11,11 @@ import java.util.function.*; class Result { boolean success; List line; - public Result(List data) { + Result(List data) { success = true; line = data; } - public Result() { + Result() { success = false; line = Collections.emptyList(); } diff --git a/patterns/dynatrash/DynaTrash.java b/patterns/dynatrash/DynaTrash.java index a3c0328a..59b36640 100644 --- a/patterns/dynatrash/DynaTrash.java +++ b/patterns/dynatrash/DynaTrash.java @@ -33,7 +33,7 @@ class TypeMap { // from ParseTrash.fillBin(): class TypeMapAdapter implements Fillable { TypeMap map; - public TypeMapAdapter(TypeMap tm) { + TypeMapAdapter(TypeMap tm) { map = tm; } @Override diff --git a/patterns/observer/ObservedFlower.java b/patterns/observer/ObservedFlower.java index a36c0569..a15e8e35 100644 --- a/patterns/observer/ObservedFlower.java +++ b/patterns/observer/ObservedFlower.java @@ -11,7 +11,7 @@ class Flower { private boolean isOpen; private boolean alreadyOpen; private boolean alreadyClosed; - public Flower() { isOpen = false; } + Flower() { isOpen = false; } OpenNotifier opening = new OpenNotifier(); CloseNotifier closing = new CloseNotifier(); public void open() { // Opens its petals @@ -48,7 +48,7 @@ class Flower { class Bee { private String name; - public Bee(String nm) { name = nm; } + Bee(String nm) { name = nm; } // Observe openings: public Observer openObserver() { return (ob, a) -> System.out.println( @@ -63,7 +63,7 @@ class Bee { class Hummingbird { private String name; - public Hummingbird(String nm) { name = nm; } + Hummingbird(String nm) { name = nm; } public Observer openObserver() { return (ob, a) -> System.out.println( "Hummingbird " + name + diff --git a/patterns/state/StateMachineDemo.java b/patterns/state/StateMachineDemo.java index de84445c..3911fe01 100644 --- a/patterns/state/StateMachineDemo.java +++ b/patterns/state/StateMachineDemo.java @@ -54,7 +54,7 @@ class Washer extends StateMachine { new Wash(), new Spin(), new Rinse(), new Spin(), }; - public Washer() { runAll(); } + Washer() { runAll(); } @Override public boolean changeState() { if(i < states.length) { diff --git a/patterns/strategy/StrategyPattern.java b/patterns/strategy/StrategyPattern.java index d26e7801..fbc8daa4 100644 --- a/patterns/strategy/StrategyPattern.java +++ b/patterns/strategy/StrategyPattern.java @@ -35,7 +35,7 @@ class Bisection extends FindMinima { // The "Context" controls the strategy: class MinimaSolver { private FindMinima strategy; - public MinimaSolver(FindMinima strat) { + MinimaSolver(FindMinima strat) { strategy = strat; } List minima(List line) { diff --git a/polymorphism/ReferenceCounting.java b/polymorphism/ReferenceCounting.java index e594f79f..a175fcad 100644 --- a/polymorphism/ReferenceCounting.java +++ b/polymorphism/ReferenceCounting.java @@ -8,7 +8,7 @@ class Shared { private int refcount = 0; private static long counter = 0; private final long id = counter++; - public Shared() { + Shared() { System.out.println("Creating " + this); } public void addRef() { refcount++; } @@ -26,7 +26,7 @@ class Composing { private Shared shared; private static long counter = 0; private final long id = counter++; - public Composing(Shared shared) { + Composing(Shared shared) { System.out.println("Creating " + this); this.shared = shared; this.shared.addRef(); diff --git a/references/AddingClone.java b/references/AddingClone.java index d9972c95..d8b1106f 100644 --- a/references/AddingClone.java +++ b/references/AddingClone.java @@ -9,7 +9,7 @@ import java.util.stream.*; class Int2 implements Cloneable { private int i; - public Int2(int ii) { i = ii; } + Int2(int ii) { i = ii; } public void increment() { i++; } @Override public String toString() { @@ -28,7 +28,7 @@ class Int2 implements Cloneable { // Inheritance doesn't remove cloneability: class Int3 extends Int2 { private int j; // Automatically duplicated - public Int3(int i) { super(i); } + Int3(int i) { super(i); } } public class AddingClone { diff --git a/references/CloneArrayList.java b/references/CloneArrayList.java index 5135a373..13bc7795 100644 --- a/references/CloneArrayList.java +++ b/references/CloneArrayList.java @@ -9,7 +9,7 @@ import java.util.stream.*; class Int { private int i; - public Int(int ii) { i = ii; } + Int(int ii) { i = ii; } public void increment() { i++; } @Override public String toString() { diff --git a/references/CopyConstructor.java b/references/CopyConstructor.java index edaeefd2..6627cf42 100644 --- a/references/CopyConstructor.java +++ b/references/CopyConstructor.java @@ -14,13 +14,13 @@ class FruitQualities { private int smell; // etc. // No-arg constructor: - public FruitQualities() { + FruitQualities() { // Do something meaningful... } // Other constructors: // ... // Copy constructor: - public FruitQualities(FruitQualities f) { + FruitQualities(FruitQualities f) { weight = f.weight; color = f.color; firmness = f.firmness; @@ -32,15 +32,15 @@ class FruitQualities { class Seed { // Members... - public Seed() { /* No-arg constructor */ } - public Seed(Seed s) { /* Copy constructor */ } + Seed() { /* No-arg constructor */ } + Seed(Seed s) { /* Copy constructor */ } } class Fruit { private FruitQualities fq; private int seeds; private Seed[] s; - public Fruit(FruitQualities q, int seedCount) { + Fruit(FruitQualities q, int seedCount) { fq = q; seeds = seedCount; s = new Seed[seeds]; @@ -50,7 +50,7 @@ class Fruit { // Other constructors: // ... // Copy constructor: - public Fruit(Fruit f) { + Fruit(Fruit f) { fq = new FruitQualities(f.fq); seeds = f.seeds; s = new Seed[seeds]; @@ -70,10 +70,10 @@ class Fruit { } class Tomato extends Fruit { - public Tomato() { + Tomato() { super(new FruitQualities(), 100); } - public Tomato(Tomato t) { // Copy-constructor + Tomato(Tomato t) { // Copy-constructor super(t); // Upcast to base copy-constructor // Other copy-construction activities... } @@ -82,21 +82,21 @@ class Tomato extends Fruit { class ZebraQualities extends FruitQualities { private int stripedness; // No-arg constructor: - public ZebraQualities() { + ZebraQualities() { super(); // do something meaningful... } - public ZebraQualities(ZebraQualities z) { + ZebraQualities(ZebraQualities z) { super(z); stripedness = z.stripedness; } } class GreenZebra extends Tomato { - public GreenZebra() { + GreenZebra() { addQualities(new ZebraQualities()); } - public GreenZebra(GreenZebra g) { + GreenZebra(GreenZebra g) { super(g); // Calls Tomato(Tomato) // Restore the right qualities: addQualities(new ZebraQualities()); diff --git a/references/Immutable2.java b/references/Immutable2.java index 9275a537..8f35edaa 100644 --- a/references/Immutable2.java +++ b/references/Immutable2.java @@ -6,7 +6,7 @@ class Mutable { private int data; - public Mutable(int initVal) { + Mutable(int initVal) { data = initVal; } public Mutable add(int x) { diff --git a/references/LocalCopy.java b/references/LocalCopy.java index 60175c7c..d7462981 100644 --- a/references/LocalCopy.java +++ b/references/LocalCopy.java @@ -6,7 +6,7 @@ class Duplo implements Cloneable { private int n; - public Duplo(int n) { this.n = n; } + Duplo(int n) { this.n = n; } @Override public Duplo clone() { // [1] try { diff --git a/references/MutableInteger.java b/references/MutableInteger.java index 30c99e0c..7f6e47d2 100644 --- a/references/MutableInteger.java +++ b/references/MutableInteger.java @@ -8,7 +8,7 @@ import java.util.stream.*; class IntValue { private int n; - public IntValue(int x) { n = x; } + IntValue(int x) { n = x; } public int getValue() { return n; } public void setValue(int n) { this.n = n; } public void increment() { n++; } diff --git a/references/SimplerMutableInteger.java b/references/SimplerMutableInteger.java index e0f7d24c..c49ceb5e 100644 --- a/references/SimplerMutableInteger.java +++ b/references/SimplerMutableInteger.java @@ -8,7 +8,7 @@ import java.util.stream.*; class IntValue2 { public int n; - public IntValue2(int n) { this.n = n; } + IntValue2(int n) { this.n = n; } } public class SimplerMutableInteger { diff --git a/reuse/FinalData.java b/reuse/FinalData.java index 0ee781ff..b233c408 100644 --- a/reuse/FinalData.java +++ b/reuse/FinalData.java @@ -7,7 +7,7 @@ import java.util.*; class Value { int i; // Package access - public Value(int i) { this.i = i; } + Value(int i) { this.i = i; } } public class FinalData { diff --git a/reuse/Orc.java b/reuse/Orc.java index dc70d3cf..9974c685 100644 --- a/reuse/Orc.java +++ b/reuse/Orc.java @@ -7,7 +7,7 @@ class Villain { private String name; protected void set(String nm) { name = nm; } - public Villain(String name) { this.name = name; } + Villain(String name) { this.name = name; } @Override public String toString() { return "I'm a Villain and my name is " + name; diff --git a/serialization/AStoreCADState.java b/serialization/AStoreCADState.java index 7b66507f..46fca27b 100644 --- a/serialization/AStoreCADState.java +++ b/serialization/AStoreCADState.java @@ -15,7 +15,7 @@ abstract class Shape implements Serializable { private static int counter = 0; public abstract void setColor(Color newColor); public abstract Color getColor(); - public Shape(int xVal, int yVal, int dim) { + Shape(int xVal, int yVal, int dim) { xPos = xVal; yPos = yVal; dimension = dim; @@ -40,7 +40,7 @@ abstract class Shape implements Serializable { class Circle extends Shape { 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); } public void setColor(Color newColor) { @@ -51,7 +51,7 @@ class Circle extends Shape { class Square extends Shape { 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); } public void setColor(Color newColor) { @@ -70,7 +70,7 @@ class Line extends Shape { throws IOException, ClassNotFoundException { color = (Color)os.readObject(); } - public Line(int xVal, int yVal, int dim) { + Line(int xVal, int yVal, int dim) { super(xVal, yVal, dim); } public void setColor(Color newColor) { diff --git a/serialization/Blips.java b/serialization/Blips.java index 4a98f123..345752da 100644 --- a/serialization/Blips.java +++ b/serialization/Blips.java @@ -6,7 +6,7 @@ import java.io.*; class Blip1 implements Externalizable { - public Blip1() { + Blip1() { System.out.println("Blip1 Constructor"); } @Override diff --git a/serialization/Worm.java b/serialization/Worm.java index 6e5e9595..4ed3570e 100644 --- a/serialization/Worm.java +++ b/serialization/Worm.java @@ -8,7 +8,7 @@ import java.util.*; class Data implements Serializable { private int n; - public Data(int n) { this.n = n; } + Data(int n) { this.n = n; } @Override public String toString() { return Integer.toString(n); diff --git a/streams/MapCollector.java b/streams/MapCollector.java index 21bf5294..3d4c97bf 100644 --- a/streams/MapCollector.java +++ b/streams/MapCollector.java @@ -8,7 +8,7 @@ import java.util.stream.*; class Pair { public final Character c; public final Integer i; - public Pair(Character c, Integer i) { + Pair(Character c, Integer i) { this.c = c; this.i = i; } diff --git a/typeinfo/Person.java b/typeinfo/Person.java index 611dcfcd..9c6a9657 100644 --- a/typeinfo/Person.java +++ b/typeinfo/Person.java @@ -12,7 +12,6 @@ class Person { public final Optional address; // etc. public final boolean empty; - public Person(String first, String last, String address) { this.first = Optional.ofNullable(first); this.last = Optional.ofNullable(last); @@ -21,11 +20,11 @@ class Person { && !this.last.isPresent() && !this.address.isPresent(); } - public Person(String first, String last) { + Person(String first, String last) { this(first, last, null); } - public Person(String last) { this(null, last, null); } - public Person() { this(null, null, null); } + Person(String last) { this(null, last, null); } + Person() { this(null, null, null); } @Override public String toString() { if(empty) diff --git a/typeinfo/PetCount3.java b/typeinfo/PetCount3.java index 803f2b92..9977f9c0 100644 --- a/typeinfo/PetCount3.java +++ b/typeinfo/PetCount3.java @@ -11,7 +11,7 @@ import typeinfo.pets.*; public class PetCount3 { static class Counter extends LinkedHashMap, Integer> { - public Counter() { + Counter() { super(LiteralPetCreator.ALL_TYPES.stream() .map(lpc -> Pair.make(lpc, 0)) .collect( diff --git a/typeinfo/Position.java b/typeinfo/Position.java index c1bfaf81..1912bb95 100644 --- a/typeinfo/Position.java +++ b/typeinfo/Position.java @@ -9,11 +9,11 @@ class EmptyTitleException extends RuntimeException {} class Position { private String title; private Person person; - public Position(String jobTitle, Person employee) { + Position(String jobTitle, Person employee) { setTitle(jobTitle); setPerson(employee); } - public Position(String jobTitle) { + Position(String jobTitle) { this(jobTitle, null); } public String getTitle() { return title; } diff --git a/typeinfo/SelectingMethods.java b/typeinfo/SelectingMethods.java index 918df79b..14c8058a 100644 --- a/typeinfo/SelectingMethods.java +++ b/typeinfo/SelectingMethods.java @@ -7,7 +7,7 @@ import java.lang.reflect.*; class MethodSelector implements InvocationHandler { private Object proxied; - public MethodSelector(Object proxied) { + MethodSelector(Object proxied) { this.proxied = proxied; } @Override diff --git a/typeinfo/SimpleDynamicProxy.java b/typeinfo/SimpleDynamicProxy.java index 361d87f9..50857ccb 100644 --- a/typeinfo/SimpleDynamicProxy.java +++ b/typeinfo/SimpleDynamicProxy.java @@ -6,7 +6,7 @@ import java.lang.reflect.*; class DynamicProxyHandler implements InvocationHandler { private Object proxied; - public DynamicProxyHandler(Object proxied) { + DynamicProxyHandler(Object proxied) { this.proxied = proxied; } @Override diff --git a/typeinfo/SimpleProxyDemo.java b/typeinfo/SimpleProxyDemo.java index d526f0c8..4ea8fea3 100644 --- a/typeinfo/SimpleProxyDemo.java +++ b/typeinfo/SimpleProxyDemo.java @@ -21,7 +21,7 @@ class RealObject implements Interface { class SimpleProxy implements Interface { private Interface proxied; - public SimpleProxy(Interface proxied) { + SimpleProxy(Interface proxied) { this.proxied = proxied; } @Override