After rewriting Type Information Chapter, added missing @Override

This commit is contained in:
Bruce Eckel 2021-01-31 15:42:31 -07:00
parent dfdbcf604f
commit 55de56e524
1034 changed files with 102363 additions and 2776 deletions

5
CI.txt
View File

@ -1,5 +0,0 @@
Links formerly in the README. Both of these mysteriously started breaking.
[![](https://travis-ci.org/BruceEckel/OnJava8-Examples.svg?branch=master)](https://travis-ci.org/BruceEckel/OnJava8-Examples)
[![](https://ci.appveyor.com/api/projects/status/github/BruceEckel/OnJava8-Examples)](https://ci.appveyor.com/project/BruceEckel/onjava-examples)

View File

@ -1,5 +1,5 @@
// Copyright.txt
This computer source code is Copyright ©2020 MindView LLC.
This computer source code is Copyright ©2021 MindView LLC.
All Rights Reserved.
Permission to use, copy, modify, and distribute this

View File

@ -1,5 +1,5 @@
// annotations/AUComposition.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Creating non-embedded tests
@ -23,8 +23,8 @@ public class AUComposition {
}
/* Output:
annotations.AUComposition
. tMethodOne
. tMethodTwo This is methodTwo
. tMethodOne
OK (2 tests)
*/

View File

@ -1,5 +1,5 @@
// annotations/AUExternalTest.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Creating non-embedded tests

View File

@ -1,5 +1,5 @@
// annotations/AtUnitExample1.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {java onjava.atunit.AtUnit
@ -34,15 +34,15 @@ public class AtUnitExample1 {
}
/* Output:
annotations.AtUnitExample1
. m3
. anotherDisappointment (failed)
. methodOneTest
. failureTest (failed)
. m2 This is methodTwo
. failureTest (failed)
. anotherDisappointment (failed)
. m3
(5 tests)
>>> 2 FAILURES <<<
annotations.AtUnitExample1: failureTest
annotations.AtUnitExample1: anotherDisappointment
annotations.AtUnitExample1: failureTest
*/

View File

@ -1,5 +1,5 @@
// annotations/AtUnitExample2.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Assertions and exceptions can be used in @Tests
@ -40,18 +40,18 @@ public class AtUnitExample2 {
}
/* Output:
annotations.AtUnitExample2
. exceptionExample java.io.FileNotFoundException:
nofile.txt (The system cannot find the file specified)
(failed)
. assertExample
. assertAndReturn This is methodTwo
. assertFailureExample java.lang.AssertionError: What
a surprise!
(failed)
. assertExample
. exceptionExample java.io.FileNotFoundException:
nofile.txt (The system cannot find the file specified)
(failed)
. assertAndReturn This is methodTwo
(4 tests)
>>> 2 FAILURES <<<
annotations.AtUnitExample2: exceptionExample
annotations.AtUnitExample2: assertFailureExample
annotations.AtUnitExample2: exceptionExample
*/

View File

@ -1,5 +1,5 @@
// annotations/AtUnitExample3.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {java onjava.atunit.AtUnit
@ -35,8 +35,8 @@ public class AtUnitExample3 {
/* Output:
annotations.AtUnitExample3
. initialization
. methodOneTest
. m2 This is methodTwo
. methodOneTest
OK (3 tests)
*/

View File

@ -1,5 +1,5 @@
// annotations/AtUnitExample4.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {java onjava.atunit.AtUnit

View File

@ -1,5 +1,5 @@
// annotations/AtUnitExample5.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {java onjava.atunit.AtUnit
@ -14,8 +14,7 @@ public class AtUnitExample5 {
public AtUnitExample5(String text) {
this.text = text;
}
@Override
public String toString() { return text; }
@Override public String toString() { return text; }
@TestProperty
static PrintWriter output;
@TestProperty

View File

@ -1,5 +1,5 @@
// annotations/DemoProcessFiles.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import onjava.ProcessFiles;

View File

@ -1,5 +1,5 @@
// annotations/HashSetTest.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {java onjava.atunit.AtUnit
@ -29,8 +29,8 @@ public class HashSetTest {
}
/* Output:
annotations.HashSetTest
. tContains
. initialization
. tRemove
. tContains
OK (3 tests)
*/

View File

@ -1,5 +1,5 @@
// annotations/PasswordUtils.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// annotations/SimulatingNull.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.lang.annotation.*;

View File

@ -1,5 +1,5 @@
// annotations/StackL.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// A stack built on a LinkedList

View File

@ -1,5 +1,5 @@
// annotations/StackLStringTst.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Applying @Unit to generics
@ -35,8 +35,8 @@ StackLStringTst extends StackL<String> {
}
/* Output:
annotations.StackLStringTst
. tPop
. tTop
. tPush
. tPop
OK (3 tests)
*/

View File

@ -1,5 +1,5 @@
// annotations/Testable.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
package annotations;

View File

@ -1,5 +1,5 @@
// annotations/UseCase.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.lang.annotation.*;

View File

@ -1,5 +1,5 @@
// annotations/UseCaseTracker.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;
@ -27,11 +27,11 @@ public class UseCaseTracker {
}
}
/* Output:
Found Use Case 49
New passwords can't equal previously used ones
Found Use Case 48
no description
Found Use Case 47
Passwords must contain at least one numeric
Found Use Case 49
New passwords can't equal previously used ones
Missing use case 50
*/

View File

@ -1,5 +1,5 @@
// annotations/database/Constraints.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
package annotations.database;

View File

@ -1,5 +1,5 @@
// annotations/database/DBTable.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
package annotations.database;

View File

@ -1,5 +1,5 @@
// annotations/database/Member.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
package annotations.database;
@ -16,7 +16,8 @@ public class Member {
public String getReference() { return reference; }
public String getFirstName() { return firstName; }
public String getLastName() { return lastName; }
@Override
public String toString() { return reference; }
@Override public String toString() {
return reference;
}
public Integer getAge() { return age; }
}

View File

@ -1,5 +1,5 @@
// annotations/database/SQLInteger.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
package annotations.database;

View File

@ -1,5 +1,5 @@
// annotations/database/SQLString.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
package annotations.database;

View File

@ -1,5 +1,5 @@
// annotations/database/TableCreator.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Reflection-based annotation processor

View File

@ -1,5 +1,5 @@
// annotations/database/Uniqueness.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Sample of nested annotations

View File

@ -1,5 +1,5 @@
// annotations/ifx/ExtractInterface.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// javac-based annotation processing

View File

@ -1,5 +1,5 @@
// annotations/ifx/IfaceExtractorProcessor.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// javac-based annotation processing
@ -21,14 +21,12 @@ extends AbstractProcessor {
interfaceMethods = new ArrayList<>();
Elements elementUtils;
private ProcessingEnvironment processingEnv;
@Override
public void init(
@Override public void init(
ProcessingEnvironment processingEnv) {
this.processingEnv = processingEnv;
elementUtils = processingEnv.getElementUtils();
}
@Override
public boolean process(
@Override public boolean process(
Set<? extends TypeElement> annotations,
RoundEnvironment env) {
for(Element elem:env.getElementsAnnotatedWith(

View File

@ -1,5 +1,5 @@
// annotations/ifx/Multiplier.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// javac-based annotation processing

View File

@ -1,5 +1,5 @@
// annotations/simplest/Simple.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// A bare-bones annotation

View File

@ -1,5 +1,5 @@
// annotations/simplest/SimpleProcessor.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// A bare-bones annotation processor
@ -14,8 +14,7 @@ import java.util.*;
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class SimpleProcessor
extends AbstractProcessor {
@Override
public boolean process(
@Override public boolean process(
Set<? extends TypeElement> annotations,
RoundEnvironment env) {
for(TypeElement t : annotations)

View File

@ -1,5 +1,5 @@
// annotations/simplest/SimpleTest.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Test the "Simple" annotation

View File

@ -1,5 +1,5 @@
// arrays/AlphabeticSearch.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Searching with a Comparator import

View File

@ -1,5 +1,5 @@
// arrays/ArrayCopying.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Demonstrate Arrays.copy() and Arrays.copyOf()
@ -10,8 +10,7 @@ import static onjava.ArrayShow.*;
class Sup { // Superclass
private int id;
Sup(int n) { id = n; }
@Override
public String toString() {
@Override public String toString() {
return getClass().getSimpleName() + id;
}
}

View File

@ -1,5 +1,5 @@
// arrays/ArrayOfGenericType.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.

View File

@ -1,5 +1,5 @@
// arrays/ArrayOfGenerics.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// arrays/ArrayOptions.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Initialization & re-assignment of arrays

View File

@ -1,5 +1,5 @@
// arrays/ArraySearching.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Using Arrays.binarySearch()

View File

@ -1,5 +1,5 @@
// arrays/AssemblingMultidimensionalArrays.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Creating multidimensional arrays

View File

@ -1,5 +1,5 @@
// arrays/AutoboxingArrays.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// arrays/CollectionComparison.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;
@ -9,8 +9,7 @@ import static onjava.ArrayShow.*;
class BerylliumSphere {
private static long counter;
private final long id = counter++;
@Override
public String toString() {
@Override public String toString() {
return "Sphere " + id;
}
}

View File

@ -1,5 +1,5 @@
// arrays/CompType.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Implementing Comparable in a class
@ -16,15 +16,13 @@ public class CompType implements Comparable<CompType> {
i = n1;
j = n2;
}
@Override
public String toString() {
@Override public String toString() {
String result = "[i = " + i + ", j = " + j + "]";
if(count++ % 3 == 0)
result += "\n";
return result;
}
@Override
public int compareTo(CompType rv) {
@Override public int compareTo(CompType rv) {
return (i < rv.i ? -1 : (i == rv.i ? 0 : 1));
}
private static SplittableRandom r =

View File

@ -1,5 +1,5 @@
// arrays/ComparatorTest.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Implementing a Comparator for a class

View File

@ -1,5 +1,5 @@
// arrays/ComparingArrays.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Using Arrays.equals()

View File

@ -1,5 +1,5 @@
// arrays/CountUpward.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// arrays/FillingArrays.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Using Arrays.fill()

View File

@ -1,5 +1,5 @@
// arrays/IceCreamFlavors.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Returning arrays from methods

View File

@ -1,5 +1,5 @@
// arrays/ModifyExisting.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// arrays/MultiDimWrapperArray.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Multidimensional arrays of "wrapper" objects

View File

@ -1,5 +1,5 @@
// arrays/MultidimensionalObjectArrays.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// arrays/MultidimensionalPrimitiveArray.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// arrays/ParallelPrefix1.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// arrays/ParallelPrefix2.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// arrays/ParallelPrefix3.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {ExcludeFromTravisCI}

View File

@ -1,5 +1,5 @@
// arrays/ParallelSetAll.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// arrays/ParameterizedArrayType.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.

View File

@ -1,5 +1,5 @@
# arrays/PythonLists.py
# (c)2020 MindView LLC: see Copyright.txt
# (c)2021 MindView LLC: see Copyright.txt
# We make no guarantees that this code is fit for any purpose.
# Visit http://OnJava8.com for more book information.
@ -20,7 +20,7 @@ class MyList(list): # Inherit from list
reversed.reverse() # Built-in list method
return reversed
# No 'new' necessary for object creation:
# No 'new' necessary for object creation: {#24-no-new-necessary-for-object-creation}
list2 = MyList(aList)
print(type(list2)) # <class '__main__.MyList'>
print(list2.getReversed()) # [8, 7, 6, 5, 4, 3, 2, 1]

View File

@ -1,5 +1,5 @@
// arrays/RaggedArray.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// arrays/Reverse.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// The Collections.reverseOrder() Comparator

View File

@ -1,5 +1,5 @@
// arrays/SimpleSetAll.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;
@ -8,8 +8,9 @@ import static onjava.ArrayShow.*;
class Bob {
final int id;
Bob(int n) { id = n; }
@Override
public String toString() { return "Bob" + id; }
@Override public String toString() {
return "Bob" + id;
}
}
public class SimpleSetAll {

View File

@ -1,5 +1,5 @@
// arrays/StreamFromArray.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// arrays/StringSorting.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Sorting an array of Strings

View File

@ -1,5 +1,5 @@
// arrays/TestConvertTo.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// arrays/TestCount.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Test counting generators

View File

@ -1,5 +1,5 @@
// arrays/TestRand.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Test random generators

View File

@ -1,5 +1,5 @@
// arrays/ThreeDWithNew.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// arrays/jmh/ParallelSort.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
package arrays.jmh;

View File

@ -1,5 +1,5 @@
// collections/AdapterMethodIdiom.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// The "Adapter Method" idiom uses for-in
@ -15,10 +15,12 @@ class ReversibleArrayList<T> extends ArrayList<T> {
public Iterator<T> iterator() {
return new Iterator<T>() {
int current = size() - 1;
public boolean hasNext() {
@Override public boolean hasNext() {
return current > -1;
}
@Override
public T next() { return get(current--); }
@Override
public void remove() { // Not implemented
throw new UnsupportedOperationException();
}

View File

@ -1,5 +1,5 @@
// collections/AddingGroups.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Adding groups of elements to Collection objects

View File

@ -1,5 +1,5 @@
// collections/ApplesAndOrangesWithGenerics.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// collections/ApplesAndOrangesWithoutGenerics.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Simple collection use (suppressing compiler warnings)

View File

@ -1,5 +1,5 @@
// collections/ArrayIsNotIterable.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// collections/AsListInference.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// collections/CollectionDifferences.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import onjava.*;

View File

@ -1,5 +1,5 @@
// collections/CollectionSequence.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import typeinfo.pets.*;
@ -7,15 +7,13 @@ import java.util.*;
public class CollectionSequence
extends AbstractCollection<Pet> {
private Pet[] pets = Pets.array(8);
private Pet[] pets = new PetCreator().array(8);
@Override
public int size() { return pets.length; }
@Override
public Iterator<Pet> iterator() {
@Override public Iterator<Pet> iterator() {
return new Iterator<Pet>() { // [1]
private int index = 0;
@Override
public boolean hasNext() {
@Override public boolean hasNext() {
return index < pets.length;
}
@Override

View File

@ -1,5 +1,5 @@
// collections/CrossCollectionIteration.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import typeinfo.pets.*;
@ -14,7 +14,7 @@ public class CrossCollectionIteration {
System.out.println();
}
public static void main(String[] args) {
List<Pet> pets = Pets.list(8);
List<Pet> pets = new PetCreator().list(8);
LinkedList<Pet> petsLL = new LinkedList<>(pets);
HashSet<Pet> petsHS = new HashSet<>(pets);
TreeSet<Pet> petsTS = new TreeSet<>(pets);

View File

@ -1,5 +1,5 @@
// collections/CrossCollectionIteration2.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import typeinfo.pets.*;
@ -15,7 +15,7 @@ public class CrossCollectionIteration2 {
System.out.println();
}
public static void main(String[] args) {
List<Pet> pets = Pets.list(8);
List<Pet> pets = new PetCreator().list(8);
LinkedList<Pet> petsLL = new LinkedList<>(pets);
HashSet<Pet> petsHS = new HashSet<>(pets);
TreeSet<Pet> petsTS = new TreeSet<>(pets);

View File

@ -1,5 +1,5 @@
// collections/EnvironmentVariables.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {VisuallyInspectOutput}

View File

@ -1,5 +1,5 @@
// collections/ForInCollections.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// All collections work with for-in

View File

@ -1,5 +1,5 @@
// collections/GenericsAndUpcasting.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;
@ -21,8 +21,8 @@ public class GenericsAndUpcasting {
}
}
/* Output:
GrannySmith@15db9742
Gala@6d06d69c
Fuji@7852e922
Braeburn@4e25154f
GrannySmith@19e0bfd
Gala@139a55
Fuji@1db9742
Braeburn@106d69c
*/

View File

@ -1,5 +1,5 @@
// collections/InterfaceVsIterator.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import typeinfo.pets.*;
@ -19,7 +19,7 @@ public class InterfaceVsIterator {
System.out.println();
}
public static void main(String[] args) {
List<Pet> petList = Pets.list(8);
List<Pet> petList = new PetCreator().list(8);
Set<Pet> petSet = new HashSet<>(petList);
Map<String, Pet> petMap = new LinkedHashMap<>();
String[] names = ("Ralph, Eric, Robin, Lacey, " +

View File

@ -1,5 +1,5 @@
// collections/IterableClass.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Anything Iterable works with for-in
@ -9,12 +9,10 @@ public class IterableClass implements Iterable<String> {
protected String[] words = ("And that is how " +
"we know the Earth to be banana-shaped."
).split(" ");
@Override
public Iterator<String> iterator() {
@Override public Iterator<String> iterator() {
return new Iterator<String>() {
private int index = 0;
@Override
public boolean hasNext() {
@Override public boolean hasNext() {
return index < words.length;
}
@Override

View File

@ -1,5 +1,5 @@
// collections/LinkedListFeatures.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import typeinfo.pets.*;
@ -8,7 +8,7 @@ import java.util.*;
public class LinkedListFeatures {
public static void main(String[] args) {
LinkedList<Pet> pets =
new LinkedList<>(Pets.list(5));
new LinkedList<>(new PetCreator().list(5));
System.out.println(pets);
// Identical:
System.out.println(
@ -27,9 +27,9 @@ public class LinkedListFeatures {
System.out.println(pets);
pets.addFirst(new Rat());
System.out.println("After addFirst(): " + pets);
pets.offer(Pets.get());
pets.offer(new PetCreator().get());
System.out.println("After offer(): " + pets);
pets.add(Pets.get());
pets.add(new PetCreator().get());
System.out.println("After add(): " + pets);
pets.addLast(new Hamster());
System.out.println("After addLast(): " + pets);
@ -47,8 +47,8 @@ pets.removeFirst(): Manx
pets.poll(): Cymric
[Mutt, Pug]
After addFirst(): [Rat, Mutt, Pug]
After offer(): [Rat, Mutt, Pug, Cymric]
After add(): [Rat, Mutt, Pug, Cymric, Pug]
After addLast(): [Rat, Mutt, Pug, Cymric, Pug, Hamster]
After offer(): [Rat, Mutt, Pug, Rat]
After add(): [Rat, Mutt, Pug, Rat, Rat]
After addLast(): [Rat, Mutt, Pug, Rat, Rat, Hamster]
pets.removeLast(): Hamster
*/

View File

@ -1,5 +1,5 @@
// collections/ListFeatures.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import typeinfo.pets.*;
@ -8,7 +8,7 @@ import java.util.*;
public class ListFeatures {
public static void main(String[] args) {
Random rand = new Random(47);
List<Pet> pets = Pets.list(7);
List<Pet> pets = new PetCreator().list(7);
System.out.println("1: " + pets);
Hamster h = new Hamster();
pets.add(h); // Automatically resizes
@ -54,7 +54,7 @@ public class ListFeatures {
pets.clear(); // Remove all elements
System.out.println("19: " + pets);
System.out.println("20: " + pets.isEmpty());
pets.addAll(Pets.list(4));
pets.addAll(new PetCreator().list(4));
System.out.println("21: " + pets);
Object[] o = pets.toArray();
System.out.println("22: " + o[3]);
@ -87,7 +87,7 @@ sub: [Mouse, Pug]
18: false
19: []
20: true
21: [Manx, Cymric, Rat, EgyptianMau]
22: EgyptianMau
21: [Rat, Manx, Cymric, Mutt]
22: Mutt
23: 14
*/

View File

@ -1,5 +1,5 @@
// collections/ListIteration.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import typeinfo.pets.*;
@ -7,7 +7,7 @@ import java.util.*;
public class ListIteration {
public static void main(String[] args) {
List<Pet> pets = Pets.list(8);
List<Pet> pets = new PetCreator().list(8);
ListIterator<Pet> it = pets.listIterator();
while(it.hasNext())
System.out.print(it.next() +
@ -22,7 +22,7 @@ public class ListIteration {
it = pets.listIterator(3);
while(it.hasNext()) {
it.next();
it.set(Pets.get());
it.set(new PetCreator().get());
}
System.out.println(pets);
}
@ -32,6 +32,5 @@ Rat, 1, 0; Manx, 2, 1; Cymric, 3, 2; Mutt, 4, 3; Pug,
5, 4; Cymric, 6, 5; Pug, 7, 6; Manx, 8, 7;
7 6 5 4 3 2 1 0
[Rat, Manx, Cymric, Mutt, Pug, Cymric, Pug, Manx]
[Rat, Manx, Cymric, Cymric, Rat, EgyptianMau, Hamster,
EgyptianMau]
[Rat, Manx, Cymric, Rat, Rat, Rat, Rat, Rat]
*/

View File

@ -1,5 +1,5 @@
// collections/MapOfList.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {java collections.MapOfList}

View File

@ -1,5 +1,5 @@
// collections/ModifyingArraysAsList.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// collections/MultiIterableClass.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Adding several Adapter Methods
@ -11,12 +11,13 @@ public class MultiIterableClass extends IterableClass {
public Iterator<String> iterator() {
return new Iterator<String>() {
int current = words.length - 1;
public boolean hasNext() {
@Override public boolean hasNext() {
return current > -1;
}
public String next() {
@Override public String next() {
return words[current--];
}
@Override
public void remove() { // Not implemented
throw new UnsupportedOperationException();
}

View File

@ -1,20 +1,19 @@
// collections/NonCollectionSequence.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import typeinfo.pets.*;
import java.util.*;
class PetSequence {
protected Pet[] pets = Pets.array(8);
protected Pet[] pets = new PetCreator().array(8);
}
public class NonCollectionSequence extends PetSequence {
public Iterator<Pet> iterator() {
return new Iterator<Pet>() {
private int index = 0;
@Override
public boolean hasNext() {
@Override public boolean hasNext() {
return index < pets.length;
}
@Override

View File

@ -1,5 +1,5 @@
// collections/PetMap.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import typeinfo.pets.*;

View File

@ -1,5 +1,5 @@
// collections/PrintingCollections.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Collections print themselves automatically

View File

@ -1,5 +1,5 @@
// collections/PriorityQueueDemo.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// collections/QueueDemo.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Upcasting to a Queue from a LinkedList

View File

@ -1,5 +1,5 @@
// collections/SetOfInteger.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// collections/SetOfString.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// collections/SetOperations.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// collections/SimpleCollection.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// collections/SimpleIteration.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import typeinfo.pets.*;
@ -7,7 +7,7 @@ import java.util.*;
public class SimpleIteration {
public static void main(String[] args) {
List<Pet> pets = Pets.list(12);
List<Pet> pets = new PetCreator().list(12);
Iterator<Pet> it = pets.iterator();
while(it.hasNext()) {
Pet p = it.next();

View File

@ -1,5 +1,5 @@
// collections/SortedSetOfString.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

View File

@ -1,5 +1,5 @@
// collections/StackCollision.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.

View File

@ -1,5 +1,5 @@
// collections/StackTest.java
// (c)2020 MindView LLC: see Copyright.txt
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;

Some files were not shown because too many files have changed in this diff Show More