Changing to {java tag

This commit is contained in:
Bruce Eckel 2016-07-28 12:48:23 -06:00
parent 72a37051d3
commit 72c57ddee3
85 changed files with 126 additions and 119 deletions

View File

@ -3,8 +3,8 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Creating non-embedded tests
// {main: onjava.atunit.AtUnit}
// {Args: build/classes/main/annotations/AtUnitComposition.class}
// {java onjava.atunit.AtUnit
// build/classes/main/annotations/AtUnitComposition.class}
package annotations;
import onjava.atunit.*;
import onjava.*;

View File

@ -2,8 +2,8 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: onjava.atunit.AtUnit}
// {Args: build/classes/main/annotations/AtUnitExample1.class}
// {java onjava.atunit.AtUnit
// build/classes/main/annotations/AtUnitExample1.class}
package annotations;
import onjava.atunit.*;
import onjava.*;

View File

@ -3,8 +3,8 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Assertions and exceptions can be used in @Tests
// {main: onjava.atunit.AtUnit}
// {Args: build/classes/main/annotations/AtUnitExample2.class}
// {java onjava.atunit.AtUnit
// build/classes/main/annotations/AtUnitExample2.class}
package annotations;
import java.io.*;
import onjava.atunit.*;

View File

@ -2,8 +2,8 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: onjava.atunit.AtUnit}
// {Args: build/classes/main/annotations/AtUnitExample3.class}
// {java onjava.atunit.AtUnit
// build/classes/main/annotations/AtUnitExample3.class}
package annotations;
import onjava.atunit.*;
import onjava.*;

View File

@ -2,8 +2,8 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: onjava.atunit.AtUnit}
// {Args: build/classes/main/annotations/AtUnitExample4.class}
// {java onjava.atunit.AtUnit
// build/classes/main/annotations/AtUnitExample4.class}
package annotations;
import java.util.*;
import onjava.atunit.*;

View File

@ -2,8 +2,8 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: onjava.atunit.AtUnit}
// {Args: build/classes/main/annotations/AtUnitExample5.class}
// {java onjava.atunit.AtUnit
// build/classes/main/annotations/AtUnitExample5.class}
package annotations;
import java.io.*;
import onjava.atunit.*;

View File

@ -3,8 +3,8 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Creating non-embedded tests
// {main: onjava.atunit.AtUnit}
// {Args: build/classes/main/annotations/AtUnitExternalTest.class}
// {java onjava.atunit.AtUnit
// build/classes/main/annotations/AtUnitExternalTest.class}
package annotations;
import onjava.atunit.*;
import onjava.*;

View File

@ -2,8 +2,8 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: onjava.atunit.AtUnit}
// {Args: build/classes/main/annotations/HashSetTest.class}
// {java onjava.atunit.AtUnit
// build/classes/main/annotations/HashSetTest.class}
package annotations;
import java.util.*;
import onjava.atunit.*;

View File

@ -3,8 +3,8 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Applying @Unit to generics
// {main: onjava.atunit.AtUnit}
// {Args: build/classes/main/annotations/StackLStringTest.class}
// {java onjava.atunit.AtUnit
// build/classes/main/annotations/StackLStringTest.class}
package annotations;
import onjava.atunit.*;
import onjava.*;

View File

@ -3,8 +3,8 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Reflection-based annotation processor
// {main: annotations.database.TableCreator}
// {Args: annotations.database.Member}
// {java annotations.database.TableCreator
// annotations.database.Member}
package annotations.database;
import java.lang.annotation.*;
import java.lang.reflect.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// javac-based annotation processing
// {main: annotations.ifx.Multiplier}
// {java annotations.ifx.Multiplier}
package annotations.ifx;
@ExtractInterface(interfaceName="IMultiplier")

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Test the "Simple" annotation
// {main: annotations.simplest.SimpleTest}
// {java annotations.simplest.SimpleTest}
package annotations.simplest;
@Simple

View File

