Adding {main: when necessary
This commit is contained in:
parent
35240be2e8
commit
2478dc168b
@ -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.
|
||||
// Does Math.random() produce 0.0 and 1.0?
|
||||
// {TimeOutDuringTesting}
|
||||
// {Args: lower}
|
||||
import onjava.*;
|
||||
|
||||
public class RandomBounds {
|
||||
static void usage() {
|
||||
@ -15,6 +15,7 @@ public class RandomBounds {
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
if(args.length != 1) usage();
|
||||
new TimedAbort(3);
|
||||
switch(args[0]) {
|
||||
case "lower":
|
||||
while(Math.random() != 0.0)
|
||||
|
@ -2,6 +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}
|
||||
package enums;
|
||||
import static enums.Spiciness.*;
|
||||
|
||||
|
@ -3,6 +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}
|
||||
package enums;
|
||||
import java.util.*;
|
||||
import static enums.AlarmPoints.*;
|
||||
|
@ -3,6 +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}
|
||||
package enums;
|
||||
import java.util.*;
|
||||
import static enums.AlarmPoints.*;
|
||||
|
@ -34,7 +34,7 @@ public class Reflection {
|
||||
exploreMethods.removeAll(enumMethods);
|
||||
System.out.println(exploreMethods);
|
||||
// Decompile the code for the enum:
|
||||
OSExecute.command("javap Explore");
|
||||
OSExecute.command("javap -cp build/classes/main Explore");
|
||||
}
|
||||
}
|
||||
/* Output:
|
||||
|
@ -3,6 +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}
|
||||
package enums;
|
||||
import java.util.*;
|
||||
import static enums.Outcome.*;
|
||||
|
@ -3,6 +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}
|
||||
package enums;
|
||||
import static enums.Outcome.*;
|
||||
|
||||
|
@ -3,6 +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}
|
||||
package enums;
|
||||
import static enums.Outcome.*;
|
||||
|
||||
|
@ -2,6 +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}
|
||||
package enums;
|
||||
|
||||
public enum RoShamBo4 implements Competitor<RoShamBo4> {
|
||||
|
@ -3,6 +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}
|
||||
package enums;
|
||||
import java.util.*;
|
||||
import static enums.Outcome.*;
|
||||
|
@ -3,6 +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}
|
||||
package enums;
|
||||
import static enums.Outcome.*;
|
||||
|
||||
|
@ -3,6 +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}
|
||||
package enums.cartoons;
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
|
@ -2,6 +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}
|
||||
package enums.menu;
|
||||
|
||||
public class Meal {
|
||||
|
@ -2,6 +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}
|
||||
package enums.menu;
|
||||
import onjava.*;
|
||||
|
||||
|
@ -2,6 +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}
|
||||
package enums.menu;
|
||||
import static enums.menu.Food.*;
|
||||
|
||||
|
@ -2,6 +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}
|
||||
package generics.coffee;
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
|
@ -2,6 +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}
|
||||
package generics.decorator;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -3,6 +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}
|
||||
package innerclasses;
|
||||
|
||||
interface Incrementable {
|
||||
|
@ -4,6 +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}
|
||||
package innerclasses;
|
||||
|
||||
class D {}
|
||||
|
@ -3,6 +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}
|
||||
package innerclasses.mui;
|
||||
|
||||
interface A {}
|
||||
|
@ -2,6 +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}
|
||||
package interfaces.interfaceprocessor;
|
||||
import interfaces.filters.*;
|
||||
|
||||
|
@ -2,6 +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}
|
||||
package interfaces.interfaceprocessor;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -3,6 +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}
|
||||
package interfaces.music4;
|
||||
import polymorphism.music.Note;
|
||||
|
||||
|
@ -2,6 +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}
|
||||
package interfaces.music5;
|
||||
import polymorphism.music.Note;
|
||||
|
||||
|
@ -2,6 +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}
|
||||
package interfaces.nesting;
|
||||
|
||||
class A {
|
||||
|
@ -2,6 +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}
|
||||
package onjava;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
|
@ -3,6 +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}
|
||||
package onjava;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -3,6 +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}
|
||||
package onjava;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -3,6 +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}
|
||||
package onjava;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -2,6 +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}
|
||||
package onjava;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
@ -25,7 +26,8 @@ public class Hex {
|
||||
if(args.length == 0)
|
||||
// Test by displaying this class file:
|
||||
System.out.println(format(
|
||||
Files.readAllBytes(Paths.get("Hex.class"))));
|
||||
Files.readAllBytes(Paths.get(
|
||||
"build/classes/main/onjava/Hex.class"))));
|
||||
else
|
||||
System.out.println(format(
|
||||
Files.readAllBytes(Paths.get(args[0]))));
|
||||
|
@ -3,6 +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}
|
||||
package onjava;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
|
@ -3,6 +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}
|
||||
package onjava.atunit;
|
||||
import java.lang.reflect.*;
|
||||
import java.io.*;
|
||||
|
@ -2,6 +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}
|
||||
package onjava.atunit;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
|
@ -3,6 +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}
|
||||
package patterns.absfactory;
|
||||
import java.util.function.*;
|
||||
|
||||
|
@ -3,6 +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}
|
||||
package patterns.adapt;
|
||||
|
||||
class WhatIHave {
|
||||
|
@ -3,6 +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}
|
||||
package patterns.chain;
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
|
@ -4,6 +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}
|
||||
package patterns.doubledispatch;
|
||||
import patterns.trash.*;
|
||||
import java.util.*;
|
||||
|
@ -5,6 +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}
|
||||
package patterns.dynatrash;
|
||||
import patterns.trash.*;
|
||||
import java.util.*;
|
||||
|
@ -3,6 +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}
|
||||
package patterns.factory;
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
@ -3,6 +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}
|
||||
package patterns.observer;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -3,6 +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}
|
||||
package patterns.recyclea;
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
|
@ -2,6 +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}
|
||||
package patterns.recycleb;
|
||||
import patterns.trash.*;
|
||||
import java.util.*;
|
||||
|
@ -3,6 +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}
|
||||
package patterns.recyclec;
|
||||
import patterns.trash.*;
|
||||
import java.util.*;
|
||||
|
@ -3,6 +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}
|
||||
package patterns.state;
|
||||
|
||||
interface State {
|
||||
|
@ -2,6 +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}
|
||||
package patterns.strategy;
|
||||
import java.util.function.*;
|
||||
import java.util.*;
|
||||
|
@ -2,6 +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}
|
||||
package patterns.strategy;
|
||||
import java.util.function.*;
|
||||
import java.util.*;
|
||||
|
@ -4,6 +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}
|
||||
package patterns.trash;
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
@ -2,6 +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}
|
||||
package patterns.trashvisitor;
|
||||
import patterns.trash.*;
|
||||
import java.util.*;
|
||||
|
@ -3,6 +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}
|
||||
package patterns.visitor;
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
|
@ -4,12 +4,13 @@
|
||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||
// Demonstration of Observer pattern using
|
||||
// Java's built-in observer classes
|
||||
// {TimeOut:4000} During testing
|
||||
// {main: patterns.visualobserver.BoxObserver}
|
||||
package patterns.visualobserver;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import onjava.*;
|
||||
import onjava.MouseClick;
|
||||
|
||||
// You must inherit a new type of Observable:
|
||||
@ -33,6 +34,7 @@ public class BoxObserver extends JFrame {
|
||||
cp.add(new OCBox(x, y, notifier));
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
new TimedAbort(4);
|
||||
int grid = 8;
|
||||
if(args.length > 0)
|
||||
grid = Integer.parseInt(args[0]);
|
||||
|
@ -3,17 +3,13 @@
|
||||
// We make no guarantees that this code is fit for any purpose.
|
||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||
// Demonstrates standard I/O redirection
|
||||
// {Exec: javap -cp build/classes/main OSExecuteDemo}
|
||||
import onjava.*;
|
||||
|
||||
public class OSExecuteDemo {
|
||||
public static void main(String[] args) {
|
||||
OSExecute.command("javap OSExecuteDemo");
|
||||
}
|
||||
}
|
||||
public class OSExecuteDemo {}
|
||||
/* Output:
|
||||
Compiled from "OSExecuteDemo.java"
|
||||
public class OSExecuteDemo {
|
||||
public OSExecuteDemo();
|
||||
public static void main(java.lang.String[]);
|
||||
}
|
||||
*/
|
||||
|
@ -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.
|
||||
// {TimeOutDuringTesting} (on single-core machines)
|
||||
// {TimeOutDuringTesting}
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class AtomicityTest implements Runnable {
|
||||
|
@ -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.
|
||||
// When threads collide
|
||||
// {TimeOutDuringTesting} (on single-core machines)
|
||||
// {TimeOutDuringTesting}
|
||||
|
||||
public class EvenSupplier extends IntSupplier {
|
||||
private int currentEvenValue = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user