Skip to content

Commit f5a2dd0

Browse files
committed
More Netbeans mods
1 parent 7175059 commit f5a2dd0

File tree

108 files changed

+474
-685
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+474
-685
lines changed

access/build.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<import file="../Ant-Common.xml"/>
77

88
<target name="run" description="Compile and run" depends="build">
9-
<touch file="failures"/>
109
<jrun cls="Cake" />
1110
<jrun cls="ChocolateChip" />
1211
<jrun cls="ChocolateChip2" />
@@ -18,7 +17,6 @@
1817
<jrun cls="PrintTest" />
1918
<jrun cls="QualifiedMyClass" />
2019
<jrun cls="SingleImport" />
21-
<delete file="failures"/>
2220
</target>
2321

2422
</project>

annotations/InterfaceExtractorProcessor.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,27 @@ public void process() {
3030
interfaceMethods.add(m);
3131
if(interfaceMethods.size() > 0) {
3232
try {
33-
PrintWriter writer =
34-
env.getFiler().createSourceFile(annot.value());
35-
writer.println("package " +
36-
typeDecl.getPackage().getQualifiedName() +";");
37-
writer.println("public interface " +
38-
annot.value() + " {");
39-
for(MethodDeclaration m : interfaceMethods) {
40-
writer.print(" public ");
41-
writer.print(m.getReturnType() + " ");
42-
writer.print(m.getSimpleName() + " (");
43-
int i = 0;
44-
for(ParameterDeclaration parm :
45-
m.getParameters()) {
46-
writer.print(parm.getType() + " " +
47-
parm.getSimpleName());
48-
if(++i < m.getParameters().size())
49-
writer.print(", ");
33+
try (PrintWriter writer = env.getFiler().createSourceFile(annot.value())) {
34+
writer.println("package " +
35+
typeDecl.getPackage().getQualifiedName() +";");
36+
writer.println("public interface " +
37+
annot.value() + " {");
38+
for(MethodDeclaration m : interfaceMethods) {
39+
writer.print(" public ");
40+
writer.print(m.getReturnType() + " ");
41+
writer.print(m.getSimpleName() + " (");
42+
int i = 0;
43+
for(ParameterDeclaration parm :
44+
m.getParameters()) {
45+
writer.print(parm.getType() + " " +
46+
parm.getSimpleName());
47+
if(++i < m.getParameters().size())
48+
writer.print(", ");
49+
}
50+
writer.println(");");
5051
}
51-
writer.println(");");
52+
writer.println("}");
5253
}
53-
writer.println("}");
54-
writer.close();
5554
} catch(IOException ioe) {
5655
throw new RuntimeException(ioe);
5756
}

annotations/build.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<import file="../Ant-Common.xml"/>
77

88
<target name="run" description="Compile and run" depends="build">
9-
<touch file="failures"/>
109
<jrun cls="annotations.AtUnitComposition" dirpath="../annotations" />
1110
<jrun cls="annotations.AtUnitExample1" dirpath="../annotations" />
1211
<jrun cls="annotations.AtUnitExample2" dirpath="../annotations" />
@@ -19,7 +18,6 @@
1918
<jrun cls="annotations.StackLStringTest" dirpath="../annotations" />
2019
<jrun cls="UseCaseTracker" />
2120
<jrun cls="annotations.database.TableCreator" dirpath="../annotations/database" arguments='annotations.database.Member' />
22-
<delete file="failures"/>
2321
</target>
2422

2523
</project>

arrays/CompType.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ public int compareTo(CompType rv) {
2525
}
2626
private static Random r = new Random(47);
2727
public static Generator<CompType> generator() {
28-
return new Generator<CompType>() {
29-
@Override
30-
public CompType next() {
31-
return new CompType(r.nextInt(100),r.nextInt(100));
32-
}
33-
};
28+
return () -> new CompType(r.nextInt(100),r.nextInt(100));
3429
}
3530
public static void main(String[] args) {
3631
CompType[] a =

arrays/CopyingArrays.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public static void main(String[] args) {
2323
// Objects:
2424
Integer[] u = new Integer[10];
2525
Integer[] v = new Integer[5];
26-
Arrays.fill(u, new Integer(47));
27-
Arrays.fill(v, new Integer(99));
26+
Arrays.fill(u, 47);
27+
Arrays.fill(v, 99);
2828
print("u = " + Arrays.toString(u));
2929
print("v = " + Arrays.toString(v));
3030
System.arraycopy(v, 0, u, u.length/2, v.length);

arrays/build.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<import file="../Ant-Common.xml"/>
77

88
<target name="run" description="Compile and run" depends="build">
9-
<touch file="failures"/>
109
<jrun cls="AlphabeticSearch" />
1110
<jrun cls="ArrayOfGenerics" />
1211
<jrun cls="ArrayOptions" />
@@ -33,7 +32,6 @@
3332
<jrun cls="TestArrayGeneration" />
3433
<jrun cls="TestGenerated" />
3534
<jrun cls="ThreeDWithNew" />
36-
<delete file="failures"/>
3735
</target>
3836

3937
</project>

assertions/build.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
<import file="../Ant-Common.xml"/>
77

88
<target name="run" description="Compile and run" depends="build">
9-
<touch file="failures"/>
109
<jrun cls="Assert1" failOnError='false' msg='* Exception was Expected *' />
1110
<jrun cls="Assert2" failOnError='false' msg='* Exception was Expected *' />
1211
<jrun cls="LoaderAssertions" failOnError='false' msg='* Exception was Expected *' />
1312
<jrun cls="Queue" />
14-
<delete file="failures"/>
1513
</target>
1614

1715
</project>

concurrency/ActiveObjectDemo.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,18 @@ private void pause(int factor) {
2222
}
2323
public Future<Integer>
2424
calculateInt(final int x, final int y) {
25-
return ex.submit(new Callable<Integer>() {
26-
@Override
27-
public Integer call() {
28-
print("starting " + x + " + " + y);
29-
pause(500);
30-
return x + y;
31-
}
25+
return ex.submit(() -> {
26+
print("starting " + x + " + " + y);
27+
pause(500);
28+
return x + y;
3229
});
3330
}
3431
public Future<Float>
3532
calculateFloat(final float x, final float y) {
36-
return ex.submit(new Callable<Float>() {
37-
@Override
38-
public Float call() {
39-
print("starting " + x + " + " + y);
40-
pause(2000);
41-
return x + y;
42-
}
33+
return ex.submit(() -> {
34+
print("starting " + x + " + " + y);
35+
pause(2000);
36+
return x + y;
4337
});
4438
}
4539
public void shutdown() { ex.shutdown(); }

concurrency/CloseResource.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ public class CloseResource {
1111
public static void main(String[] args) throws Exception {
1212
ExecutorService exec = Executors.newCachedThreadPool();
1313
ServerSocket server = new ServerSocket(8080);
14-
InputStream socketInput =
15-
new Socket("localhost", 8080).getInputStream();
16-
exec.execute(new IOBlocked(socketInput));
17-
exec.execute(new IOBlocked(System.in));
18-
TimeUnit.MILLISECONDS.sleep(100);
19-
print("Shutting down all threads");
20-
exec.shutdownNow();
21-
TimeUnit.SECONDS.sleep(1);
22-
print("Closing " + socketInput.getClass().getName());
23-
socketInput.close(); // Releases blocked thread
14+
try (InputStream socketInput = new Socket("localhost", 8080).getInputStream()) {
15+
exec.execute(new IOBlocked(socketInput));
16+
exec.execute(new IOBlocked(System.in));
17+
TimeUnit.MILLISECONDS.sleep(100);
18+
print("Shutting down all threads");
19+
exec.shutdownNow();
20+
TimeUnit.SECONDS.sleep(1);
21+
print("Closing " + socketInput.getClass().getName());
22+
socketInput.close(); // Releases blocked thread
23+
}
2424
TimeUnit.SECONDS.sleep(1);
2525
print("Closing " + System.in.getClass().getName());
2626
System.in.close(); // Releases blocked thread

concurrency/HorseRace.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,23 @@ public class HorseRace {
4646
Executors.newCachedThreadPool();
4747
private CyclicBarrier barrier;
4848
public HorseRace(int nHorses, final int pause) {
49-
barrier = new CyclicBarrier(nHorses, new Runnable() {
50-
@Override
51-
public void run() {
52-
StringBuilder s = new StringBuilder();
53-
for(int i = 0; i < FINISH_LINE; i++)
54-
s.append("="); // The fence on the racetrack
55-
print(s);
56-
for(Horse horse : horses)
57-
print(horse.tracks());
58-
for(Horse horse : horses)
59-
if(horse.getStrides() >= FINISH_LINE) {
60-
print(horse + "won!");
61-
exec.shutdownNow();
62-
return;
63-
}
64-
try {
65-
TimeUnit.MILLISECONDS.sleep(pause);
66-
} catch(InterruptedException e) {
67-
print("barrier-action sleep interrupted");
49+
barrier = new CyclicBarrier(nHorses, () -> {
50+
StringBuilder s = new StringBuilder();
51+
for(int i = 0; i < FINISH_LINE; i++)
52+
s.append("="); // The fence on the racetrack
53+
print(s);
54+
for(Horse horse : horses)
55+
print(horse.tracks());
56+
for(Horse horse : horses)
57+
if(horse.getStrides() >= FINISH_LINE) {
58+
print(horse + "won!");
59+
exec.shutdownNow();
60+
return;
6861
}
62+
try {
63+
TimeUnit.MILLISECONDS.sleep(pause);
64+
} catch(InterruptedException e) {
65+
print("barrier-action sleep interrupted");
6966
}
7067
});
7168
for(int i = 0; i < nHorses; i++) {

0 commit comments

Comments
 (0)