@ -3,7 +3,7 @@ import org.apache.tools.ant.util.TeeOutputStream
boolean debug = false
class Tags {
Boolean mainMethod = false
Boolean hasMainMethod = false
Boolean compileTimeError = false
Boolean throwsException = false
Boolean errorOutputExpected = false
@ -22,20 +22,25 @@ class Tags {
def Tags(List<String> lines) {
this.lines = lines
block = lines.join('')
mainMethod = block.contains('main(String[] args)')
hasMainMethod = block.contains('main(String[] args)')
fileRoot = lines[0].split("/")[-1] - ".java"
mainClass = fileRoot
javaCmd = extract('java')
if(javaCmd) {
mainClass = javaCmd
println("fileRoot: " + fileRoot)
println("mainClass: " + mainClass)
def pieces = javaCmd.split()
mainClass = pieces[0]
if(pieces.size() > 1)
for(p in pieces[1..-1])
if(p.startsWith("-"))
jVMArgs << p
else
args << p
}
compileTimeError = testFor('CompileTimeError')
throwsException = testFor('ThrowsException')
errorOutputExpected = testFor('ErrorOutputExpected')
validateByHand = testFor('ValidateByHand')
ignoreOutput = testFor('IgnoreOutput')
compileTimeError = hasTag('CompileTimeError')
throwsException = hasTag('ThrowsException')
errorOutputExpected = hasTag('ErrorOutputExpected')
validateByHand = hasTag('ValidateByHand')
ignoreOutput = hasTag('IgnoreOutput')
def argString = extract('Args:')
if(argString)
args = argString.split(' ')
@ -50,7 +55,7 @@ class Tags {
}
}
}
private def testFor(String marker) {
private def hasTag(String marker) {
return block.contains("// {" + marker + "}")
}
private def extract(String marker) {
@ -89,7 +94,7 @@ class Tags {
else
break
"""
mainMethod
hasMainMethod
compileTimeError
throwsException
errorOutputExpected
@ -139,7 +144,7 @@ subprojects {
if(debug && tags.hasTags()) println tags
// Add tasks for java sources with main methods
if ((tags.mainMethod || tags.javaCmd) && (!tags.compileTimeError)) {
if ((tags.hasMainMethod || tags.javaCmd) && (!tags.compileTimeError)) {
if (!tags.validateByHand) {
// Only add tasks that we know we can run successfully to the task list

2
check.bat Normal file
View File

@ -0,0 +1,2 @@
cp ..\..\OnJava-Tools\verify_output.py .
python verify_output.py

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: collections.MapOfList}
// {java collections.MapOfList}
package collections;
import typeinfo.pets.*;
import java.util.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: enums.Burrito}
// {java enums.Burrito}
package enums;
import static enums.Spiciness.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Basics of EnumMaps
// {main: enums.EnumMaps}
// {java enums.EnumMaps}
package enums;
import java.util.*;
import static enums.AlarmPoints.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Operations on EnumSets
// {main: enums.EnumSets}
// {java enums.EnumSets}
package enums;
import java.util.*;
import static enums.AlarmPoints.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Demonstration of multiple dispatching
// {main: enums.RoShamBo1}
// {java enums.RoShamBo1}
package enums;
import java.util.*;
import static enums.Outcome.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Switching one enum on another
// {main: enums.RoShamBo2}
// {java enums.RoShamBo2}
package enums;
import static enums.Outcome.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Using constant-specific methods
// {main: enums.RoShamBo3}
// {java enums.RoShamBo3}
package enums;
import static enums.Outcome.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: enums.RoShamBo4}
// {java enums.RoShamBo4}
package enums;
public enum RoShamBo4 implements Competitor<RoShamBo4> {

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Multiple dispatching using an EnumMap of EnumMaps
// {main: enums.RoShamBo5}
// {java enums.RoShamBo5}
package enums;
import java.util.*;
import static enums.Outcome.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Enums using "tables" instead of multiple dispatch
// {main: enums.RoShamBo6}
// {java enums.RoShamBo6}
package enums;
import static enums.Outcome.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// An enum can implement an interface
// {main: enums.cartoons.EnumImplementation}
// {java enums.cartoons.EnumImplementation}
package enums.cartoons;
import java.util.*;
import java.util.function.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: enums.menu.Meal}
// {java enums.menu.Meal}
package enums.menu;
public class Meal {

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: enums.menu.Meal2}
// {java enums.menu.Meal2}
package enums.menu;
import onjava.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: enums.menu.TypeOfFood}
// {java enums.menu.TypeOfFood}
package enums.menu;
import static enums.menu.Food.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: generics.coffee.CoffeeSupplier}
// {java generics.coffee.CoffeeSupplier}
package generics.coffee;
import java.util.*;
import java.util.function.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: generics.decorator.Decoration}
// {java generics.decorator.Decoration}
package generics.decorator;
import java.util.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Using inner classes for callbacks
// {main: innerclasses.Callbacks}
// {java innerclasses.Callbacks}
package innerclasses;
interface Incrementable {

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: ClassInInterface$Test}
// {java ClassInInterface$Test}
public interface ClassInInterface {
void howdy();

View File

@ -4,7 +4,7 @@
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// For concrete or abstract classes, inner classes
// produce "multiple implementation inheritance"
// {main: innerclasses.MultiImplementation}
// {java innerclasses.MultiImplementation}
package innerclasses;
class D {}

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Putting test code in a nested class
// {main: TestBed$Tester}
// {java TestBed$Tester}
public class TestBed {
public void f() { System.out.println("f()"); }

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Two ways that a class can implement multiple interfaces
// {main: innerclasses.mui.MultiInterfaces}
// {java innerclasses.mui.MultiInterfaces}
package innerclasses.mui;
interface A {}

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: interfaces.interfaceprocessor.FilterProcessor}
// {java interfaces.interfaceprocessor.FilterProcessor}
package interfaces.interfaceprocessor;
import interfaces.filters.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: interfaces.interfaceprocessor.StringProcessor}
// {java interfaces.interfaceprocessor.StringProcessor}
package interfaces.interfaceprocessor;
import java.util.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Abstract classes and methods
// {main: interfaces.music4.Music4}
// {java interfaces.music4.Music4}
package interfaces.music4;
import polymorphism.music.Note;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: interfaces.music5.Music5}
// {java interfaces.music5.Music5}
package interfaces.music5;
import polymorphism.music.Note;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: interfaces.nesting.NestingInterfaces}
// {java interfaces.nesting.NestingInterfaces}
package interfaces.nesting;
class A {

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: onjava.CollectionMethodDifferences}
// {java onjava.CollectionMethodDifferences}
package onjava;
import java.lang.reflect.*;
import java.util.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Unlimited-length Map containing sample data
// {main: onjava.CountMap}
// {java onjava.CountMap}
package onjava;
import java.util.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// List of any length, containing sample data
// {main: onjava.CountingIntegerList}
// {java onjava.CountingIntegerList}
package onjava;
import java.util.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// "Flyweight" Maps and Lists of sample data
// {main: onjava.Countries}
// {java onjava.Countries}
package onjava;
import java.util.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: onjava.Hex}
// {java onjava.Hex}
package onjava;
import java.io.*;
import java.nio.file.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {ValidateByHand}
// {main: onjava.ProcessFiles}
// {java onjava.ProcessFiles}
package onjava;
import java.io.*;
import java.nio.file.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// An annotation-based unit-test framework
// {main: onjava.atunit.AtUnit}
// {java onjava.atunit.AtUnit}
package onjava.atunit;
import java.lang.reflect.*;
import java.io.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: onjava.atunit.ClassNameFinder}
// {java onjava.atunit.ClassNameFinder}
package onjava.atunit;
import java.io.*;
import java.nio.file.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// An example of the Abstract Factory pattern
// {main: patterns.absfactory.GameEnvironment}
// {java patterns.absfactory.GameEnvironment}
package patterns.absfactory;
import java.util.function.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Variations on the Adapter pattern
// {main: patterns.adapt.Adapter}
// {java patterns.adapt.Adapter}
package patterns.adapt;
class WhatIHave {

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Using the Functional interface
// {main: patterns.chain.ChainOfResponsibility}
// {java patterns.chain.ChainOfResponsibility}
package patterns.chain;
import java.util.*;
import java.util.function.*;

View File

@ -4,7 +4,7 @@
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Using multiple dispatching to handle more
// than one unknown type during a method call
// {main: patterns.doubledispatch.DoubleDispatch}
// {java patterns.doubledispatch.DoubleDispatch}
package patterns.doubledispatch;
import patterns.trash.*;
import java.util.*;

View File

@ -5,7 +5,7 @@
// Using a Map of Lists and RTTI to automatically
// sort trash into Lists. This solution, despite
// the use of RTTI, is extensible.
// {main: patterns.dynatrash.DynaTrash}
// {java patterns.dynatrash.DynaTrash}
package patterns.dynatrash;
import patterns.trash.*;
import java.util.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// A simple static factory method
// {main: patterns.factory.ShapeFactory1}
// {java patterns.factory.ShapeFactory1}
package patterns.factory;
import java.util.*;
import java.util.stream.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Demonstration of "Observer" pattern
// {main: patterns.observer.ObservedFlower}
// {java patterns.observer.ObservedFlower}
package patterns.observer;
import java.util.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Recycling with RTTI
// {main: patterns.recyclea.RecycleA}
// {java patterns.recyclea.RecycleA}
package patterns.recyclea;
import java.util.*;
import java.util.function.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: patterns.recycleb.RecycleB}
// {java patterns.recycleb.RecycleB}
package patterns.recycleb;
import patterns.trash.*;
import java.util.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Adding more objects to the recycling problem
// {main: patterns.recyclec.RecycleC}
// {java patterns.recyclec.RecycleC}
package patterns.recyclec;
import patterns.trash.*;
import java.util.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// The StateMachine pattern and Template method
// {main: patterns.state.StateMachineDemo}
// {java patterns.state.StateMachineDemo}
package patterns.state;
interface State {

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: patterns.strategy.StrategyPattern}
// {java patterns.strategy.StrategyPattern}
package patterns.strategy;
import java.util.function.*;
import java.util.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: patterns.strategy.StrategyPattern2}
// {java patterns.strategy.StrategyPattern2}
package patterns.strategy;
import java.util.function.*;
import java.util.*;

View File

@ -4,7 +4,7 @@
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Open a file and parse its contents into
// Trash objects, placing each into a List
// {main: patterns.trash.ParseTrash}
// {java patterns.trash.ParseTrash}
package patterns.trash;
import java.util.*;
import java.util.stream.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: patterns.trashvisitor.TrashVisitor}
// {java patterns.trashvisitor.TrashVisitor}
package patterns.trashvisitor;
import patterns.trash.*;
import java.util.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Demonstration of "visitor" pattern
// {main: patterns.visitor.BeeAndFlowers}
// {java patterns.visitor.BeeAndFlowers}
package patterns.visitor;
import java.util.*;
import java.util.function.*;

View File

@ -4,7 +4,7 @@
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Demonstration of Observer pattern using
// Java's built-in observer classes
// {main: patterns.visualobserver.BoxObserver}
// {java patterns.visualobserver.BoxObserver}
package patterns.visualobserver;
import javax.swing.*;
import java.awt.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Cleanup and inheritance
// {main: polymorphism.Frog}
// {java polymorphism.Frog}
package polymorphism;
class Characteristic {

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Trying to override a private method
// {main: polymorphism.PrivateOverride}
// {java polymorphism.PrivateOverride}
package polymorphism;
public class PrivateOverride {

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Order of constructor calls
// {main: polymorphism.Sandwich}
// {java polymorphism.Sandwich}
package polymorphism;
class Meal {

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Inheritance & upcasting
// {main: polymorphism.music.Music}
// {java polymorphism.music.Music}
package polymorphism.music;
public class Music {

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Overloading instead of upcasting
// {main: polymorphism.music.Music2}
// {java polymorphism.music.Music2}
package polymorphism.music;
class Stringed extends Instrument {

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// An extensible program
// {main: polymorphism.music3.Music3}
// {java polymorphism.music3.Music3}
package polymorphism.music3;
import polymorphism.music.Note;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Ensuring proper cleanup
// {main: reuse.CADSystem}
// {java reuse.CADSystem}
package reuse;
class Shape {

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Recover a serialized file
// {main: serialization.xfiles.ThawAlien}
// {java serialization.xfiles.ThawAlien}
// {RunFirst: FreezeAlien}
package serialization.xfiles;
import java.io.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: staticchecking.dr.DogsAndRobots}
// {java staticchecking.dr.DogsAndRobots}
package staticchecking.dr;
interface Speaks { void talk(); }

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: staticchecking.drc.DogAndRobotCollections}
// {java staticchecking.drc.DogAndRobotCollections}
package staticchecking.drc;
import java.util.*;

View File

@ -2,7 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {main: staticchecking.latent.Latent}
// {java staticchecking.latent.Latent}
package staticchecking.latent;
import java.lang.reflect.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Speaking pets in Java
// {main: staticchecking.petspeak.PetSpeak}
// {java staticchecking.petspeak.PetSpeak}
package staticchecking.petspeak;
interface Pet {

View File

@ -6,7 +6,7 @@
// Synchronizing blocks instead of entire methods. Also
// demonstrates protection of a non-thread-safe class
// with a thread-safe one.
// {main: threads.CriticalSection}
// {java threads.CriticalSection}
package threads;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;

View File

@ -4,7 +4,7 @@
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {ThrowsException} on a multiprocessor machine
// Using explicit Lock objects to create critical sections
// {main: threads.ExplicitCriticalSection}
// {java threads.ExplicitCriticalSection}
package threads;
import java.util.concurrent.locks.*;

View File

@ -2,8 +2,7 @@
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// {Args: 5}
// {main: threads.restaurant2.RestaurantWithQueues}
// {java threads.restaurant2.RestaurantWithQueues 5}
package threads.restaurant2;
import enums.menu.*;
import java.util.concurrent.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// The difference between instanceof and class
// {main: typeinfo.FamilyVsExactType}
// {java typeinfo.FamilyVsExactType}
package typeinfo;
class Base {}

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Using class literals
// {main: typeinfo.pets.LiteralPetCreator}
// {java typeinfo.pets.LiteralPetCreator}
package typeinfo.pets;
import java.util.*;

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Testing class Class
// {main: typeinfo.toys.GenericToyTest}
// {java typeinfo.toys.GenericToyTest}
package typeinfo.toys;
public class GenericToyTest {

View File

@ -3,7 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Testing class Class
// {main: typeinfo.toys.ToyTest}
// {java typeinfo.toys.ToyTest}
package typeinfo.toys;
interface HasBatteries {}

View File

@ -102,17 +102,18 @@ def no_match(input_text): return True
# Chain of responsibility:
strategies = [
# Filter Retain result for rest of chain
(exact_match, False),
(ignore_dates, True ),
(ignore_memory_addresses, True ),
(sort_lines, False),
(ignore_digits, False),
(sort_words, False),
(unique_lines, False),
(unique_words, False),
(words_only, False),
(no_match, False),
# Filter # Retain result
# for rest of chain
(exact_match, False),
(ignore_dates, True),
(ignore_memory_addresses, True),
(sort_lines, False),
(ignore_digits, False),
(sort_words, False),
(unique_lines, False),
(unique_words, False),
(words_only, False),
(no_match, False),
]
@ -142,8 +143,8 @@ class Validator(defaultdict): # Map of lists
with Validator.compare_output.open('a') as batch:
batch.write("subl " + str(tfile) + "\n")
with tfile.open('w') as trace_file:
trace_file.write(str(embedded_output) + "\n\n")
trace_file.write("=== Actual ===\n\n")
trace_file.write(javafile.read_text() + "\n\n")
trace_file.write("// === Actual ===\n\n")
trace_file.write(str(generated_output))
return
if retain: