Radically reorganized
Plus many new examples in "streams" chapter.
This commit is contained in:
parent
0edda16067
commit
bc0026c3e1
@ -31,8 +31,7 @@
|
|||||||
<exclude name="**/*.cpp" />
|
<exclude name="**/*.cpp" />
|
||||||
<exclude name="**/VendingMachineInput.txt" />
|
<exclude name="**/VendingMachineInput.txt" />
|
||||||
<exclude name="**/Trash.dat" />
|
<exclude name="**/Trash.dat" />
|
||||||
<exclude name="**/DDTrash.dat" />
|
<exclude name="**/Cheese.dat" />
|
||||||
<exclude name="**/VTrash.dat" />
|
|
||||||
<exclude name="**/log.prop"/>
|
<exclude name="**/log.prop"/>
|
||||||
<exclude name="**/runall.ps1" />
|
<exclude name="**/runall.ps1" />
|
||||||
</fileset>
|
</fileset>
|
||||||
|
@ -74,7 +74,13 @@
|
|||||||
<target name="base">
|
<target name="base">
|
||||||
<javac includeantruntime="false"
|
<javac includeantruntime="false"
|
||||||
classpath="${java.class.path};${basedir};${basedir}/.."
|
classpath="${java.class.path};${basedir};${basedir}/.."
|
||||||
srcdir="${basedir}/../com/mindviewinc/">
|
srcdir="${basedir}/../onjava/">
|
||||||
|
<compilerarg value="-Xmaxerrs"/>
|
||||||
|
<compilerarg value="10"/>
|
||||||
|
</javac>
|
||||||
|
<javac includeantruntime="false"
|
||||||
|
classpath="${java.class.path};${basedir};${basedir}/.."
|
||||||
|
srcdir="${basedir}/../com/">
|
||||||
<compilerarg value="-Xmaxerrs"/>
|
<compilerarg value="-Xmaxerrs"/>
|
||||||
<compilerarg value="10"/>
|
<compilerarg value="10"/>
|
||||||
</javac>
|
</javac>
|
||||||
@ -90,6 +96,12 @@
|
|||||||
<compilerarg value="-Xmaxerrs"/>
|
<compilerarg value="-Xmaxerrs"/>
|
||||||
<compilerarg value="10"/>
|
<compilerarg value="10"/>
|
||||||
</javac>
|
</javac>
|
||||||
|
<javac includeantruntime="false"
|
||||||
|
classpath="${java.class.path};${basedir};${basedir}/.."
|
||||||
|
srcdir="${basedir}/../enums/menu/">
|
||||||
|
<compilerarg value="-Xmaxerrs"/>
|
||||||
|
<compilerarg value="10"/>
|
||||||
|
</javac>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target
|
<target
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Creating non-embedded tests.
|
// Creating non-embedded tests.
|
||||||
package annotations;
|
package annotations;
|
||||||
import com.mindviewinc.atunit.*;
|
import com.mindviewinc.atunit.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class AtUnitComposition {
|
public class AtUnitComposition {
|
||||||
AtUnitExample1 testObject = new AtUnitExample1();
|
AtUnitExample1 testObject = new AtUnitExample1();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// annotations/AtUnitExample1.java
|
// annotations/AtUnitExample1.java
|
||||||
package annotations;
|
package annotations;
|
||||||
import com.mindviewinc.atunit.*;
|
import com.mindviewinc.atunit.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class AtUnitExample1 {
|
public class AtUnitExample1 {
|
||||||
public String methodOne() {
|
public String methodOne() {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
package annotations;
|
package annotations;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import com.mindviewinc.atunit.*;
|
import com.mindviewinc.atunit.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class AtUnitExample2 {
|
public class AtUnitExample2 {
|
||||||
public String methodOne() {
|
public String methodOne() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// annotations/AtUnitExample3.java
|
// annotations/AtUnitExample3.java
|
||||||
package annotations;
|
package annotations;
|
||||||
import com.mindviewinc.atunit.*;
|
import com.mindviewinc.atunit.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class AtUnitExample3 {
|
public class AtUnitExample3 {
|
||||||
private int n;
|
private int n;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
package annotations;
|
package annotations;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.atunit.*;
|
import com.mindviewinc.atunit.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class AtUnitExample4 {
|
public class AtUnitExample4 {
|
||||||
static String theory = "All brontosauruses " +
|
static String theory = "All brontosauruses " +
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
package annotations;
|
package annotations;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import com.mindviewinc.atunit.*;
|
import com.mindviewinc.atunit.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class AtUnitExample5 {
|
public class AtUnitExample5 {
|
||||||
private String text;
|
private String text;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Creating non-embedded tests.
|
// Creating non-embedded tests.
|
||||||
package annotations;
|
package annotations;
|
||||||
import com.mindviewinc.atunit.*;
|
import com.mindviewinc.atunit.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class AtUnitExternalTest extends AtUnitExample1 {
|
public class AtUnitExternalTest extends AtUnitExample1 {
|
||||||
@Test boolean _methodOne() {
|
@Test boolean _methodOne() {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
package annotations;
|
package annotations;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.atunit.*;
|
import com.mindviewinc.atunit.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class HashSetTest {
|
public class HashSetTest {
|
||||||
HashSet<String> testObject = new HashSet<>();
|
HashSet<String> testObject = new HashSet<>();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Applying @Unit to generics.
|
// Applying @Unit to generics.
|
||||||
package annotations;
|
package annotations;
|
||||||
import com.mindviewinc.atunit.*;
|
import com.mindviewinc.atunit.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class StackLStringTest extends StackL<String> {
|
public class StackLStringTest extends StackL<String> {
|
||||||
@Test void _push() {
|
@Test void _push() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// arrays/AlphabeticSearch.java
|
// arrays/AlphabeticSearch.java
|
||||||
// Searching with a Comparator.
|
// Searching with a Comparator.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class AlphabeticSearch {
|
public class AlphabeticSearch {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -7,6 +7,7 @@ public class ArrayOptions {
|
|||||||
// Arrays of objects:
|
// Arrays of objects:
|
||||||
BerylliumSphere[] a; // Local uninitialized variable
|
BerylliumSphere[] a; // Local uninitialized variable
|
||||||
BerylliumSphere[] b = new BerylliumSphere[5];
|
BerylliumSphere[] b = new BerylliumSphere[5];
|
||||||
|
|
||||||
// The references inside the array are
|
// The references inside the array are
|
||||||
// automatically initialized to null:
|
// automatically initialized to null:
|
||||||
System.out.println("b: " + Arrays.toString(b));
|
System.out.println("b: " + Arrays.toString(b));
|
||||||
@ -14,14 +15,17 @@ public class ArrayOptions {
|
|||||||
for(int i = 0; i < c.length; i++)
|
for(int i = 0; i < c.length; i++)
|
||||||
if(c[i] == null) // Can test for null reference
|
if(c[i] == null) // Can test for null reference
|
||||||
c[i] = new BerylliumSphere();
|
c[i] = new BerylliumSphere();
|
||||||
|
|
||||||
// Aggregate initialization:
|
// Aggregate initialization:
|
||||||
BerylliumSphere[] d = { new BerylliumSphere(),
|
BerylliumSphere[] d = { new BerylliumSphere(),
|
||||||
new BerylliumSphere(), new BerylliumSphere()
|
new BerylliumSphere(), new BerylliumSphere()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Dynamic aggregate initialization:
|
// Dynamic aggregate initialization:
|
||||||
a = new BerylliumSphere[]{
|
a = new BerylliumSphere[]{
|
||||||
new BerylliumSphere(), new BerylliumSphere(),
|
new BerylliumSphere(), new BerylliumSphere(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// (Trailing comma is optional in both cases)
|
// (Trailing comma is optional in both cases)
|
||||||
System.out.println("a.length = " + a.length);
|
System.out.println("a.length = " + a.length);
|
||||||
System.out.println("b.length = " + b.length);
|
System.out.println("b.length = " + b.length);
|
||||||
@ -33,6 +37,7 @@ public class ArrayOptions {
|
|||||||
// Arrays of primitives:
|
// Arrays of primitives:
|
||||||
int[] e; // Null reference
|
int[] e; // Null reference
|
||||||
int[] f = new int[5];
|
int[] f = new int[5];
|
||||||
|
|
||||||
// The primitives inside the array are
|
// The primitives inside the array are
|
||||||
// automatically initialized to zero:
|
// automatically initialized to zero:
|
||||||
System.out.println("f: " + Arrays.toString(f));
|
System.out.println("f: " + Arrays.toString(f));
|
||||||
@ -40,6 +45,7 @@ public class ArrayOptions {
|
|||||||
for(int i = 0; i < g.length; i++)
|
for(int i = 0; i < g.length; i++)
|
||||||
g[i] = i*i;
|
g[i] = i*i;
|
||||||
int[] h = { 11, 47, 93 };
|
int[] h = { 11, 47, 93 };
|
||||||
|
|
||||||
// Compile error: variable e not initialized:
|
// Compile error: variable e not initialized:
|
||||||
//!print("e.length = " + e.length);
|
//!print("e.length = " + e.length);
|
||||||
System.out.println("f.length = " + f.length);
|
System.out.println("f.length = " + f.length);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Using Arrays.binarySearch().
|
// Using Arrays.binarySearch().
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class ArraySearching {
|
public class ArraySearching {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Implementing Comparable in a class.
|
// Implementing Comparable in a class.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class CompType implements Comparable<CompType> {
|
public class CompType implements Comparable<CompType> {
|
||||||
int i;
|
int i;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// arrays/ComparatorTest.java
|
// arrays/ComparatorTest.java
|
||||||
// Implementing a Comparator for a class.
|
// Implementing a Comparator for a class.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
class CompTypeComparator implements Comparator<CompType> {
|
class CompTypeComparator implements Comparator<CompType> {
|
||||||
public int compare(CompType o1, CompType o2) {
|
public int compare(CompType o1, CompType o2) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// arrays/PrimitiveConversionDemonstration.java
|
// arrays/PrimitiveConversionDemonstration.java
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class PrimitiveConversionDemonstration {
|
public class PrimitiveConversionDemonstration {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// arrays/RandomSuppliersTest.java
|
// arrays/RandomSuppliersTest.java
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class RandomSuppliersTest {
|
public class RandomSuppliersTest {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// arrays/Reverse.java
|
// arrays/Reverse.java
|
||||||
// The Collections.reverseOrder() Comparator
|
// The Collections.reverseOrder() Comparator
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class Reverse {
|
public class Reverse {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// arrays/StringSorting.java
|
// arrays/StringSorting.java
|
||||||
// Sorting an array of Strings.
|
// Sorting an array of Strings.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class StringSorting {
|
public class StringSorting {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// arrays/SuppliersTest.java
|
// arrays/SuppliersTest.java
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class SuppliersTest {
|
public class SuppliersTest {
|
||||||
public static int size = 10;
|
public static int size = 10;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// arrays/TestArrayGeneration.java
|
// arrays/TestArrayGeneration.java
|
||||||
// Test the tools that use generators to fill arrays.
|
// Test the tools that use generators to fill arrays.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class TestArrayGeneration {
|
public class TestArrayGeneration {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// arrays/TestGenerated.java
|
// arrays/TestGenerated.java
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class TestGenerated {
|
public class TestGenerated {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
19
build.xml
19
build.xml
@ -30,28 +30,35 @@
|
|||||||
polymorphism/build.xml
|
polymorphism/build.xml
|
||||||
interfaces/build.xml
|
interfaces/build.xml
|
||||||
innerclasses/build.xml
|
innerclasses/build.xml
|
||||||
|
functions/build.xml
|
||||||
containers/build.xml
|
containers/build.xml
|
||||||
|
streams/build.xml
|
||||||
exceptions/build.xml
|
exceptions/build.xml
|
||||||
strings/build.xml
|
strings/build.xml
|
||||||
typeinfo/build.xml
|
typeinfo/build.xml
|
||||||
generics/build.xml
|
generics/build.xml
|
||||||
arrays/build.xml
|
arrays/build.xml
|
||||||
containersindepth/build.xml
|
containersindepth/build.xml
|
||||||
io/build.xml
|
files/build.xml
|
||||||
xml/build.xml
|
|
||||||
enums/build.xml
|
enums/build.xml
|
||||||
annotations/build.xml
|
annotations/build.xml
|
||||||
concurrency/build.xml
|
concurrency/build.xml
|
||||||
ui/build.xml
|
ui/build.xml
|
||||||
swt/build.xml
|
swt/build.xml
|
||||||
patterns/build.xml
|
patterns/build.xml
|
||||||
references/build.xml
|
|
||||||
assertions/build.xml
|
|
||||||
unittesting/build.xml
|
unittesting/build.xml
|
||||||
debugging/build.xml
|
assertions/build.xml
|
||||||
logging/build.xml
|
references/build.xml
|
||||||
|
iostreams/build.xml
|
||||||
|
standardio/build.xml
|
||||||
|
newio/build.xml
|
||||||
|
compression/build.xml
|
||||||
|
serialization/build.xml
|
||||||
|
preferences/build.xml
|
||||||
network/build.xml
|
network/build.xml
|
||||||
remote/build.xml
|
remote/build.xml
|
||||||
|
logging/build.xml
|
||||||
|
debugging/build.xml
|
||||||
staticchecking/build.xml
|
staticchecking/build.xml
|
||||||
"/>
|
"/>
|
||||||
|
|
||||||
|
@ -9,13 +9,6 @@
|
|||||||
<target name="run" description="Compile and run" depends="build">
|
<target name="run" description="Compile and run" depends="build">
|
||||||
<jrun cls="com.mindviewinc.atunit.AtUnit" dirpath="../com/mindviewinc/atunit" />
|
<jrun cls="com.mindviewinc.atunit.AtUnit" dirpath="../com/mindviewinc/atunit" />
|
||||||
<jrun cls="com.mindviewinc.atunit.ClassNameFinder" dirpath="../com/mindviewinc/atunit" />
|
<jrun cls="com.mindviewinc.atunit.ClassNameFinder" dirpath="../com/mindviewinc/atunit" />
|
||||||
<jrun cls="com.mindviewinc.util.ContainerMethodDifferences" dirpath="../com/mindviewinc/util" />
|
|
||||||
<jrun cls="com.mindviewinc.util.CountingIntegerList" dirpath="../com/mindviewinc/util" />
|
|
||||||
<jrun cls="com.mindviewinc.util.CountingMapData" dirpath="../com/mindviewinc/util" />
|
|
||||||
<jrun cls="com.mindviewinc.util.Countries" dirpath="../com/mindviewinc/util" />
|
|
||||||
<jrun cls="com.mindviewinc.util.Directory" dirpath="../com/mindviewinc/util" />
|
|
||||||
<jrun cls="com.mindviewinc.util.Hex" dirpath="../com/mindviewinc/util" />
|
|
||||||
<jrun cls="com.mindviewinc.util.TextFile" dirpath="../com/mindviewinc/util" />
|
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -4,7 +4,7 @@ package com.mindviewinc.atunit;
|
|||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class AtUnit implements ProcessFiles.Strategy {
|
public class AtUnit implements ProcessFiles.Strategy {
|
||||||
static Class<?> testClass;
|
static Class<?> testClass;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
package com.mindviewinc.atunit;
|
package com.mindviewinc.atunit;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class ClassNameFinder {
|
public class ClassNameFinder {
|
||||||
public static String thisClass(byte[] classBytes) {
|
public static String thisClass(byte[] classBytes) {
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
// com/mindviewinc/util/FiveTuple.java
|
|
||||||
package com.mindviewinc.util;
|
|
||||||
|
|
||||||
public class FiveTuple<A, B, C, D, E>
|
|
||||||
extends FourTuple<A, B, C, D> {
|
|
||||||
public final E fifth;
|
|
||||||
public FiveTuple(A a, B b, C c, D d, E e) {
|
|
||||||
super(a, b, c, d);
|
|
||||||
fifth = e;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "(" + first + ", " + second + ", " +
|
|
||||||
third + ", " + fourth + ", " + fifth + ")";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
// com/mindviewinc/util/FourTuple.java
|
|
||||||
package com.mindviewinc.util;
|
|
||||||
|
|
||||||
public class FourTuple<A, B, C, D>
|
|
||||||
extends ThreeTuple<A, B, C> {
|
|
||||||
public final D fourth;
|
|
||||||
public FourTuple(A a, B b, C c, D d) {
|
|
||||||
super(a, b, c);
|
|
||||||
fourth = d;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "(" + first + ", " + second + ", " +
|
|
||||||
third + ", " + fourth + ")";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
// com/mindviewinc/util/Null.java
|
|
||||||
package com.mindviewinc.util;
|
|
||||||
public interface Null {}
|
|
@ -1,14 +0,0 @@
|
|||||||
// com/mindviewinc/util/ThreeTuple.java
|
|
||||||
package com.mindviewinc.util;
|
|
||||||
|
|
||||||
public class ThreeTuple<A,B,C> extends TwoTuple<A, B> {
|
|
||||||
public final C third;
|
|
||||||
public ThreeTuple(A a, B b, C c) {
|
|
||||||
super(a, b);
|
|
||||||
third = c;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "(" + first + ", " + second + ", " + third +")";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
// com/mindviewinc/util/Tuple.java
|
|
||||||
// Tuple library using type argument inference.
|
|
||||||
package com.mindviewinc.util;
|
|
||||||
|
|
||||||
public class Tuple {
|
|
||||||
public static <A, B> TwoTuple<A, B> tuple(A a, B b) {
|
|
||||||
return new TwoTuple<>(a, b);
|
|
||||||
}
|
|
||||||
public static <A, B, C> ThreeTuple<A, B, C>
|
|
||||||
tuple(A a, B b, C c) {
|
|
||||||
return new ThreeTuple<>(a, b, c);
|
|
||||||
}
|
|
||||||
public static <A, B, C, D> FourTuple<A, B, C, D>
|
|
||||||
tuple(A a, B b, C c, D d) {
|
|
||||||
return new FourTuple<>(a, b, c, d);
|
|
||||||
}
|
|
||||||
public static <A, B, C, D, E>
|
|
||||||
FiveTuple<A, B, C, D, E> tuple(A a, B b, C c, D d, E e) {
|
|
||||||
return new FiveTuple<>(a, b, c, d, e);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
// com/mindviewinc/util/TwoTuple.java
|
|
||||||
package com.mindviewinc.util;
|
|
||||||
|
|
||||||
public class TwoTuple<A, B> {
|
|
||||||
public final A first;
|
|
||||||
public final B second;
|
|
||||||
public TwoTuple(A a, B b) { first = a; second = b; }
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "(" + first + ", " + second + ")";
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,7 +2,7 @@
|
|||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class AtomicIntegerTest implements Runnable {
|
public class AtomicIntegerTest implements Runnable {
|
||||||
private AtomicInteger i = new AtomicInteger(0);
|
private AtomicInteger i = new AtomicInteger(0);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// concurrency/DaemonFromFactory.java
|
// concurrency/DaemonFromFactory.java
|
||||||
// Using a Thread Factory to create daemons.
|
// Using a Thread Factory to create daemons.
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class DaemonFromFactory implements Runnable {
|
public class DaemonFromFactory implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
class ExchangerProducer<T> implements Runnable {
|
class ExchangerProducer<T> implements Runnable {
|
||||||
private Supplier<T> generator;
|
private Supplier<T> generator;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// Rough comparison of thread-safe List performance.
|
// Rough comparison of thread-safe List performance.
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
abstract class ListTest extends Tester<List<Integer>> {
|
abstract class ListTest extends Tester<List<Integer>> {
|
||||||
ListTest(String testId, int nReaders, int nWriters) {
|
ListTest(String testId, int nReaders, int nWriters) {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// Rough comparison of thread-safe Map performance.
|
// Rough comparison of thread-safe Map performance.
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
abstract class MapTest
|
abstract class MapTest
|
||||||
extends Tester<Map<Integer,Integer>> {
|
extends Tester<Map<Integer,Integer>> {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// concurrency/Tester.java
|
// concurrency/Tester.java
|
||||||
// Framework to test performance of concurrency containers.
|
// Framework to test performance of concurrency containers.
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public abstract class Tester<C> {
|
public abstract class Tester<C> {
|
||||||
static int testReps = 10;
|
static int testReps = 10;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// containers/AdapterMethodIdiom.java
|
// containers/AdapterMethodIdiom.java
|
||||||
// The "Adapter Method" idiom uses for-each
|
// The "Adapter Method" idiom uses for-in
|
||||||
// with additional kinds of Iterables.
|
// with additional kinds of Iterables.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ public class ApplesAndOrangesWithGenerics {
|
|||||||
for(Apple apple : apples) {
|
for(Apple apple : apples) {
|
||||||
System.out.println(apple.id());
|
System.out.println(apple.id());
|
||||||
}
|
}
|
||||||
// Using for-each:
|
// Using for-in:
|
||||||
for(Apple c : apples)
|
for(Apple c : apples)
|
||||||
System.out.println(c.id());
|
System.out.println(c.id());
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ public class ArrayIsNotIterable {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
test(Arrays.asList(1, 2, 3));
|
test(Arrays.asList(1, 2, 3));
|
||||||
String[] strings = { "A", "B", "C" };
|
String[] strings = { "A", "B", "C" };
|
||||||
// An array works in for-each, but it's not Iterable:
|
// An array works in for-in, but it's not Iterable:
|
||||||
//! test(strings);
|
//! test(strings);
|
||||||
// You must explicitly convert it to an Iterable:
|
// You must explicitly convert it to an Iterable:
|
||||||
test(Arrays.asList(strings));
|
test(Arrays.asList(strings));
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// containers/ContainerMethods.java
|
// containers/ContainerMethods.java
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class ContainerMethods {
|
public class ContainerMethods {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -8,7 +8,7 @@ public class ContainerMethods {
|
|||||||
}
|
}
|
||||||
/* Output:
|
/* Output:
|
||||||
Collection: [add, addAll, clear, contains, containsAll,
|
Collection: [add, addAll, clear, contains, containsAll,
|
||||||
equals, for-each, hashCode, isEmpty, iterator,
|
equals, forEach, hashCode, isEmpty, iterator,
|
||||||
parallelStream, remove, removeAll, removeIf, retainAll,
|
parallelStream, remove, removeAll, removeIf, retainAll,
|
||||||
size, spliterator, stream, toArray]
|
size, spliterator, stream, toArray]
|
||||||
Interfaces in Collection: [Iterable]
|
Interfaces in Collection: [Iterable]
|
||||||
@ -42,7 +42,7 @@ Interfaces in Queue: [Collection]
|
|||||||
PriorityQueue extends Queue, adds: [comparator]
|
PriorityQueue extends Queue, adds: [comparator]
|
||||||
Interfaces in PriorityQueue: [Serializable]
|
Interfaces in PriorityQueue: [Serializable]
|
||||||
Map: [clear, compute, computeIfAbsent, computeIfPresent,
|
Map: [clear, compute, computeIfAbsent, computeIfPresent,
|
||||||
containsKey, containsValue, entrySet, equals, for-each, get,
|
containsKey, containsValue, entrySet, equals, forEach, get,
|
||||||
getOrDefault, hashCode, isEmpty, keySet, merge, put,
|
getOrDefault, hashCode, isEmpty, keySet, merge, put,
|
||||||
putAll, putIfAbsent, remove, replace, replaceAll, size,
|
putAll, putIfAbsent, remove, replace, replaceAll, size,
|
||||||
values]
|
values]
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// containers/ForEachCollections.java
|
// containers/ForInCollections.java
|
||||||
// All collections work with for-each.
|
// All collections work with for-in.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class ForEachCollections {
|
public class ForInCollections {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Collection<String> cs = new LinkedList<>();
|
Collection<String> cs = new LinkedList<>();
|
||||||
Collections.addAll(cs,
|
Collections.addAll(cs,
|
@ -1,5 +1,5 @@
|
|||||||
// containers/IterableClass.java
|
// containers/IterableClass.java
|
||||||
// Anything Iterable works with for-each.
|
// Anything Iterable works with for-in.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class IterableClass implements Iterable<String> {
|
public class IterableClass implements Iterable<String> {
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
public class StackCollision {
|
public class StackCollision {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
com.mindviewinc.util.Stack<String> stack =
|
onjava.Stack<String> stack = new onjava.Stack<>();
|
||||||
new com.mindviewinc.util.Stack<>();
|
|
||||||
for(String s : "My dog has fleas".split(" "))
|
for(String s : "My dog has fleas".split(" "))
|
||||||
stack.push(s);
|
stack.push(s);
|
||||||
while(!stack.empty())
|
while(!stack.empty())
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// containers/StackTest.java
|
// containers/StackTest.java
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class StackTest {
|
public class StackTest {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// containers/UniqueWords.java
|
// containers/UniqueWords.java
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class UniqueWords {
|
public class UniqueWords {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// containers/UniqueWordsAlphabetic.java
|
// containers/UniqueWordsAlphabetic.java
|
||||||
// Producing an alphabetic listing.
|
// Producing an alphabetic listing.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class UniqueWordsAlphabetic {
|
public class UniqueWordsAlphabetic {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<jrun cls="ContainerMethods" />
|
<jrun cls="ContainerMethods" />
|
||||||
<jrun cls="CrossContainerIteration" />
|
<jrun cls="CrossContainerIteration" />
|
||||||
<jrun cls="EnvironmentVariables" />
|
<jrun cls="EnvironmentVariables" />
|
||||||
<jrun cls="ForEachCollections" />
|
<jrun cls="ForInCollections" />
|
||||||
<jrun cls="GenericsAndUpcasting" />
|
<jrun cls="GenericsAndUpcasting" />
|
||||||
<jrun cls="InterfaceVsIterator" />
|
<jrun cls="InterfaceVsIterator" />
|
||||||
<jrun cls="IterableClass" />
|
<jrun cls="IterableClass" />
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// containersindepth/CollectionDataGeneration.java
|
// containersindepth/CollectionDataGeneration.java
|
||||||
// Using the Suppliers defined in the Arrays chapter.
|
// Using the Suppliers defined in the Arrays chapter.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class CollectionDataGeneration {
|
public class CollectionDataGeneration {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// containersindepth/CollectionDataTest.java
|
// containersindepth/CollectionDataTest.java
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
class Government implements Supplier<String> {
|
class Government implements Supplier<String> {
|
||||||
String[] foundation = ("strange women lying in ponds " +
|
String[] foundation = ("strange women lying in ponds " +
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// containersindepth/CollectionMethods.java
|
// containersindepth/CollectionMethods.java
|
||||||
// Things you can do with all Collections.
|
// Things you can do with all Collections.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class CollectionMethods {
|
public class CollectionMethods {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -11,7 +11,7 @@ public class CountedString {
|
|||||||
s = str;
|
s = str;
|
||||||
created.add(s);
|
created.add(s);
|
||||||
// id is the total number of instances
|
// id is the total number of instances
|
||||||
// of this string in use by CountedString:
|
// of this String in use by CountedString:
|
||||||
for(String s2 : created)
|
for(String s2 : created)
|
||||||
if(s2.equals(s))
|
if(s2.equals(s))
|
||||||
id++;
|
id++;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// containersindepth/DequeTest.java
|
// containersindepth/DequeTest.java
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class DequeTest {
|
public class DequeTest {
|
||||||
static void fillTest(Deque<Integer> deque) {
|
static void fillTest(Deque<Integer> deque) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// containersindepth/Enumerations.java
|
// containersindepth/Enumerations.java
|
||||||
// Java 1.0/1.1 Vector and Enumeration.
|
// Java 1.0/1.1 Vector and Enumeration.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class Enumerations {
|
public class Enumerations {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// containersindepth/LinkedHashMapDemo.java
|
// containersindepth/LinkedHashMapDemo.java
|
||||||
// What you can do with a LinkedHashMap.
|
// What you can do with a LinkedHashMap.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class LinkedHashMapDemo {
|
public class LinkedHashMapDemo {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Demonstrates performance differences in Lists.
|
// Demonstrates performance differences in Lists.
|
||||||
// {Args: 100 500} Small to keep build testing short
|
// {Args: 100 500} Small to keep build testing short
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class ListPerformance {
|
public class ListPerformance {
|
||||||
static Random rand = new Random();
|
static Random rand = new Random();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// containersindepth/Lists.java
|
// containersindepth/Lists.java
|
||||||
// Things you can do with Lists.
|
// Things you can do with Lists.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class Lists {
|
public class Lists {
|
||||||
private static boolean b;
|
private static boolean b;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// containersindepth/MapDataTest.java
|
// containersindepth/MapDataTest.java
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
class Letters implements Supplier<Pair<Integer,String>>,
|
class Letters implements Supplier<Pair<Integer,String>>,
|
||||||
Iterable<Integer> {
|
Iterable<Integer> {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Things you can do with Maps.
|
// Things you can do with Maps.
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class Maps {
|
public class Maps {
|
||||||
public static void printKeys(Map<Integer,String> map) {
|
public static void printKeys(Map<Integer,String> map) {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class QueueBehavior {
|
public class QueueBehavior {
|
||||||
private static int count = 10;
|
private static int count = 10;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// containersindepth/ReadOnly.java
|
// containersindepth/ReadOnly.java
|
||||||
// Using the Collections.unmodifiable methods.
|
// Using the Collections.unmodifiable methods.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class ReadOnly {
|
public class ReadOnly {
|
||||||
static Collection<String> data =
|
static Collection<String> data =
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// containersindepth/SimpleHashMap.java
|
// containersindepth/SimpleHashMap.java
|
||||||
// A demonstration hashed Map.
|
// A demonstration hashed Map.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class SimpleHashMap<K, V> extends AbstractMap<K, V> {
|
public class SimpleHashMap<K, V> extends AbstractMap<K, V> {
|
||||||
// Choose a prime number for the hash table
|
// Choose a prime number for the hash table
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// containersindepth/SlowMap.java
|
// containersindepth/SlowMap.java
|
||||||
// A Map implemented with ArrayLists.
|
// A Map implemented with ArrayLists.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class SlowMap<K, V> extends AbstractMap<K, V> {
|
public class SlowMap<K, V> extends AbstractMap<K, V> {
|
||||||
private List<K> keys = new ArrayList<>();
|
private List<K> keys = new ArrayList<>();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// containersindepth/SortedMapDemo.java
|
// containersindepth/SortedMapDemo.java
|
||||||
// What you can do with a TreeMap.
|
// What you can do with a TreeMap.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class SortedMapDemo {
|
public class SortedMapDemo {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -28,8 +28,8 @@ public class Stacks {
|
|||||||
|
|
||||||
// Using the Stack class from
|
// Using the Stack class from
|
||||||
// the Containers Chapter:
|
// the Containers Chapter:
|
||||||
com.mindviewinc.util.Stack<String> stack2 =
|
onjava.Stack<String> stack2 =
|
||||||
new com.mindviewinc.util.Stack<>();
|
new onjava.Stack<>();
|
||||||
for(Month m : Month.values())
|
for(Month m : Month.values())
|
||||||
stack2.push(m.toString());
|
stack2.push(m.toString());
|
||||||
System.out.println("stack2 = " + stack2);
|
System.out.println("stack2 = " + stack2);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// control/BreakAndContinue.java
|
// control/BreakAndContinue.java
|
||||||
// Demonstrates break and continue keywords.
|
// Demonstrates break and continue keywords.
|
||||||
import static com.mindviewinc.util.Range.*;
|
import static onjava.Range.*;
|
||||||
|
|
||||||
public class BreakAndContinue {
|
public class BreakAndContinue {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -10,7 +10,7 @@ public class BreakAndContinue {
|
|||||||
System.out.println(i + " ");
|
System.out.println(i + " ");
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
// Using forEach:
|
// Using for-in:
|
||||||
for(int i : range(100)) {
|
for(int i : range(100)) {
|
||||||
if(i == 74) break; // Out of for loop
|
if(i == 74) break; // Out of for loop
|
||||||
if(i % 9 != 0) continue; // Next iteration
|
if(i % 9 != 0) continue; // Next iteration
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// control/ForEachFloat.java
|
// control/ForInFloat.java
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class ForEachFloat {
|
public class ForInFloat {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Random rand = new Random(47);
|
Random rand = new Random(47);
|
||||||
float f[] = new float[10];
|
float f[] = new float[10];
|
@ -1,7 +1,7 @@
|
|||||||
// control/ForEachInt.java
|
// control/ForInInt.java
|
||||||
import static com.mindviewinc.util.Range.*;
|
import static onjava.Range.*;
|
||||||
|
|
||||||
public class ForEachInt {
|
public class ForInInt {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
for(int i : range(10)) // 0..9
|
for(int i : range(10)) // 0..9
|
||||||
System.out.print(i + " ");
|
System.out.print(i + " ");
|
||||||
@ -12,10 +12,14 @@ public class ForEachInt {
|
|||||||
for(int i : range(5, 20, 3)) // 5..20 step 3
|
for(int i : range(5, 20, 3)) // 5..20 step 3
|
||||||
System.out.print(i + " ");
|
System.out.print(i + " ");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
for(int i : range(20, 5, -3)) // Count down
|
||||||
|
System.out.print(i + " ");
|
||||||
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Output:
|
/* Output:
|
||||||
0 1 2 3 4 5 6 7 8 9
|
0 1 2 3 4 5 6 7 8 9
|
||||||
5 6 7 8 9
|
5 6 7 8 9
|
||||||
5 8 11 14 17
|
5 8 11 14 17
|
||||||
|
20 17 14 11 8
|
||||||
*/
|
*/
|
@ -1,6 +1,6 @@
|
|||||||
// control/ForEachString.java
|
// control/ForInString.java
|
||||||
|
|
||||||
public class ForEachString {
|
public class ForInString {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
for(char c : "An African Swallow".toCharArray())
|
for(char c : "An African Swallow".toCharArray())
|
||||||
System.out.println(c + " ");
|
System.out.println(c + " ");
|
@ -9,9 +9,9 @@
|
|||||||
<target name="run" description="Compile and run" depends="build">
|
<target name="run" description="Compile and run" depends="build">
|
||||||
<jrun cls="BreakAndContinue" />
|
<jrun cls="BreakAndContinue" />
|
||||||
<jrun cls="CommaOperator" />
|
<jrun cls="CommaOperator" />
|
||||||
<jrun cls="ForEachFloat" />
|
<jrun cls="ForInFloat" />
|
||||||
<jrun cls="ForEachInt" />
|
<jrun cls="ForInInt" />
|
||||||
<jrun cls="ForEachString" />
|
<jrun cls="ForInString" />
|
||||||
<jrun cls="IfElse" />
|
<jrun cls="IfElse" />
|
||||||
<jrun cls="IfElse2" />
|
<jrun cls="IfElse2" />
|
||||||
<jrun cls="LabeledFor" />
|
<jrun cls="LabeledFor" />
|
||||||
|
@ -14,7 +14,7 @@ public class EnumClass {
|
|||||||
System.out.println(s.name());
|
System.out.println(s.name());
|
||||||
System.out.println("----------------------");
|
System.out.println("----------------------");
|
||||||
}
|
}
|
||||||
// Produce an enum value from a string name:
|
// Produce an enum value from a String name:
|
||||||
for(String s : "HANGING CRAWLING GROUND".split(" ")) {
|
for(String s : "HANGING CRAWLING GROUND".split(" ")) {
|
||||||
Shrubbery shrub = Enum.valueOf(Shrubbery.class, s);
|
Shrubbery shrub = Enum.valueOf(Shrubbery.class, s);
|
||||||
System.out.println(shrub);
|
System.out.println(shrub);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// enums/PostOffice.java
|
// enums/PostOffice.java
|
||||||
// Modeling a post office.
|
// Modeling a post office.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
class Mail {
|
class Mail {
|
||||||
// The NO's lower the probability of random selection:
|
// The NO's lower the probability of random selection:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// enums/RandomTest.java
|
// enums/RandomTest.java
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
enum Activity { SITTING, LYING, STANDING, HOPPING,
|
enum Activity { SITTING, LYING, STANDING, HOPPING,
|
||||||
RUNNING, DODGING, JUMPING, FALLING, FLYING }
|
RUNNING, DODGING, JUMPING, FALLING, FLYING }
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Analyzing enums using reflection.
|
// Analyzing enums using reflection.
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
enum Explore { HERE, THERE }
|
enum Explore { HERE, THERE }
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// enums/RoShamBo.java
|
// enums/RoShamBo.java
|
||||||
// Common tools for RoShamBo examples.
|
// Common tools for RoShamBo examples.
|
||||||
package enums;
|
package enums;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class RoShamBo {
|
public class RoShamBo {
|
||||||
public static <T extends Competitor<T>>
|
public static <T extends Competitor<T>>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// enums/SecurityCategory.java
|
// enums/SecurityCategory.java
|
||||||
// More succinct subcategorization of enums.
|
// More succinct subcategorization of enums.
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
enum SecurityCategory {
|
enum SecurityCategory {
|
||||||
STOCK(Security.Stock.class), BOND(Security.Bond.class);
|
STOCK(Security.Stock.class), BOND(Security.Bond.class);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// {Args: VendingMachineInput.txt}
|
// {Args: VendingMachineInput.txt}
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
enum Category {
|
enum Category {
|
||||||
MONEY(Input.NICKEL, Input.DIME,
|
MONEY(Input.NICKEL, Input.DIME,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// enums/menu/Course.java
|
// enums/menu/Course.java
|
||||||
package enums.menu;
|
package enums.menu;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public enum Course {
|
public enum Course {
|
||||||
APPETIZER(Food.Appetizer.class),
|
APPETIZER(Food.Appetizer.class),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// enums/menu/Meal2.java
|
// enums/menu/Meal2.java
|
||||||
package enums.menu;
|
package enums.menu;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public enum Meal2 {
|
public enum Meal2 {
|
||||||
APPETIZER(Food.Appetizer.class),
|
APPETIZER(Food.Appetizer.class),
|
||||||
|
@ -89,7 +89,8 @@ public class DynamicFields {
|
|||||||
df.setField("d", "A new value for d");
|
df.setField("d", "A new value for d");
|
||||||
df.setField("number3", 11);
|
df.setField("number3", 11);
|
||||||
System.out.println("df: " + df);
|
System.out.println("df: " + df);
|
||||||
System.out.println("df.getField(\"d\") : " + df.getField("d"));
|
System.out.println("df.getField(\"d\") : "
|
||||||
|
+ df.getField("d"));
|
||||||
Object field = df.setField("d", null); // Exception
|
Object field = df.setField("d", null); // Exception
|
||||||
} catch(NoSuchFieldException |
|
} catch(NoSuchFieldException |
|
||||||
DynamicFieldsException e) {
|
DynamicFieldsException e) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// io/DirList.java
|
// files/DirList.java
|
||||||
// Display a directory listing using regular expressions.
|
// Display a directory listing using regular expressions.
|
||||||
// {Args: "D.*\.java"}
|
// {Args: "D.*\.java"}
|
||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
@ -1,4 +1,4 @@
|
|||||||
// io/DirList2.java
|
// files/DirList2.java
|
||||||
// Uses anonymous inner classes.
|
// Uses anonymous inner classes.
|
||||||
// {Args: "D.*\.java"}
|
// {Args: "D.*\.java"}
|
||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
@ -1,4 +1,4 @@
|
|||||||
// io/DirList3.java
|
// files/DirList3.java
|
||||||
// Building the anonymous inner class "in-place."
|
// Building the anonymous inner class "in-place."
|
||||||
// {Args: "D.*\.java"}
|
// {Args: "D.*\.java"}
|
||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
@ -1,7 +1,7 @@
|
|||||||
// io/DirectoryDemo.java
|
// files/DirectoryDemo.java
|
||||||
// Sample use of Directory utilities.
|
// Sample use of Directory utilities.
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class DirectoryDemo {
|
public class DirectoryDemo {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
@ -1,4 +1,4 @@
|
|||||||
// io/MakeDirectories.java
|
// files/MakeDirectories.java
|
||||||
// Demonstrates using the File class to
|
// Demonstrates using the File class to
|
||||||
// create directories and manipulate files.
|
// create directories and manipulate files.
|
||||||
// {Args: MakeDirectoriesTest}
|
// {Args: MakeDirectoriesTest}
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" ?>
|
<?xml version="1.0" ?>
|
||||||
|
|
||||||
<project default="run">
|
<project default="run">
|
||||||
<property name="chapter" value="io"/>
|
<property name="chapter" value="files"/>
|
||||||
<property name="excludedfiles" value=""/>
|
<property name="excludedfiles" value=""/>
|
||||||
<import file="../Ant-Common.xml"/>
|
<import file="../Ant-Common.xml"/>
|
||||||
<import file="../Ant-Clean.xml"/>
|
<import file="../Ant-Clean.xml"/>
|
@ -1,5 +1,5 @@
|
|||||||
// generics/BasicSupplierDemo.java
|
// generics/BasicSupplierDemo.java
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
|
|
||||||
public class BasicSupplierDemo {
|
public class BasicSupplierDemo {
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
// generics/DynamicProxyMixin.java
|
// generics/DynamicProxyMixin.java
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
import static com.mindviewinc.util.Tuple.*;
|
import static onjava.Tuple.*;
|
||||||
|
|
||||||
class MixinProxy implements InvocationHandler {
|
class MixinProxy implements InvocationHandler {
|
||||||
Map<String,Object> delegatesByMethod;
|
Map<String,Object> delegatesByMethod;
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public MixinProxy(TwoTuple<Object,Class<?>>... pairs) {
|
public MixinProxy(Tuple2<Object,Class<?>>... pairs) {
|
||||||
delegatesByMethod = new HashMap<>();
|
delegatesByMethod = new HashMap<>();
|
||||||
for(TwoTuple<Object,Class<?>> pair : pairs) {
|
for(Tuple2<Object,Class<?>> pair : pairs) {
|
||||||
for(Method method : pair.second.getMethods()) {
|
for(Method method : pair._2.getMethods()) {
|
||||||
String methodName = method.getName();
|
String methodName = method.getName();
|
||||||
// The first interface in the map
|
// The first interface in the map
|
||||||
// implements the method.
|
// implements the method.
|
||||||
if(!delegatesByMethod.containsKey(methodName))
|
if(!delegatesByMethod.containsKey(methodName))
|
||||||
delegatesByMethod.put(methodName, pair.first);
|
delegatesByMethod.put(methodName, pair._1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -27,13 +27,13 @@ class MixinProxy implements InvocationHandler {
|
|||||||
return method.invoke(delegate, args);
|
return method.invoke(delegate, args);
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Object newInstance(TwoTuple... pairs) {
|
public static Object newInstance(Tuple2... pairs) {
|
||||||
Class[] interfaces = new Class[pairs.length];
|
Class[] interfaces = new Class[pairs.length];
|
||||||
for(int i = 0; i < pairs.length; i++) {
|
for(int i = 0; i < pairs.length; i++) {
|
||||||
interfaces[i] = (Class)pairs[i].second;
|
interfaces[i] = (Class)pairs[i]._2;
|
||||||
}
|
}
|
||||||
ClassLoader cl =
|
ClassLoader cl =
|
||||||
pairs[0].first.getClass().getClassLoader();
|
pairs[0]._1.getClass().getClassLoader();
|
||||||
return Proxy.newProxyInstance(
|
return Proxy.newProxyInstance(
|
||||||
cl, interfaces, new MixinProxy(pairs));
|
cl, interfaces, new MixinProxy(pairs));
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public class Functional {
|
|||||||
// object can act as a collecting parameter, so it is
|
// object can act as a collecting parameter, so it is
|
||||||
// returned at the end.
|
// returned at the end.
|
||||||
public static <T> Collector<T>
|
public static <T> Collector<T>
|
||||||
forEach(Iterable<T> seq, Collector<T> func) {
|
forIn(Iterable<T> seq, Collector<T> func) {
|
||||||
for(T t : seq)
|
for(T t : seq)
|
||||||
func.function(t);
|
func.function(t);
|
||||||
return func;
|
return func;
|
||||||
@ -132,10 +132,10 @@ public class Functional {
|
|||||||
|
|
||||||
System.out.println(filter(li, new GreaterThan<>(4)));
|
System.out.println(filter(li, new GreaterThan<>(4)));
|
||||||
|
|
||||||
System.out.println(forEach(li,
|
System.out.println(forIn(li,
|
||||||
new MultiplyingIntegerCollector()).result());
|
new MultiplyingIntegerCollector()).result());
|
||||||
|
|
||||||
System.out.println(forEach(filter(li, new GreaterThan<>(4)),
|
System.out.println(forIn(filter(li, new GreaterThan<>(4)),
|
||||||
new MultiplyingIntegerCollector()).result());
|
new MultiplyingIntegerCollector()).result());
|
||||||
|
|
||||||
MathContext mc = new MathContext(7);
|
MathContext mc = new MathContext(7);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// generics/PrimitiveGenericTest.java
|
// generics/PrimitiveGenericTest.java
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
|
|
||||||
// Fill an array using a generator:
|
// Fill an array using a generator:
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
// generics/TupleList.java
|
// generics/TupleList.java
|
||||||
// Combining generic types to make complex generic types.
|
// Combining generic types to make complex generic types.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
public class TupleList<A, B, C, D>
|
public class TupleList<A, B, C, D>
|
||||||
extends ArrayList<FourTuple<A, B, C, D>> {
|
extends ArrayList<Tuple4<A, B, C, D>> {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
TupleList<Vehicle, Amphibian, String, Integer> tl =
|
TupleList<Vehicle, Amphibian, String, Integer> tl =
|
||||||
new TupleList<>();
|
new TupleList<>();
|
||||||
tl.add(TupleTest.h());
|
tl.add(TupleTest.h());
|
||||||
tl.add(TupleTest.h());
|
tl.add(TupleTest.h());
|
||||||
for(FourTuple<Vehicle,Amphibian,String,Integer> i: tl)
|
for(Tuple4<Vehicle,Amphibian,String,Integer> i: tl)
|
||||||
System.out.println(i);
|
System.out.println(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,33 @@
|
|||||||
// generics/TupleTest.java
|
// generics/TupleTest.java
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
class Amphibian {}
|
class Amphibian {}
|
||||||
class Vehicle {}
|
class Vehicle {}
|
||||||
|
|
||||||
public class TupleTest {
|
public class TupleTest {
|
||||||
static TwoTuple<String, Integer> f() {
|
static Tuple2<String, Integer> f() {
|
||||||
// Autoboxing converts the int to Integer:
|
// Autoboxing converts the int to Integer:
|
||||||
return new TwoTuple<>("hi", 47);
|
return new Tuple2<>("hi", 47);
|
||||||
}
|
}
|
||||||
static ThreeTuple<Amphibian, String, Integer> g() {
|
static Tuple3<Amphibian, String, Integer> g() {
|
||||||
return new ThreeTuple<>(new Amphibian(), "hi", 47);
|
return new Tuple3<>(new Amphibian(), "hi", 47);
|
||||||
}
|
}
|
||||||
static
|
static
|
||||||
FourTuple<Vehicle, Amphibian, String, Integer> h() {
|
Tuple4<Vehicle, Amphibian, String, Integer> h() {
|
||||||
return
|
return
|
||||||
new FourTuple<>(
|
new Tuple4<>(
|
||||||
new Vehicle(), new Amphibian(), "hi", 47);
|
new Vehicle(), new Amphibian(), "hi", 47);
|
||||||
}
|
}
|
||||||
static
|
static
|
||||||
FiveTuple<Vehicle, Amphibian, String, Integer, Double> k(){
|
Tuple5<Vehicle, Amphibian, String, Integer, Double> k(){
|
||||||
return new
|
return new
|
||||||
FiveTuple<>(
|
Tuple5<>(
|
||||||
new Vehicle(), new Amphibian(), "hi", 47, 11.1);
|
new Vehicle(), new Amphibian(), "hi", 47, 11.1);
|
||||||
}
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
TwoTuple<String, Integer> ttsi = f();
|
Tuple2<String, Integer> ttsi = f();
|
||||||
System.out.println(ttsi);
|
System.out.println(ttsi);
|
||||||
// ttsi.first = "there"; // Compile error: final
|
// ttsi._1 = "there"; // Compile error: final
|
||||||
System.out.println(g());
|
System.out.println(g());
|
||||||
System.out.println(h());
|
System.out.println(h());
|
||||||
System.out.println(k());
|
System.out.println(k());
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
// generics/TupleTest2.java
|
// generics/TupleTest2.java
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
import static com.mindviewinc.util.Tuple.*;
|
import static onjava.Tuple.*;
|
||||||
|
|
||||||
public class TupleTest2 {
|
public class TupleTest2 {
|
||||||
static TwoTuple<String, Integer> f() {
|
static Tuple2<String, Integer> f() {
|
||||||
return tuple("hi", 47);
|
return tuple("hi", 47);
|
||||||
}
|
}
|
||||||
static TwoTuple f2() { return tuple("hi", 47); }
|
static Tuple2 f2() { return tuple("hi", 47); }
|
||||||
static ThreeTuple<Amphibian, String, Integer> g() {
|
static Tuple3<Amphibian, String, Integer> g() {
|
||||||
return tuple(new Amphibian(), "hi", 47);
|
return tuple(new Amphibian(), "hi", 47);
|
||||||
}
|
}
|
||||||
static
|
static
|
||||||
FourTuple<Vehicle, Amphibian, String, Integer> h() {
|
Tuple4<Vehicle, Amphibian, String, Integer> h() {
|
||||||
return tuple(new Vehicle(), new Amphibian(), "hi", 47);
|
return tuple(new Vehicle(), new Amphibian(), "hi", 47);
|
||||||
}
|
}
|
||||||
static
|
static
|
||||||
FiveTuple<Vehicle, Amphibian, String, Integer, Double> k(){
|
Tuple5<Vehicle, Amphibian, String, Integer, Double> k(){
|
||||||
return tuple(new Vehicle(), new Amphibian(),
|
return tuple(new Vehicle(), new Amphibian(),
|
||||||
"hi", 47, 11.1);
|
"hi", 47, 11.1);
|
||||||
}
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
TwoTuple<String, Integer> ttsi = f();
|
Tuple2<String, Integer> ttsi = f();
|
||||||
System.out.println(ttsi);
|
System.out.println(ttsi);
|
||||||
System.out.println(f2());
|
System.out.println(f2());
|
||||||
System.out.println(g());
|
System.out.println(g());
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// generics/WatercolorSets.java
|
// generics/WatercolorSets.java
|
||||||
import generics.watercolors.*;
|
import generics.watercolors.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import static com.mindviewinc.util.Sets.*;
|
import static onjava.Sets.*;
|
||||||
import static generics.watercolors.Watercolors.*;
|
import static generics.watercolors.Watercolors.*;
|
||||||
|
|
||||||
public class WatercolorSets {
|
public class WatercolorSets {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// housekeeping/TerminationCondition.java
|
// housekeeping/TerminationCondition.java
|
||||||
// Using finalize() to detect an object that
|
// Using finalize() to detect an object that
|
||||||
// hasn't been properly cleaned up.
|
// hasn't been properly cleaned up.
|
||||||
import com.mindviewinc.util.*;
|
import onjava.*;
|
||||||
|
|
||||||
class Book {
|
class Book {
|
||||||
boolean checkedOut = false;
|
boolean checkedOut = false;
|
||||||
|
@ -6,7 +6,7 @@ public class ConfigureLogging {
|
|||||||
static Logger
|
static Logger
|
||||||
lgr = Logger.getLogger("com"),
|
lgr = Logger.getLogger("com"),
|
||||||
lgr2 = Logger.getLogger("com.mindviewinc"),
|
lgr2 = Logger.getLogger("com.mindviewinc"),
|
||||||
util= Logger.getLogger("com.mindviewinc.util"),
|
util= Logger.getLogger("onjava"),
|
||||||
test= Logger.getLogger("com.mindviewinc.test"),
|
test= Logger.getLogger("com.mindviewinc.test"),
|
||||||
rand = Logger.getLogger("random");
|
rand = Logger.getLogger("random");
|
||||||
public ConfigureLogging() {
|
public ConfigureLogging() {
|
||||||
@ -42,7 +42,7 @@ public class ConfigureLogging {
|
|||||||
/* Output:
|
/* Output:
|
||||||
Logger Name : net Level: SEVERE
|
Logger Name : net Level: SEVERE
|
||||||
Logger Name : com.mindviewinc Level: FINEST
|
Logger Name : com.mindviewinc Level: FINEST
|
||||||
Logger Name : com.mindviewinc.util Level: INFO
|
Logger Name : onjava Level: INFO
|
||||||
Logger Name : com.mindviewinc.test Level: FINER
|
Logger Name : com.mindviewinc.test Level: FINER
|
||||||
Logger Name : random Level: SEVERE
|
Logger Name : random Level: SEVERE
|
||||||
___[ Error Output ]___
|
___[ Error Output ]___
|
||||||
|
@ -6,7 +6,7 @@ public class LoggingLevelManipulation {
|
|||||||
private static Logger
|
private static Logger
|
||||||
lgr = Logger.getLogger("com"),
|
lgr = Logger.getLogger("com"),
|
||||||
lgr2 = Logger.getLogger("com.mindviewinc"),
|
lgr2 = Logger.getLogger("com.mindviewinc"),
|
||||||
util= Logger.getLogger("com.mindviewinc.util"),
|
util= Logger.getLogger("onjava"),
|
||||||
test= Logger.getLogger("com.mindviewinc.test"),
|
test= Logger.getLogger("com.mindviewinc.test"),
|
||||||
rand = Logger.getLogger("random");
|
rand = Logger.getLogger("random");
|
||||||
static void printLogMessages(Logger logger) {
|
static void printLogMessages(Logger logger) {
|
||||||
@ -59,18 +59,18 @@ public class LoggingLevelManipulation {
|
|||||||
}
|
}
|
||||||
/* Output:
|
/* Output:
|
||||||
-- printing levels -- net : null com.mindviewinc : null
|
-- printing levels -- net : null com.mindviewinc : null
|
||||||
com.mindviewinc.util : null com.mindviewinc.test : null
|
onjava : null com.mindviewinc.test : null
|
||||||
random : null
|
random : null
|
||||||
-- printing levels -- net : SEVERE com.mindviewinc : null
|
-- printing levels -- net : SEVERE com.mindviewinc : null
|
||||||
com.mindviewinc.util : null com.mindviewinc.test : null
|
onjava : null com.mindviewinc.test : null
|
||||||
random : null
|
random : null
|
||||||
net level: SEVERE
|
net level: SEVERE
|
||||||
-- printing levels -- net : SEVERE com.mindviewinc : null
|
-- printing levels -- net : SEVERE com.mindviewinc : null
|
||||||
com.mindviewinc.util : FINEST com.mindviewinc.test : FINEST
|
onjava : FINEST com.mindviewinc.test : FINEST
|
||||||
random : FINEST
|
random : FINEST
|
||||||
individual loggers set to FINEST
|
individual loggers set to FINEST
|
||||||
-- printing levels -- net : FINEST com.mindviewinc : null
|
-- printing levels -- net : FINEST com.mindviewinc : null
|
||||||
com.mindviewinc.util : FINEST com.mindviewinc.test : FINEST
|
onjava : FINEST com.mindviewinc.test : FINEST
|
||||||
random : FINEST
|
random : FINEST
|
||||||
net level: FINEST
|
net level: FINEST
|
||||||
___[ Error Output ]___
|
___[ Error Output ]___
|
||||||
@ -88,13 +88,13 @@ printLogMessages
|
|||||||
SEVERE: com.mindviewinc Severe
|
SEVERE: com.mindviewinc Severe
|
||||||
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
||||||
printLogMessages
|
printLogMessages
|
||||||
INFO: com.mindviewinc.util Info
|
INFO: onjava Info
|
||||||
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
||||||
printLogMessages
|
printLogMessages
|
||||||
WARNING: com.mindviewinc.util Warning
|
WARNING: onjava Warning
|
||||||
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
||||||
printLogMessages
|
printLogMessages
|
||||||
SEVERE: com.mindviewinc.util Severe
|
SEVERE: onjava Severe
|
||||||
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
||||||
printLogMessages
|
printLogMessages
|
||||||
INFO: com.mindviewinc.test Info
|
INFO: com.mindviewinc.test Info
|
||||||
@ -127,13 +127,13 @@ printLogMessages
|
|||||||
SEVERE: com.mindviewinc Severe
|
SEVERE: com.mindviewinc Severe
|
||||||
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
||||||
printLogMessages
|
printLogMessages
|
||||||
INFO: com.mindviewinc.util Info
|
INFO: onjava Info
|
||||||
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
||||||
printLogMessages
|
printLogMessages
|
||||||
WARNING: com.mindviewinc.util Warning
|
WARNING: onjava Warning
|
||||||
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
||||||
printLogMessages
|
printLogMessages
|
||||||
SEVERE: com.mindviewinc.util Severe
|
SEVERE: onjava Severe
|
||||||
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
||||||
printLogMessages
|
printLogMessages
|
||||||
INFO: com.mindviewinc.test Info
|
INFO: com.mindviewinc.test Info
|
||||||
@ -172,13 +172,13 @@ printLogMessages
|
|||||||
SEVERE: com.mindviewinc Severe
|
SEVERE: com.mindviewinc Severe
|
||||||
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
||||||
printLogMessages
|
printLogMessages
|
||||||
INFO: com.mindviewinc.util Info
|
INFO: onjava Info
|
||||||
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
||||||
printLogMessages
|
printLogMessages
|
||||||
WARNING: com.mindviewinc.util Warning
|
WARNING: onjava Warning
|
||||||
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
||||||
printLogMessages
|
printLogMessages
|
||||||
SEVERE: com.mindviewinc.util Severe
|
SEVERE: onjava Severe
|
||||||
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
Jun 15, 2015 3:47:52 PM LoggingLevelManipulation
|
||||||
printLogMessages
|
printLogMessages
|
||||||
INFO: com.mindviewinc.test Info
|
INFO: com.mindviewinc.test Info
|
||||||
|
@ -6,7 +6,7 @@ public class LoggingLevels {
|
|||||||
private static Logger
|
private static Logger
|
||||||
lgr = Logger.getLogger("com"),
|
lgr = Logger.getLogger("com"),
|
||||||
lgr2 = Logger.getLogger("com.mindviewinc"),
|
lgr2 = Logger.getLogger("com.mindviewinc"),
|
||||||
util= Logger.getLogger("com.mindviewinc.util"),
|
util= Logger.getLogger("onjava"),
|
||||||
test= Logger.getLogger("com.mindviewinc.test"),
|
test= Logger.getLogger("com.mindviewinc.test"),
|
||||||
rand = Logger.getLogger("random");
|
rand = Logger.getLogger("random");
|
||||||
private static void logMessages() {
|
private static void logMessages() {
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user