Skip to content

Commit

Permalink
More Netbeans mods
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceEckel committed May 5, 2015
1 parent 7175059 commit f5a2dd0
Show file tree
Hide file tree
Showing 108 changed files with 474 additions and 685 deletions.
2 changes: 0 additions & 2 deletions access/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<import file="../Ant-Common.xml"/>

<target name="run" description="Compile and run" depends="build">
<touch file="failures"/>
<jrun cls="Cake" />
<jrun cls="ChocolateChip" />
<jrun cls="ChocolateChip2" />
Expand All @@ -18,7 +17,6 @@
<jrun cls="PrintTest" />
<jrun cls="QualifiedMyClass" />
<jrun cls="SingleImport" />
<delete file="failures"/>
</target>

</project>
39 changes: 19 additions & 20 deletions annotations/InterfaceExtractorProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,27 @@ public void process() {
interfaceMethods.add(m);
if(interfaceMethods.size() > 0) {
try {
PrintWriter writer =
env.getFiler().createSourceFile(annot.value());
writer.println("package " +
typeDecl.getPackage().getQualifiedName() +";");
writer.println("public interface " +
annot.value() + " {");
for(MethodDeclaration m : interfaceMethods) {
writer.print(" public ");
writer.print(m.getReturnType() + " ");
writer.print(m.getSimpleName() + " (");
int i = 0;
for(ParameterDeclaration parm :
m.getParameters()) {
writer.print(parm.getType() + " " +
parm.getSimpleName());
if(++i < m.getParameters().size())
writer.print(", ");
try (PrintWriter writer = env.getFiler().createSourceFile(annot.value())) {
writer.println("package " +
typeDecl.getPackage().getQualifiedName() +";");
writer.println("public interface " +
annot.value() + " {");
for(MethodDeclaration m : interfaceMethods) {
writer.print(" public ");
writer.print(m.getReturnType() + " ");
writer.print(m.getSimpleName() + " (");
int i = 0;
for(ParameterDeclaration parm :
m.getParameters()) {
writer.print(parm.getType() + " " +
parm.getSimpleName());
if(++i < m.getParameters().size())
writer.print(", ");
}
writer.println(");");
}
writer.println(");");
writer.println("}");
}
writer.println("}");
writer.close();
} catch(IOException ioe) {
throw new RuntimeException(ioe);
}
Expand Down
2 changes: 0 additions & 2 deletions annotations/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<import file="../Ant-Common.xml"/>

<target name="run" description="Compile and run" depends="build">
<touch file="failures"/>
<jrun cls="annotations.AtUnitComposition" dirpath="../annotations" />
<jrun cls="annotations.AtUnitExample1" dirpath="../annotations" />
<jrun cls="annotations.AtUnitExample2" dirpath="../annotations" />
Expand All @@ -19,7 +18,6 @@
<jrun cls="annotations.StackLStringTest" dirpath="../annotations" />
<jrun cls="UseCaseTracker" />
<jrun cls="annotations.database.TableCreator" dirpath="../annotations/database" arguments='annotations.database.Member' />
<delete file="failures"/>
</target>

</project>
7 changes: 1 addition & 6 deletions arrays/CompType.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ public int compareTo(CompType rv) {
}
private static Random r = new Random(47);
public static Generator<CompType> generator() {
return new Generator<CompType>() {
@Override
public CompType next() {
return new CompType(r.nextInt(100),r.nextInt(100));
}
};
return () -> new CompType(r.nextInt(100),r.nextInt(100));
}
public static void main(String[] args) {
CompType[] a =
Expand Down
4 changes: 2 additions & 2 deletions arrays/CopyingArrays.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public static void main(String[] args) {
// Objects:
Integer[] u = new Integer[10];
Integer[] v = new Integer[5];
Arrays.fill(u, new Integer(47));
Arrays.fill(v, new Integer(99));
Arrays.fill(u, 47);
Arrays.fill(v, 99);
print("u = " + Arrays.toString(u));
print("v = " + Arrays.toString(v));
System.arraycopy(v, 0, u, u.length/2, v.length);
Expand Down
2 changes: 0 additions & 2 deletions arrays/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<import file="../Ant-Common.xml"/>

<target name="run" description="Compile and run" depends="build">
<touch file="failures"/>
<jrun cls="AlphabeticSearch" />
<jrun cls="ArrayOfGenerics" />
<jrun cls="ArrayOptions" />
Expand All @@ -33,7 +32,6 @@
<jrun cls="TestArrayGeneration" />
<jrun cls="TestGenerated" />
<jrun cls="ThreeDWithNew" />
<delete file="failures"/>
</target>

</project>
2 changes: 0 additions & 2 deletions assertions/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
<import file="../Ant-Common.xml"/>

<target name="run" description="Compile and run" depends="build">
<touch file="failures"/>
<jrun cls="Assert1" failOnError='false' msg='* Exception was Expected *' />
<jrun cls="Assert2" failOnError='false' msg='* Exception was Expected *' />
<jrun cls="LoaderAssertions" failOnError='false' msg='* Exception was Expected *' />
<jrun cls="Queue" />
<delete file="failures"/>
</target>

</project>
22 changes: 8 additions & 14 deletions concurrency/ActiveObjectDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,18 @@ private void pause(int factor) {
}
public Future<Integer>
calculateInt(final int x, final int y) {
return ex.submit(new Callable<Integer>() {
@Override
public Integer call() {
print("starting " + x + " + " + y);
pause(500);
return x + y;
}
return ex.submit(() -> {
print("starting " + x + " + " + y);
pause(500);
return x + y;
});
}
public Future<Float>
calculateFloat(final float x, final float y) {
return ex.submit(new Callable<Float>() {
@Override
public Float call() {
print("starting " + x + " + " + y);
pause(2000);
return x + y;
}
return ex.submit(() -> {
print("starting " + x + " + " + y);
pause(2000);
return x + y;
});
}
public void shutdown() { ex.shutdown(); }
Expand Down
20 changes: 10 additions & 10 deletions concurrency/CloseResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ public class CloseResource {
public static void main(String[] args) throws Exception {
ExecutorService exec = Executors.newCachedThreadPool();
ServerSocket server = new ServerSocket(8080);
InputStream socketInput =
new Socket("localhost", 8080).getInputStream();
exec.execute(new IOBlocked(socketInput));
exec.execute(new IOBlocked(System.in));
TimeUnit.MILLISECONDS.sleep(100);
print("Shutting down all threads");
exec.shutdownNow();
TimeUnit.SECONDS.sleep(1);
print("Closing " + socketInput.getClass().getName());
socketInput.close(); // Releases blocked thread
try (InputStream socketInput = new Socket("localhost", 8080).getInputStream()) {
exec.execute(new IOBlocked(socketInput));
exec.execute(new IOBlocked(System.in));
TimeUnit.MILLISECONDS.sleep(100);
print("Shutting down all threads");
exec.shutdownNow();
TimeUnit.SECONDS.sleep(1);
print("Closing " + socketInput.getClass().getName());
socketInput.close(); // Releases blocked thread
}
TimeUnit.SECONDS.sleep(1);
print("Closing " + System.in.getClass().getName());
System.in.close(); // Releases blocked thread
Expand Down
35 changes: 16 additions & 19 deletions concurrency/HorseRace.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,23 @@ public class HorseRace {
Executors.newCachedThreadPool();
private CyclicBarrier barrier;
public HorseRace(int nHorses, final int pause) {
barrier = new CyclicBarrier(nHorses, new Runnable() {
@Override
public void run() {
StringBuilder s = new StringBuilder();
for(int i = 0; i < FINISH_LINE; i++)
s.append("="); // The fence on the racetrack
print(s);
for(Horse horse : horses)
print(horse.tracks());
for(Horse horse : horses)
if(horse.getStrides() >= FINISH_LINE) {
print(horse + "won!");
exec.shutdownNow();
return;
}
try {
TimeUnit.MILLISECONDS.sleep(pause);
} catch(InterruptedException e) {
print("barrier-action sleep interrupted");
barrier = new CyclicBarrier(nHorses, () -> {
StringBuilder s = new StringBuilder();
for(int i = 0; i < FINISH_LINE; i++)
s.append("="); // The fence on the racetrack
print(s);
for(Horse horse : horses)
print(horse.tracks());
for(Horse horse : horses)
if(horse.getStrides() >= FINISH_LINE) {
print(horse + "won!");
exec.shutdownNow();
return;
}
try {
TimeUnit.MILLISECONDS.sleep(pause);
} catch(InterruptedException e) {
print("barrier-action sleep interrupted");
}
});
for(int i = 0; i < nHorses; i++) {
Expand Down
20 changes: 10 additions & 10 deletions concurrency/NIOInterruption.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public static void main(String[] args) throws Exception {
InetSocketAddress isa =
new InetSocketAddress("localhost", 8080);
SocketChannel sc1 = SocketChannel.open(isa);
SocketChannel sc2 = SocketChannel.open(isa);
Future<?> f = exec.submit(new NIOBlocked(sc1));
exec.execute(new NIOBlocked(sc2));
exec.shutdown();
TimeUnit.SECONDS.sleep(1);
// Produce an interrupt via cancel:
f.cancel(true);
TimeUnit.SECONDS.sleep(1);
// Release the block by closing the channel:
sc2.close();
try (SocketChannel sc2 = SocketChannel.open(isa)) {
Future<?> f = exec.submit(new NIOBlocked(sc1));
exec.execute(new NIOBlocked(sc2));
exec.shutdown();
TimeUnit.SECONDS.sleep(1);
// Produce an interrupt via cancel:
f.cancel(true);
TimeUnit.SECONDS.sleep(1);
// Release the block by closing the channel:
}
}
} /* Output: (Sample)
Waiting for read() in NIOBlocked@7a84e4
Expand Down
17 changes: 7 additions & 10 deletions concurrency/SemaphoreDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@ public static void main(String[] args) throws Exception {
f.operation();
list.add(f);
}
Future<?> blocked = exec.submit(new Runnable() {
@Override
public void run() {
try {
// Semaphore prevents additional checkout,
// so call is blocked:
pool.checkOut();
} catch(InterruptedException e) {
print("checkOut() Interrupted");
}
Future<?> blocked = exec.submit(() -> {
try {
// Semaphore prevents additional checkout,
// so call is blocked:
pool.checkOut();
} catch(InterruptedException e) {
print("checkOut() Interrupted");
}
});
TimeUnit.SECONDS.sleep(2);
Expand Down
2 changes: 0 additions & 2 deletions concurrency/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<import file="../Ant-Common.xml"/>

<target name="run" description="Compile and run" depends="build">
<touch file="failures"/>
<jrun cls="ActiveObjectDemo" />
<jrun cls="AtomicEvenGenerator" failOnError='false' timeOut='4000' msg='* Timeout for Testing *' />
<jrun cls="AtomicIntegerTest" />
Expand Down Expand Up @@ -74,7 +73,6 @@
<jrun cls="concurrency.restaurant2.RestaurantWithQueues" dirpath="../concurrency/restaurant2" arguments='5' />
<jrun cls="concurrency.waxomatic.WaxOMatic" dirpath="../concurrency/waxomatic" />
<jrun cls="concurrency.waxomatic2.WaxOMatic2" dirpath="../concurrency/waxomatic2" />
<delete file="failures"/>
</target>

</project>
2 changes: 0 additions & 2 deletions containers/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<import file="../Ant-Common.xml"/>

<target name="run" description="Compile and run" depends="build">
<touch file="failures"/>
<jrun cls="AssociativeArray" />
<jrun cls="Bits" />
<jrun cls="CanonicalMapping" />
Expand Down Expand Up @@ -44,7 +43,6 @@
<jrun cls="TypesForSets" />
<jrun cls="Unsupported" />
<jrun cls="Utilities" />
<delete file="failures"/>
</target>

</project>
2 changes: 0 additions & 2 deletions control/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<import file="../Ant-Common.xml"/>

<target name="run" description="Compile and run" depends="build">
<touch file="failures"/>
<jrun cls="BreakAndContinue" />
<jrun cls="CommaOperator" />
<jrun cls="ForEachFloat" />
Expand All @@ -20,7 +19,6 @@
<jrun cls="StringSwitch" />
<jrun cls="VowelsAndConsonants" />
<jrun cls="WhileTest" />
<delete file="failures"/>
</target>

</project>
2 changes: 0 additions & 2 deletions debugging/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
<import file="../Ant-Common.xml"/>

<target name="run" description="Compile and run" depends="build">
<touch file="failures"/>
<jrun cls="SimpleDebugging" failOnError='false' msg='* Exception was Expected *' />
<delete file="failures"/>
</target>

</project>
10 changes: 4 additions & 6 deletions enumerated/EnumMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ public class EnumMaps {
public static void main(String[] args) {
EnumMap<AlarmPoints,Command> em =
new EnumMap<>(AlarmPoints.class);
em.put(KITCHEN, new Command() {
@Override
public void action() { print("Kitchen fire!"); }
em.put(KITCHEN, (Command) () -> {
print("Kitchen fire!");
});
em.put(BATHROOM, new Command() {
@Override
public void action() { print("Bathroom alert!"); }
em.put(BATHROOM, (Command) () -> {
print("Bathroom alert!");
});
for(Map.Entry<AlarmPoints,Command> e : em.entrySet()) {
printnb(e.getKey() + ": ");
Expand Down
2 changes: 0 additions & 2 deletions enumerated/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<import file="../Ant-Common.xml"/>

<target name="run" description="Compile and run" depends="build">
<touch file="failures"/>
<jrun cls="BigEnumSet" />
<jrun cls="enumerated.Burrito" dirpath="../enumerated" />
<jrun cls="CarWash" />
Expand Down Expand Up @@ -34,7 +33,6 @@
<jrun cls="enumerated.menu.Meal" dirpath="../enumerated/menu" />
<jrun cls="enumerated.menu.Meal2" dirpath="../enumerated/menu" />
<jrun cls="enumerated.menu.TypeOfFood" dirpath="../enumerated/menu" />
<delete file="failures"/>
</target>

</project>
2 changes: 0 additions & 2 deletions exceptions/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<import file="../Ant-Common.xml"/>

<target name="run" description="Compile and run" depends="build">
<touch file="failures"/>
<jrun cls="AlwaysFinally" />
<jrun cls="Cleanup" />
<jrun cls="CleanupIdiom" />
Expand All @@ -31,7 +30,6 @@
<jrun cls="TurnOffChecking" />
<jrun cls="WhoCalled" />
<jrun cls="WithFinally" />
<delete file="failures"/>
</target>

</project>
Loading

0 comments on commit f5a2dd0

Please sign in to comment.