diff --git a/Copyright.txt b/Copyright.txt
index 78338904..d30c4a4c 100644
--- a/Copyright.txt
+++ b/Copyright.txt
@@ -1,4 +1,5 @@
-This computer source code is Copyright (c)2006 MindView, Inc.
+//: Copyright.txt
+This computer source code is Copyright 2015 MindView LLC
All Rights Reserved.
Permission to use, copy, modify, and distribute this
@@ -20,47 +21,54 @@ Java" is cited as the origin.
3. Permission to incorporate the Source Code into printed
media may be obtained by contacting:
-MindView, Inc. 5343 Valle Vista La Mesa, California 91941
-Wayne@MindView.net
+MindView LLC, PO Box 969, Crested Butte, CO 81224
+MindViewInc@gmail.com
4. The Source Code and documentation are copyrighted by
-MindView, Inc. The Source code is provided without express
+MindView LLC. The Source code is provided without express
or implied warranty of any kind, including any implied
warranty of merchantability, fitness for a particular
-purpose or non-infringement. MindView, Inc. does not
-warrant that the operation of any program that includes the Source Code will be uninterrupted or error-free. MindView,
-Inc. makes no representation about the suitability of the
+purpose or non-infringement. MindView LLC does not
+warrant that the operation of any program that includes the
+Source Code will be uninterrupted or error-free. MindView
+LLC makes no representation about the suitability of the
Source Code or of any software that includes the Source
Code for any purpose. The entire risk as to the quality
and performance of any program that includes the Source
Code is with the user of the Source Code. The user
-understands that the Source Code was developed for research and instructional purposes and is advised not to rely
+understands that the Source Code was developed for research
+and instructional purposes and is advised not to rely
exclusively for any reason on the Source Code or any
program that includes the Source Code. Should the Source
Code or any resulting software prove defective, the user
assumes the cost of all necessary servicing, repair, or
correction.
-5. IN NO EVENT SHALL MINDVIEW, INC., OR ITS PUBLISHER BE
+5. IN NO EVENT SHALL MINDVIEW LLC, OR ITS PUBLISHER BE
LIABLE TO ANY PARTY UNDER ANY LEGAL THEORY FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
INCLUDING LOST PROFITS, BUSINESS INTERRUPTION, LOSS OF
BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS, OR FOR
PERSONAL INJURIES, ARISING OUT OF THE USE OF THIS SOURCE
-CODE AND ITS DOCUMENTATION, OR ARISING OUT OF THE INABILITY TO USE ANY RESULTING PROGRAM, EVEN IF MINDVIEW, INC., OR
+CODE AND ITS DOCUMENTATION, OR ARISING OUT OF THE INABILITY
+TO USE ANY RESULTING PROGRAM, EVEN IF MINDVIEW LLC, OR
ITS PUBLISHER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGE. MINDVIEW, INC. SPECIFICALLY DISCLAIMS ANY
+DAMAGE. MINDVIEW LLC SPECIFICALLY DISCLAIMS ANY
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE SOURCE CODE AND DOCUMENTATION PROVIDED
HEREUNDER IS ON AN "AS IS" BASIS, WITHOUT ANY ACCOMPANYING
-SERVICES FROM MINDVIEW, INC., AND MINDVIEW, INC. HAS NO
+SERVICES FROM MINDVIEW LLC, AND MINDVIEW LLC HAS NO
OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
ENHANCEMENTS, OR MODIFICATIONS.
-Please note that MindView, Inc. maintains a Web site which
-is the sole distribution point for electronic copies of the Source Code, http://www.MindView.net (and official mirror
-sites), where it is freely available under the terms stated above.
+Please note that MindView LLC maintains a Web site which
+is the sole distribution point for electronic copies of the
+Source Code, http://www.MindView.net (and official mirror
+sites), where it is freely available under the terms stated
+above.
If you think you've found an error in the Source Code,
-please submit a correction using the feedback system that you will find at http://www.MindView.net.
+please submit a correction using the feedback system that
+you will find at http://www.MindView.net.
+///:~
diff --git a/access/SingleImport.java b/access/SingleImport.java
index ecb7c8dd..5f98455c 100644
--- a/access/SingleImport.java
+++ b/access/SingleImport.java
@@ -5,4 +5,4 @@ public class SingleImport {
public static void main(String[] args) {
ArrayList list = new ArrayList();
}
-} ///:~
\ No newline at end of file
+} ///:~
diff --git a/access/build.xml b/access/build.xml
new file mode 100644
index 00000000..cfae737b
--- /dev/null
+++ b/access/build.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/annotations/AtUnitExample4.java b/annotations/AtUnitExample4.java
index ca5c51cb..1e3684e7 100644
--- a/annotations/AtUnitExample4.java
+++ b/annotations/AtUnitExample4.java
@@ -14,7 +14,7 @@ public class AtUnitExample4 {
public AtUnitExample4(String word) { this.word = word; }
public String getWord() { return word; }
public String scrambleWord() {
- List chars = new ArrayList();
+ List chars = new ArrayList<>();
for(Character c : word.toCharArray())
chars.add(c);
Collections.shuffle(chars, rand);
diff --git a/annotations/AtUnitExample5.java b/annotations/AtUnitExample5.java
index 28c0bb8b..294f74c2 100644
--- a/annotations/AtUnitExample5.java
+++ b/annotations/AtUnitExample5.java
@@ -7,6 +7,7 @@ import net.mindview.util.*;
public class AtUnitExample5 {
private String text;
public AtUnitExample5(String text) { this.text = text; }
+ @Override
public String toString() { return text; }
@TestProperty static PrintWriter output;
@TestProperty static int counter;
diff --git a/annotations/HashSetTest.java b/annotations/HashSetTest.java
index 2aa05334..a8b638e8 100644
--- a/annotations/HashSetTest.java
+++ b/annotations/HashSetTest.java
@@ -5,7 +5,7 @@ import net.mindview.atunit.*;
import net.mindview.util.*;
public class HashSetTest {
- HashSet testObject = new HashSet();
+ HashSet testObject = new HashSet<>();
@Test void initialization() {
assert testObject.isEmpty();
}
diff --git a/annotations/InterfaceExtractorProcessor.java b/annotations/InterfaceExtractorProcessor.java
index 738c5d37..840ba3a5 100644
--- a/annotations/InterfaceExtractorProcessor.java
+++ b/annotations/InterfaceExtractorProcessor.java
@@ -14,7 +14,7 @@ public class InterfaceExtractorProcessor
implements AnnotationProcessor {
private final AnnotationProcessorEnvironment env;
private ArrayList interfaceMethods =
- new ArrayList();
+ new ArrayList<>();
public InterfaceExtractorProcessor(
AnnotationProcessorEnvironment env) { this.env = env; }
public void process() {
@@ -58,4 +58,4 @@ public class InterfaceExtractorProcessor
}
}
}
-} ///:~
\ No newline at end of file
+} ///:~
diff --git a/annotations/InterfaceExtractorProcessorFactory.java b/annotations/InterfaceExtractorProcessorFactory.java
index 59c432ca..22aabb97 100644
--- a/annotations/InterfaceExtractorProcessorFactory.java
+++ b/annotations/InterfaceExtractorProcessorFactory.java
@@ -20,4 +20,4 @@ public class InterfaceExtractorProcessorFactory
public Collection supportedOptions() {
return Collections.emptySet();
}
-} ///:~
\ No newline at end of file
+} ///:~
diff --git a/annotations/StackL.java b/annotations/StackL.java
index 80fd0c03..ce572b05 100644
--- a/annotations/StackL.java
+++ b/annotations/StackL.java
@@ -4,7 +4,7 @@ package annotations;
import java.util.*;
public class StackL {
- private LinkedList list = new LinkedList();
+ private LinkedList list = new LinkedList<>();
public void push(T v) { list.addFirst(v); }
public T top() { return list.getFirst(); }
public T pop() { return list.removeFirst(); }
diff --git a/annotations/UseCaseTracker.java b/annotations/UseCaseTracker.java
index 530da6c0..924ee6fc 100644
--- a/annotations/UseCaseTracker.java
+++ b/annotations/UseCaseTracker.java
@@ -18,7 +18,7 @@ public class UseCaseTracker {
}
}
public static void main(String[] args) {
- List useCases = new ArrayList();
+ List useCases = new ArrayList<>();
Collections.addAll(useCases, 47, 48, 49, 50);
trackUseCases(useCases, PasswordUtils.class);
}
diff --git a/annotations/build.xml b/annotations/build.xml
new file mode 100644
index 00000000..f83f83e4
--- /dev/null
+++ b/annotations/build.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/annotations/database/Member.java b/annotations/database/Member.java
index 4e832de0..89a815fa 100644
--- a/annotations/database/Member.java
+++ b/annotations/database/Member.java
@@ -13,6 +13,7 @@ public class Member {
public String getHandle() { return handle; }
public String getFirstName() { return firstName; }
public String getLastName() { return lastName; }
+ @Override
public String toString() { return handle; }
public Integer getAge() { return age; }
} ///:~
diff --git a/annotations/database/TableCreationProcessorFactory.java b/annotations/database/TableCreationProcessorFactory.java
index 883d7377..54b100e0 100644
--- a/annotations/database/TableCreationProcessorFactory.java
+++ b/annotations/database/TableCreationProcessorFactory.java
@@ -98,4 +98,4 @@ public class TableCreationProcessorFactory
}
}
}
-} ///:~
\ No newline at end of file
+} ///:~
diff --git a/annotations/database/TableCreator.java b/annotations/database/TableCreator.java
index 14685ae1..37953dde 100644
--- a/annotations/database/TableCreator.java
+++ b/annotations/database/TableCreator.java
@@ -24,7 +24,7 @@ public class TableCreator {
// If the name is empty, use the Class name:
if(tableName.length() < 1)
tableName = cl.getName().toUpperCase();
- List columnDefs = new ArrayList();
+ List columnDefs = new ArrayList<>();
for(Field field : cl.getDeclaredFields()) {
String columnName = null;
Annotation[] anns = field.getDeclaredAnnotations();
diff --git a/arrays/ArrayOfGenerics.java b/arrays/ArrayOfGenerics.java
index d831bb5c..c48ce23f 100644
--- a/arrays/ArrayOfGenerics.java
+++ b/arrays/ArrayOfGenerics.java
@@ -8,14 +8,14 @@ public class ArrayOfGenerics {
List[] ls;
List[] la = new List[10];
ls = (List[])la; // "Unchecked" warning
- ls[0] = new ArrayList();
+ ls[0] = new ArrayList<>();
// Compile-time checking produces an error:
//! ls[1] = new ArrayList();
// The problem: List is a subtype of Object
Object[] objects = ls; // So assignment is OK
// Compiles and runs without complaint:
- objects[1] = new ArrayList();
+ objects[1] = new ArrayList<>();
// However, if your needs are straightforward it is
// possible to create an array of generics, albeit
@@ -23,6 +23,6 @@ public class ArrayOfGenerics {
List[] spheres =
(List[])new List[10];
for(int i = 0; i < spheres.length; i++)
- spheres[i] = new ArrayList();
+ spheres[i] = new ArrayList<>();
}
} ///:~
diff --git a/arrays/CompType.java b/arrays/CompType.java
index 77d56fff..aa19da10 100644
--- a/arrays/CompType.java
+++ b/arrays/CompType.java
@@ -12,18 +12,21 @@ public class CompType implements Comparable {
i = n1;
j = n2;
}
+ @Override
public String toString() {
String result = "[i = " + i + ", j = " + j + "]";
if(count++ % 3 == 0)
result += "\n";
return result;
}
+ @Override
public int compareTo(CompType rv) {
return (i < rv.i ? -1 : (i == rv.i ? 0 : 1));
}
private static Random r = new Random(47);
public static Generator generator() {
return new Generator() {
+ @Override
public CompType next() {
return new CompType(r.nextInt(100),r.nextInt(100));
}
diff --git a/arrays/ContainerComparison.java b/arrays/ContainerComparison.java
index bb0311b6..288b4a28 100644
--- a/arrays/ContainerComparison.java
+++ b/arrays/ContainerComparison.java
@@ -5,6 +5,7 @@ import static net.mindview.util.Print.*;
class BerylliumSphere {
private static long counter;
private final long id = counter++;
+ @Override
public String toString() { return "Sphere " + id; }
}
@@ -16,8 +17,7 @@ public class ContainerComparison {
print(Arrays.toString(spheres));
print(spheres[4]);
- List sphereList =
- new ArrayList();
+ List sphereList= new ArrayList<>();
for(int i = 0; i < 5; i++)
sphereList.add(new BerylliumSphere());
print(sphereList);
@@ -27,7 +27,7 @@ public class ContainerComparison {
print(Arrays.toString(integers));
print(integers[4]);
- List intList = new ArrayList(
+ List intList = new ArrayList<>(
Arrays.asList(0, 1, 2, 3, 4, 5));
intList.add(97);
print(intList);
diff --git a/arrays/PythonLists.py b/arrays/PythonLists.py
new file mode 100644
index 00000000..79a50460
--- /dev/null
+++ b/arrays/PythonLists.py
@@ -0,0 +1,23 @@
+#: arrays/PythonLists.py
+
+aList = [1, 2, 3, 4, 5]
+print(type(aList)) #
+print(aList) # [1, 2, 3, 4, 5]
+print(aList[4]) # 5 Basic list indexing
+aList.append(6) # lists can be resized
+aList += [7, 8] # Add a list to a list
+print(aList) # [1, 2, 3, 4, 5, 6, 7, 8]
+aSlice = aList[2:4]
+print(aSlice) # [3, 4]
+
+class MyList(list): # Inherit from list
+ # Define a method, 'this' pointer is explicit:
+ def getReversed(self):
+ reversed = self[:] # Copy list using slices
+ reversed.reverse() # Built-in list method
+ return reversed
+
+list2 = MyList(aList) # No 'new' needed for object creation
+print(type(list2)) #
+print(list2.getReversed()) # [8, 7, 6, 5, 4, 3, 2, 1]
+#:~
diff --git a/arrays/build.xml b/arrays/build.xml
new file mode 100644
index 00000000..605f4ea7
--- /dev/null
+++ b/arrays/build.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/assertions/Assert1.java b/assertions/Assert1.java
new file mode 100644
index 00000000..63ced5f4
--- /dev/null
+++ b/assertions/Assert1.java
@@ -0,0 +1,11 @@
+//: assertions/Assert1.java
+// Non-informative style of assert
+// Compile with: javac -source 1.4 Assert1.java
+// {JVMArgs: -ea} // Must run with -ea
+// {ThrowsException}
+
+public class Assert1 {
+ public static void main(String[] args) {
+ assert false;
+ }
+} ///:~
diff --git a/assertions/Assert2.java b/assertions/Assert2.java
new file mode 100644
index 00000000..b5bad5c1
--- /dev/null
+++ b/assertions/Assert2.java
@@ -0,0 +1,10 @@
+//: assertions/Assert2.java
+// Assert with an informative message
+// {JVMArgs: -ea}
+// {ThrowsException}
+
+public class Assert2 {
+ public static void main(String[] args) {
+ assert false: "Here's a message saying what happened";
+ }
+} ///:~
diff --git a/assertions/LoaderAssertions.java b/assertions/LoaderAssertions.java
new file mode 100644
index 00000000..2dc4699b
--- /dev/null
+++ b/assertions/LoaderAssertions.java
@@ -0,0 +1,18 @@
+//: assertions/LoaderAssertions.java
+// Using the class loader to enable assertions
+// Compile with: javac -source 1.4 LoaderAssertions.java
+// {ThrowsException}
+
+public class LoaderAssertions {
+ public static void main(String[] args) {
+ ClassLoader.getSystemClassLoader()
+ .setDefaultAssertionStatus(true);
+ new Loaded().go();
+ }
+}
+
+class Loaded {
+ public void go() {
+ assert false: "Loaded.go()";
+ }
+} ///:~
diff --git a/assertions/Queue.java b/assertions/Queue.java
new file mode 100644
index 00000000..bf177318
--- /dev/null
+++ b/assertions/Queue.java
@@ -0,0 +1,172 @@
+//: assertions/Queue.java
+// Demonstration of Design by Contract (DBC) combined
+// with white-box unit testing.
+// {Depends: junit.jar}
+import junit.framework.*;
+import java.util.*;
+
+public class Queue {
+ private Object[] data;
+ private int
+ in = 0, // Next available storage space
+ out = 0; // Next gettable object
+ // Has it wrapped around the circular queue?
+ private boolean wrapped = false;
+ public static class
+ QueueException extends RuntimeException {
+ public QueueException(String why) { super(why); }
+ }
+ public Queue(int size) {
+ data = new Object[size];
+ assert invariant(); // Must be true after construction
+ }
+ public boolean empty() {
+ return !wrapped && in == out;
+ }
+ public boolean full() {
+ return wrapped && in == out;
+ }
+ public void put(Object item) {
+ precondition(item != null, "put() null item");
+ precondition(!full(), "put() into full Queue");
+ assert invariant();
+ data[in++] = item;
+ if(in >= data.length) {
+ in = 0;
+ wrapped = true;
+ }
+ assert invariant();
+ }
+ public Object get() {
+ precondition(!empty(), "get() from empty Queue");
+ assert invariant();
+ Object returnVal = data[out];
+ data[out] = null;
+ out++;
+ if(out >= data.length) {
+ out = 0;
+ wrapped = false;
+ }
+ assert postcondition(
+ returnVal != null, "Null item in Queue");
+ assert invariant();
+ return returnVal;
+ }
+ // Design-by-contract support methods:
+ private static void
+ precondition(boolean cond, String msg) {
+ if(!cond) throw new QueueException(msg);
+ }
+ private static boolean
+ postcondition(boolean cond, String msg) {
+ if(!cond) throw new QueueException(msg);
+ return true;
+ }
+ private boolean invariant() {
+ // Guarantee that no null values are in the
+ // region of 'data' that holds objects:
+ for(int i = out; i != in; i = (i + 1) % data.length)
+ if(data[i] == null)
+ throw new QueueException("null in queue");
+ // Guarantee that only null values are outside the
+ // region of 'data' that holds objects:
+ if(full()) return true;
+ for(int i = in; i != out; i = (i + 1) % data.length)
+ if(data[i] != null)
+ throw new QueueException(
+ "non-null outside of queue range: " + dump());
+ return true;
+ }
+ private String dump() {
+ return "in = " + in +
+ ", out = " + out +
+ ", full() = " + full() +
+ ", empty() = " + empty() +
+ ", queue = " + Arrays.asList(data);
+ }
+ // JUnit testing.
+ // As an inner class, this has access to privates:
+ public static class WhiteBoxTest extends TestCase {
+ private Queue queue = new Queue(10);
+ private int i = 0;
+ public WhiteBoxTest(String name) {
+ super(name);
+ while(i < 5) // Preload with some data
+ queue.put("" + i++);
+ }
+ // Support methods:
+ private void showFullness() {
+ assertTrue(queue.full());
+ assertFalse(queue.empty());
+ // Dump is private, white-box testing allows access:
+ System.out.println(queue.dump());
+ }
+ private void showEmptiness() {
+ assertFalse(queue.full());
+ assertTrue(queue.empty());
+ System.out.println(queue.dump());
+ }
+ public void testFull() {
+ System.out.println("testFull");
+ System.out.println(queue.dump());
+ System.out.println(queue.get());
+ System.out.println(queue.get());
+ while(!queue.full())
+ queue.put("" + i++);
+ String msg = "";
+ try {
+ queue.put("");
+ } catch(QueueException e) {
+ msg = e.getMessage();
+ System.out.println(msg);
+ }
+ assertEquals(msg, "put() into full Queue");
+ showFullness();
+ }
+ public void testEmpty() {
+ System.out.println("testEmpty");
+ while(!queue.empty())
+ System.out.println(queue.get());
+ String msg = "";
+ try {
+ queue.get();
+ } catch(QueueException e) {
+ msg = e.getMessage();
+ System.out.println(msg);
+ }
+ assertEquals(msg, "get() from empty Queue");
+ showEmptiness();
+ }
+ public void testNullPut() {
+ System.out.println("testNullPut");
+ String msg = "";
+ try {
+ queue.put(null);
+ } catch(QueueException e) {
+ msg = e.getMessage();
+ System.out.println(msg);
+ }
+ assertEquals(msg, "put() null item");
+ }
+ public void testCircularity() {
+ System.out.println("testCircularity");
+ while(!queue.full())
+ queue.put("" + i++);
+ showFullness();
+ // White-box testing accesses private field:
+ assertTrue(queue.wrapped);
+ while(!queue.empty())
+ System.out.println(queue.get());
+ showEmptiness();
+ while(!queue.full())
+ queue.put("" + i++);
+ showFullness();
+ while(!queue.empty())
+ System.out.println(queue.get());
+ showEmptiness();
+ }
+ }
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Queue.WhiteBoxTest.class);
+ }
+} ///:~
diff --git a/assertions/build.xml b/assertions/build.xml
new file mode 100644
index 00000000..5c65b0b4
--- /dev/null
+++ b/assertions/build.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/concurrency/ActiveObjectDemo.java b/concurrency/ActiveObjectDemo.java
index c84ad18a..aa274a3d 100644
--- a/concurrency/ActiveObjectDemo.java
+++ b/concurrency/ActiveObjectDemo.java
@@ -23,6 +23,7 @@ public class ActiveObjectDemo {
public Future
calculateInt(final int x, final int y) {
return ex.submit(new Callable() {
+ @Override
public Integer call() {
print("starting " + x + " + " + y);
pause(500);
@@ -33,6 +34,7 @@ public class ActiveObjectDemo {
public Future
calculateFloat(final float x, final float y) {
return ex.submit(new Callable() {
+ @Override
public Float call() {
print("starting " + x + " + " + y);
pause(2000);
@@ -45,7 +47,7 @@ public class ActiveObjectDemo {
ActiveObjectDemo d1 = new ActiveObjectDemo();
// Prevents ConcurrentModificationException:
List> results =
- new CopyOnWriteArrayList>();
+ new CopyOnWriteArrayList<>();
for(float f = 0.0f; f < 1.0f; f += 0.2f)
results.add(d1.calculateFloat(f, f));
for(int i = 0; i < 5; i++)
diff --git a/concurrency/AtomicEvenGenerator.java b/concurrency/AtomicEvenGenerator.java
index 4ca8797b..c355f282 100644
--- a/concurrency/AtomicEvenGenerator.java
+++ b/concurrency/AtomicEvenGenerator.java
@@ -1,11 +1,12 @@
//: concurrency/AtomicEvenGenerator.java
// Atomic classes are occasionally useful in regular code.
-// {RunByHand}
+// {TimeOutDuringTesting}
import java.util.concurrent.atomic.*;
public class AtomicEvenGenerator extends IntGenerator {
private AtomicInteger currentEvenValue =
new AtomicInteger(0);
+ @Override
public int next() {
return currentEvenValue.addAndGet(2);
}
diff --git a/concurrency/AtomicIntegerTest.java b/concurrency/AtomicIntegerTest.java
index 5ae816aa..8ef05eff 100644
--- a/concurrency/AtomicIntegerTest.java
+++ b/concurrency/AtomicIntegerTest.java
@@ -7,12 +7,14 @@ public class AtomicIntegerTest implements Runnable {
private AtomicInteger i = new AtomicInteger(0);
public int getValue() { return i.get(); }
private void evenIncrement() { i.addAndGet(2); }
+ @Override
public void run() {
while(true)
evenIncrement();
}
public static void main(String[] args) {
new Timer().schedule(new TimerTask() {
+ @Override
public void run() {
System.err.println("Aborting");
System.exit(0);
diff --git a/concurrency/AtomicityTest.java b/concurrency/AtomicityTest.java
index 958bdeb7..2fe558b8 100644
--- a/concurrency/AtomicityTest.java
+++ b/concurrency/AtomicityTest.java
@@ -5,6 +5,7 @@ public class AtomicityTest implements Runnable {
private int i = 0;
public int getValue() { return i; }
private synchronized void evenIncrement() { i++; i++; }
+ @Override
public void run() {
while(true)
evenIncrement();
diff --git a/concurrency/AttemptLocking.java b/concurrency/AttemptLocking.java
index ac2aa9b3..c54df34a 100644
--- a/concurrency/AttemptLocking.java
+++ b/concurrency/AttemptLocking.java
@@ -37,6 +37,7 @@ public class AttemptLocking {
// Now create a separate task to grab the lock:
new Thread() {
{ setDaemon(true); }
+ @Override
public void run() {
al.lock.lock();
System.out.println("acquired");
diff --git a/concurrency/BankTellerSimulation.java b/concurrency/BankTellerSimulation.java
index fa4d2ebe..b0022385 100644
--- a/concurrency/BankTellerSimulation.java
+++ b/concurrency/BankTellerSimulation.java
@@ -19,6 +19,7 @@ class CustomerLine extends ArrayBlockingQueue {
public CustomerLine(int maxLineSize) {
super(maxLineSize);
}
+ @Override
public String toString() {
if(this.size() == 0)
return "[Empty]";
@@ -36,6 +37,7 @@ class CustomerGenerator implements Runnable {
public CustomerGenerator(CustomerLine cq) {
customers = cq;
}
+ @Override
public void run() {
try {
while(!Thread.interrupted()) {
@@ -96,9 +98,9 @@ class TellerManager implements Runnable {
private ExecutorService exec;
private CustomerLine customers;
private PriorityQueue workingTellers =
- new PriorityQueue();
+ new PriorityQueue<>();
private Queue tellersDoingOtherThings =
- new LinkedList();
+ new LinkedList<>();
private int adjustmentPeriod;
public TellerManager(ExecutorService e,
@@ -146,6 +148,7 @@ class TellerManager implements Runnable {
teller.doSomethingElse();
tellersDoingOtherThings.offer(teller);
}
+ @Override
public void run() {
try {
while(!Thread.interrupted()) {
@@ -161,6 +164,7 @@ class TellerManager implements Runnable {
}
System.out.println(this + "terminating");
}
+ @Override
public String toString() { return "TellerManager "; }
}
@@ -201,4 +205,4 @@ Teller 0 interrupted
Teller 0 terminating
CustomerGenerator interrupted
CustomerGenerator terminating
-*///:~
\ No newline at end of file
+*///:~
diff --git a/concurrency/CallableDemo.java b/concurrency/CallableDemo.java
index 2538defa..3d27d8c7 100644
--- a/concurrency/CallableDemo.java
+++ b/concurrency/CallableDemo.java
@@ -7,6 +7,7 @@ class TaskWithResult implements Callable {
public TaskWithResult(int id) {
this.id = id;
}
+ @Override
public String call() {
return "result of TaskWithResult " + id;
}
@@ -15,8 +16,7 @@ class TaskWithResult implements Callable {
public class CallableDemo {
public static void main(String[] args) {
ExecutorService exec = Executors.newCachedThreadPool();
- ArrayList> results =
- new ArrayList>();
+ ArrayList> results = new ArrayList<>();
for(int i = 0; i < 10; i++)
results.add(exec.submit(new TaskWithResult(i)));
for(Future fs : results)
diff --git a/concurrency/CaptureUncaughtException.java b/concurrency/CaptureUncaughtException.java
index aa33ca6f..6ca80ba6 100644
--- a/concurrency/CaptureUncaughtException.java
+++ b/concurrency/CaptureUncaughtException.java
@@ -1,8 +1,9 @@
//: concurrency/CaptureUncaughtException.java
-// {RunByHand}
+// {TimeOutDuringTesting}
import java.util.concurrent.*;
class ExceptionThread2 implements Runnable {
+ @Override
public void run() {
Thread t = Thread.currentThread();
System.out.println("run() by " + t);
@@ -14,12 +15,14 @@ class ExceptionThread2 implements Runnable {
class MyUncaughtExceptionHandler implements
Thread.UncaughtExceptionHandler {
+ @Override
public void uncaughtException(Thread t, Throwable e) {
System.out.println("caught " + e);
}
}
class HandlerThreadFactory implements ThreadFactory {
+ @Override
public Thread newThread(Runnable r) {
System.out.println(this + " creating new Thread");
Thread t = new Thread(r);
@@ -45,4 +48,4 @@ eh = MyUncaughtExceptionHandler@1fb8ee3
run() by Thread[Thread-0,5,main]
eh = MyUncaughtExceptionHandler@1fb8ee3
caught java.lang.RuntimeException
-*///:~
\ No newline at end of file
+*///:~
diff --git a/concurrency/CarBuilder.java b/concurrency/CarBuilder.java
index b038fb63..5bf308b6 100644
--- a/concurrency/CarBuilder.java
+++ b/concurrency/CarBuilder.java
@@ -30,6 +30,7 @@ class ChassisBuilder implements Runnable {
private CarQueue carQueue;
private int counter = 0;
public ChassisBuilder(CarQueue cq) { carQueue = cq; }
+ @Override
public void run() {
try {
while(!Thread.interrupted()) {
@@ -59,6 +60,7 @@ class Assembler implements Runnable {
}
public Car car() { return car; }
public CyclicBarrier barrier() { return barrier; }
+ @Override
public void run() {
try {
while(!Thread.interrupted()) {
@@ -85,6 +87,7 @@ class Assembler implements Runnable {
class Reporter implements Runnable {
private CarQueue carQueue;
public Reporter(CarQueue cq) { carQueue = cq; }
+ @Override
public void run() {
try {
while(!Thread.interrupted()) {
@@ -167,7 +170,7 @@ class WheelRobot extends Robot {
class RobotPool {
// Quietly prevents identical entries:
- private Set pool = new HashSet();
+ private Set pool = new HashSet<>();
public synchronized void add(Robot r) {
pool.add(r);
notifyAll();
diff --git a/concurrency/CloseResource.java b/concurrency/CloseResource.java
index 416e763e..aa8ad31a 100644
--- a/concurrency/CloseResource.java
+++ b/concurrency/CloseResource.java
@@ -1,7 +1,7 @@
//: concurrency/CloseResource.java
// Interrupting a blocked task by
// closing the underlying resource.
-// {RunByHand}
+// {TimeOutDuringTesting}
import java.net.*;
import java.util.concurrent.*;
import java.io.*;
diff --git a/concurrency/CountDownLatchDemo.java b/concurrency/CountDownLatchDemo.java
index 740afe98..62eecaf9 100644
--- a/concurrency/CountDownLatchDemo.java
+++ b/concurrency/CountDownLatchDemo.java
@@ -12,6 +12,7 @@ class TaskPortion implements Runnable {
TaskPortion(CountDownLatch latch) {
this.latch = latch;
}
+ @Override
public void run() {
try {
doWork();
@@ -24,6 +25,7 @@ class TaskPortion implements Runnable {
TimeUnit.MILLISECONDS.sleep(rand.nextInt(2000));
print(this + "completed");
}
+ @Override
public String toString() {
return String.format("%1$-3d ", id);
}
@@ -37,6 +39,7 @@ class WaitingTask implements Runnable {
WaitingTask(CountDownLatch latch) {
this.latch = latch;
}
+ @Override
public void run() {
try {
latch.await();
@@ -45,6 +48,7 @@ class WaitingTask implements Runnable {
print(this + " interrupted");
}
}
+ @Override
public String toString() {
return String.format("WaitingTask %1$-3d ", id);
}
diff --git a/concurrency/CriticalSection.java b/concurrency/CriticalSection.java
index 9ba36521..8e11ed68 100644
--- a/concurrency/CriticalSection.java
+++ b/concurrency/CriticalSection.java
@@ -1,5 +1,6 @@
//: concurrency/CriticalSection.java
-// {RunByHand} (Behavior may have changed in Java 8).
+// {TimeOutDuringTesting}
+// (Behavior may have changed in Java 8).
// Synchronizing blocks instead of entire methods. Also
// demonstrates protection of a non-thread-safe class
// with a thread-safe one.
@@ -19,6 +20,7 @@ class Pair { // Not thread-safe
public int getY() { return y; }
public void incrementX() { x++; }
public void incrementY() { y++; }
+ @Override
public String toString() {
return "x: " + x + ", y: " + y;
}
@@ -40,7 +42,7 @@ abstract class PairManager {
AtomicInteger checkCounter = new AtomicInteger(0);
protected Pair p = new Pair();
private List storage =
- Collections.synchronizedList(new ArrayList());
+ Collections.synchronizedList(new ArrayList<>());
public synchronized Pair getPair() {
// Make a copy to keep the original safe:
return new Pair(p.getX(), p.getY());
@@ -57,6 +59,7 @@ abstract class PairManager {
// Synchronize the entire method:
class PairManager1 extends PairManager {
+ @Override
public synchronized void increment() {
p.incrementX();
p.incrementY();
@@ -66,6 +69,7 @@ class PairManager1 extends PairManager {
// Use a critical section:
class PairManager2 extends PairManager {
+ @Override
public void increment() {
Pair temp;
synchronized(this) {
@@ -82,10 +86,12 @@ class PairManipulator implements Runnable {
public PairManipulator(PairManager pm) {
this.pm = pm;
}
+ @Override
public void run() {
while(true)
pm.increment();
}
+ @Override
public String toString() {
return "Pair: " + pm.getPair() +
" checkCounter = " + pm.checkCounter.get();
@@ -97,6 +103,7 @@ class PairChecker implements Runnable {
public PairChecker(PairManager pm) {
this.pm = pm;
}
+ @Override
public void run() {
while(true) {
pm.checkCounter.incrementAndGet();
@@ -137,4 +144,4 @@ public class CriticalSection {
} /* Output: (Sample)
pm1: Pair: x: 15, y: 15 checkCounter = 272565
pm2: Pair: x: 16, y: 16 checkCounter = 3956974
-*///:~
\ No newline at end of file
+*///:~
diff --git a/concurrency/DaemonFromFactory.java b/concurrency/DaemonFromFactory.java
index 150cacda..c6fad692 100644
--- a/concurrency/DaemonFromFactory.java
+++ b/concurrency/DaemonFromFactory.java
@@ -5,6 +5,7 @@ import net.mindview.util.*;
import static net.mindview.util.Print.*;
public class DaemonFromFactory implements Runnable {
+ @Override
public void run() {
try {
while(true) {
diff --git a/concurrency/Daemons.java b/concurrency/Daemons.java
index 60000956..bff30b86 100644
--- a/concurrency/Daemons.java
+++ b/concurrency/Daemons.java
@@ -5,6 +5,7 @@ import static net.mindview.util.Print.*;
class Daemon implements Runnable {
private Thread[] t = new Thread[10];
+ @Override
public void run() {
for(int i = 0; i < t.length; i++) {
t[i] = new Thread(new DaemonSpawn());
@@ -20,6 +21,7 @@ class Daemon implements Runnable {
}
class DaemonSpawn implements Runnable {
+ @Override
public void run() {
while(true)
Thread.yield();
diff --git a/concurrency/DaemonsDontRunFinally.java b/concurrency/DaemonsDontRunFinally.java
index 0db66da3..743558b6 100644
--- a/concurrency/DaemonsDontRunFinally.java
+++ b/concurrency/DaemonsDontRunFinally.java
@@ -4,6 +4,7 @@ import java.util.concurrent.*;
import static net.mindview.util.Print.*;
class ADaemon implements Runnable {
+ @Override
public void run() {
try {
print("Starting ADaemon");
diff --git a/concurrency/DelayQueueDemo.java b/concurrency/DelayQueueDemo.java
index 838c2aa6..1b42e8d6 100644
--- a/concurrency/DelayQueueDemo.java
+++ b/concurrency/DelayQueueDemo.java
@@ -10,24 +10,28 @@ class DelayedTask implements Runnable, Delayed {
private final int delta;
private final long trigger;
protected static List sequence =
- new ArrayList();
+ new ArrayList<>();
public DelayedTask(int delayInMilliseconds) {
delta = delayInMilliseconds;
trigger = System.nanoTime() +
NANOSECONDS.convert(delta, MILLISECONDS);
sequence.add(this);
}
+ @Override
public long getDelay(TimeUnit unit) {
return unit.convert(
trigger - System.nanoTime(), NANOSECONDS);
}
+ @Override
public int compareTo(Delayed arg) {
DelayedTask that = (DelayedTask)arg;
if(trigger < that.trigger) return -1;
if(trigger > that.trigger) return 1;
return 0;
}
+ @Override
public void run() { printnb(this + " "); }
+ @Override
public String toString() {
return String.format("[%1$-4d]", delta) +
" Task " + id;
@@ -41,6 +45,7 @@ class DelayedTask implements Runnable, Delayed {
super(delay);
exec = e;
}
+ @Override
public void run() {
for(DelayedTask pt : sequence) {
printnb(pt.summary() + " ");
@@ -57,6 +62,7 @@ class DelayedTaskConsumer implements Runnable {
public DelayedTaskConsumer(DelayQueue q) {
this.q = q;
}
+ @Override
public void run() {
try {
while(!Thread.interrupted())
@@ -73,7 +79,7 @@ public class DelayQueueDemo {
Random rand = new Random(47);
ExecutorService exec = Executors.newCachedThreadPool();
DelayQueue queue =
- new DelayQueue();
+ new DelayQueue<>();
// Fill with tasks that have random delays:
for(int i = 0; i < 20; i++)
queue.put(new DelayedTask(rand.nextInt(5000)));
diff --git a/concurrency/EvenChecker.java b/concurrency/EvenChecker.java
index c1c96e69..7874581d 100644
--- a/concurrency/EvenChecker.java
+++ b/concurrency/EvenChecker.java
@@ -8,6 +8,7 @@ public class EvenChecker implements Runnable {
generator = g;
id = ident;
}
+ @Override
public void run() {
while(!generator.isCanceled()) {
int val = generator.next();
diff --git a/concurrency/EvenGenerator.java b/concurrency/EvenGenerator.java
index 33497e6d..4a5136de 100644
--- a/concurrency/EvenGenerator.java
+++ b/concurrency/EvenGenerator.java
@@ -3,6 +3,7 @@
public class EvenGenerator extends IntGenerator {
private int currentEvenValue = 0;
+ @Override
public int next() {
++currentEvenValue; // Danger point here!
++currentEvenValue;
diff --git a/concurrency/ExceptionThread.java b/concurrency/ExceptionThread.java
index 469e4e94..386d6ed7 100644
--- a/concurrency/ExceptionThread.java
+++ b/concurrency/ExceptionThread.java
@@ -3,6 +3,7 @@
import java.util.concurrent.*;
public class ExceptionThread implements Runnable {
+ @Override
public void run() {
throw new RuntimeException();
}
diff --git a/concurrency/ExchangerDemo.java b/concurrency/ExchangerDemo.java
index e03b559d..467c722a 100644
--- a/concurrency/ExchangerDemo.java
+++ b/concurrency/ExchangerDemo.java
@@ -13,6 +13,7 @@ class ExchangerProducer implements Runnable {
generator = gen;
this.holder = holder;
}
+ @Override
public void run() {
try {
while(!Thread.interrupted()) {
@@ -35,6 +36,7 @@ class ExchangerConsumer implements Runnable {
exchanger = ex;
this.holder = holder;
}
+ @Override
public void run() {
try {
while(!Thread.interrupted()) {
@@ -60,14 +62,14 @@ public class ExchangerDemo {
if(args.length > 1)
delay = new Integer(args[1]);
ExecutorService exec = Executors.newCachedThreadPool();
- Exchanger> xc = new Exchanger>();
+ Exchanger> xc = new Exchanger<>();
List
- producerList = new CopyOnWriteArrayList(),
- consumerList = new CopyOnWriteArrayList();
- exec.execute(new ExchangerProducer(xc,
+ producerList = new CopyOnWriteArrayList<>(),
+ consumerList = new CopyOnWriteArrayList<>();
+ exec.execute(new ExchangerProducer<>(xc,
BasicGenerator.create(Fat.class), producerList));
exec.execute(
- new ExchangerConsumer(xc,consumerList));
+ new ExchangerConsumer<>(xc,consumerList));
TimeUnit.SECONDS.sleep(delay);
exec.shutdownNow();
}
diff --git a/concurrency/ExplicitCriticalSection.java b/concurrency/ExplicitCriticalSection.java
index dbf99dc7..1191ad7f 100644
--- a/concurrency/ExplicitCriticalSection.java
+++ b/concurrency/ExplicitCriticalSection.java
@@ -7,6 +7,7 @@ import java.util.concurrent.locks.*;
// Synchronize the entire method:
class ExplicitPairManager1 extends PairManager {
private Lock lock = new ReentrantLock();
+ @Override
public void increment() {
lock.lock();
try {
@@ -22,6 +23,7 @@ class ExplicitPairManager1 extends PairManager {
// Use a critical section:
class ExplicitPairManager2 extends PairManager {
private Lock lock = new ReentrantLock();
+ @Override
public void increment() {
Pair temp;
lock.lock();
@@ -43,4 +45,4 @@ public class ExplicitCriticalSection {
pman2 = new ExplicitPairManager2();
CriticalSection.testApproaches(pman1, pman2);
}
-} ///:~
\ No newline at end of file
+} ///:~
diff --git a/concurrency/FastSimulation.java b/concurrency/FastSimulation.java
index 7a4e3e52..8d60d45e 100644
--- a/concurrency/FastSimulation.java
+++ b/concurrency/FastSimulation.java
@@ -12,6 +12,7 @@ public class FastSimulation {
new AtomicInteger[N_ELEMENTS][N_GENES];
static Random rand = new Random(47);
static class Evolver implements Runnable {
+ @Override
public void run() {
while(!Thread.interrupted()) {
// Randomly select an element to work on:
diff --git a/concurrency/Fat.java b/concurrency/Fat.java
index 48f849d3..0be5590a 100644
--- a/concurrency/Fat.java
+++ b/concurrency/Fat.java
@@ -12,5 +12,6 @@ public class Fat {
}
}
public void operation() { System.out.println(this); }
+ @Override
public String toString() { return "Fat id: " + id; }
} ///:~
diff --git a/concurrency/GreenhouseScheduler.java b/concurrency/GreenhouseScheduler.java
index 4cb3902c..3aefcf37 100644
--- a/concurrency/GreenhouseScheduler.java
+++ b/concurrency/GreenhouseScheduler.java
@@ -26,6 +26,7 @@ public class GreenhouseScheduler {
event, initialDelay, period, TimeUnit.MILLISECONDS);
}
class LightOn implements Runnable {
+ @Override
public void run() {
// Put hardware control code here to
// physically turn on the light.
@@ -34,6 +35,7 @@ public class GreenhouseScheduler {
}
}
class LightOff implements Runnable {
+ @Override
public void run() {
// Put hardware control code here to
// physically turn off the light.
@@ -42,6 +44,7 @@ public class GreenhouseScheduler {
}
}
class WaterOn implements Runnable {
+ @Override
public void run() {
// Put hardware control code here.
System.out.println("Turning greenhouse water on");
@@ -49,6 +52,7 @@ public class GreenhouseScheduler {
}
}
class WaterOff implements Runnable {
+ @Override
public void run() {
// Put hardware control code here.
System.out.println("Turning greenhouse water off");
@@ -56,6 +60,7 @@ public class GreenhouseScheduler {
}
}
class ThermostatNight implements Runnable {
+ @Override
public void run() {
// Put hardware control code here.
System.out.println("Thermostat to night setting");
@@ -63,6 +68,7 @@ public class GreenhouseScheduler {
}
}
class ThermostatDay implements Runnable {
+ @Override
public void run() {
// Put hardware control code here.
System.out.println("Thermostat to day setting");
@@ -70,15 +76,18 @@ public class GreenhouseScheduler {
}
}
class Bell implements Runnable {
+ @Override
public void run() { System.out.println("Bing!"); }
}
class Terminate implements Runnable {
+ @Override
public void run() {
System.out.println("Terminating");
scheduler.shutdownNow();
// Must start a separate task to do this job,
// since the scheduler was shut down:
new Thread() {
+ @Override
public void run() {
for(DataPoint d : data)
System.out.println(d);
@@ -96,6 +105,7 @@ public class GreenhouseScheduler {
temperature = temp;
humidity = hum;
}
+ @Override
public String toString() {
return time.getTime() +
String.format(
@@ -114,8 +124,9 @@ public class GreenhouseScheduler {
private int humidityDirection = +1;
private Random rand = new Random(47);
List data = Collections.synchronizedList(
- new ArrayList());
+ new ArrayList<>());
class CollectData implements Runnable {
+ @Override
public void run() {
System.out.println("Collecting data");
synchronized(GreenhouseScheduler.this) {
@@ -153,4 +164,4 @@ public class GreenhouseScheduler {
gh.repeat(gh.new ThermostatDay(), 0, 1400);
gh.repeat(gh.new CollectData(), 500, 500);
}
-} /* (Execute to see output) *///:~
\ No newline at end of file
+} /* (Execute to see output) *///:~
diff --git a/concurrency/HorseRace.java b/concurrency/HorseRace.java
index 13de71f7..d23f5a99 100644
--- a/concurrency/HorseRace.java
+++ b/concurrency/HorseRace.java
@@ -12,6 +12,7 @@ class Horse implements Runnable {
private static CyclicBarrier barrier;
public Horse(CyclicBarrier b) { barrier = b; }
public synchronized int getStrides() { return strides; }
+ @Override
public void run() {
try {
while(!Thread.interrupted()) {
@@ -27,6 +28,7 @@ class Horse implements Runnable {
throw new RuntimeException(e);
}
}
+ @Override
public String toString() { return "Horse " + id + " "; }
public String tracks() {
StringBuilder s = new StringBuilder();
@@ -39,12 +41,13 @@ class Horse implements Runnable {
public class HorseRace {
static final int FINISH_LINE = 75;
- private List horses = new ArrayList();
+ private List horses = new ArrayList<>();
private ExecutorService exec =
Executors.newCachedThreadPool();
private CyclicBarrier barrier;
public HorseRace(int nHorses, final int pause) {
barrier = new CyclicBarrier(nHorses, new Runnable() {
+ @Override
public void run() {
StringBuilder s = new StringBuilder();
for(int i = 0; i < FINISH_LINE; i++)
diff --git a/concurrency/Interrupting.java b/concurrency/Interrupting.java
index a6cfecfe..c31858c6 100644
--- a/concurrency/Interrupting.java
+++ b/concurrency/Interrupting.java
@@ -5,6 +5,7 @@ import java.io.*;
import static net.mindview.util.Print.*;
class SleepBlocked implements Runnable {
+ @Override
public void run() {
try {
TimeUnit.SECONDS.sleep(100);
@@ -18,6 +19,7 @@ class SleepBlocked implements Runnable {
class IOBlocked implements Runnable {
private InputStream in;
public IOBlocked(InputStream is) { in = is; }
+ @Override
public void run() {
try {
print("Waiting for read():");
@@ -40,11 +42,13 @@ class SynchronizedBlocked implements Runnable {
}
public SynchronizedBlocked() {
new Thread() {
+ @Override
public void run() {
f(); // Lock acquired by this thread
}
}.start();
}
+ @Override
public void run() {
print("Trying to call f()");
f();
diff --git a/concurrency/Interrupting2.java b/concurrency/Interrupting2.java
index b84b97b2..cd56abf1 100644
--- a/concurrency/Interrupting2.java
+++ b/concurrency/Interrupting2.java
@@ -24,6 +24,7 @@ class BlockedMutex {
class Blocked2 implements Runnable {
BlockedMutex blocked = new BlockedMutex();
+ @Override
public void run() {
print("Waiting for f() in BlockedMutex");
blocked.f();
diff --git a/concurrency/InterruptingIdiom.java b/concurrency/InterruptingIdiom.java
index 1973be84..7347144f 100644
--- a/concurrency/InterruptingIdiom.java
+++ b/concurrency/InterruptingIdiom.java
@@ -17,6 +17,7 @@ class NeedsCleanup {
class Blocked3 implements Runnable {
private volatile double d = 0.0;
+ @Override
public void run() {
try {
while(!Thread.interrupted()) {
diff --git a/concurrency/Joining.java b/concurrency/Joining.java
index 4a40c926..0b637615 100644
--- a/concurrency/Joining.java
+++ b/concurrency/Joining.java
@@ -9,6 +9,7 @@ class Sleeper extends Thread {
duration = sleepTime;
start();
}
+ @Override
public void run() {
try {
sleep(duration);
@@ -28,6 +29,7 @@ class Joiner extends Thread {
this.sleeper = sleeper;
start();
}
+ @Override
public void run() {
try {
sleeper.join();
diff --git a/concurrency/LiftOff.java b/concurrency/LiftOff.java
index 6564aedd..d15bcaa7 100644
--- a/concurrency/LiftOff.java
+++ b/concurrency/LiftOff.java
@@ -13,6 +13,7 @@ public class LiftOff implements Runnable {
return "#" + id + "(" +
(countDown > 0 ? countDown : "Liftoff!") + "), ";
}
+ @Override
public void run() {
while(countDown-- > 0) {
System.out.print(status());
diff --git a/concurrency/ListComparisons.java b/concurrency/ListComparisons.java
index 66067923..638dd27b 100644
--- a/concurrency/ListComparisons.java
+++ b/concurrency/ListComparisons.java
@@ -42,7 +42,7 @@ abstract class ListTest extends Tester> {
class SynchronizedArrayListTest extends ListTest {
List containerInitializer() {
return Collections.synchronizedList(
- new ArrayList(
+ new ArrayList<>(
new CountingIntegerList(containerSize)));
}
SynchronizedArrayListTest(int nReaders, int nWriters) {
@@ -52,7 +52,7 @@ class SynchronizedArrayListTest extends ListTest {
class CopyOnWriteArrayListTest extends ListTest {
List containerInitializer() {
- return new CopyOnWriteArrayList(
+ return new CopyOnWriteArrayList<>(
new CountingIntegerList(containerSize));
}
CopyOnWriteArrayListTest(int nReaders, int nWriters) {
diff --git a/concurrency/MapComparisons.java b/concurrency/MapComparisons.java
index 76bf4156..6c87fb46 100644
--- a/concurrency/MapComparisons.java
+++ b/concurrency/MapComparisons.java
@@ -43,7 +43,7 @@ extends Tester