Skip to content

Commit d54e290

Browse files
committed
iluwatar#466: Fix Checkstyle Issues
1 parent 4456a44 commit d54e290

18 files changed

+420
-57
lines changed

monitor-object/pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
<?xml version="1.0"?>
2+
<!--
3+
4+
The MIT License
5+
Copyright (c) 2014 Ilkka Seppälä
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
25+
-->
226
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
327
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
428
<modelVersion>4.0.0</modelVersion>

monitor-object/src/main/java/com/iluwatar/monitor/AbstractMonitor.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
123
package com.iluwatar.monitor;
224

325
import java.util.ArrayList;
@@ -135,7 +157,7 @@ protected Condition makeCondition(Assertion prop) {
135157
* Create a condition queue with no associated checked Assertion.
136158
*/
137159
protected Condition makeCondition() {
138-
return makeCondition(null, TrueAssertion.singleton);
160+
return makeCondition(null, TrueAssertion.SINGLETON);
139161
}
140162

141163
/**
@@ -150,7 +172,7 @@ protected Condition makeCondition(String name, Assertion prop) {
150172
* Create a condition queue with no associated checked Assertion.
151173
*/
152174
protected Condition makeCondition(String name) {
153-
return makeCondition(name, TrueAssertion.singleton);
175+
return makeCondition(name, TrueAssertion.SINGLETON);
154176
}
155177

156178
/** Register a listener. */

monitor-object/src/main/java/com/iluwatar/monitor/Assertion.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
123
package com.iluwatar.monitor;/** * Assertions that may be checked from time to time. */public abstract class Assertion { private static final String DEFAULTMESSAGE = "Assertion Failure"; protected String message = DEFAULTMESSAGE; /** This method says whether the assertion is true. */ public abstract boolean isTrue(); /** Throw an AssertionError if the assertion is not true. */ public void check() { check(isTrue(), message); } /** Throw an AssertionError if the parameter is not true. */ public static void check(boolean b) { check(b, DEFAULTMESSAGE); } /** Throw an AssertionError if the boolean parameter is not true. */ public static void check(boolean b, String message) { if (!b) { throw new AssertionError(message); } }}

monitor-object/src/main/java/com/iluwatar/monitor/Condition.java

Lines changed: 22 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
123
package com.iluwatar.monitor;
224

325
/**
@@ -9,15 +31,15 @@ public final class Monitor extends AbstractMonitor {
931
private Assertion invariant;
1032

1133
public Monitor() {
12-
this(TrueAssertion.singleton);
34+
this(TrueAssertion.SINGLETON);
1335
}
1436

1537
public Monitor(Assertion invariant) {
1638
this.invariant = invariant;
1739
}
1840

1941
public Monitor(String name) {
20-
this(name, TrueAssertion.singleton);
42+
this(name, TrueAssertion.SINGLETON);
2143
}
2244

2345
public Monitor(String name, Assertion invariant) {
@@ -29,49 +51,4 @@ public Monitor(String name, Assertion invariant) {
2951
public boolean invariant() {
3052
return invariant.isTrue();
3153
}
32-
33-
@Override
34-
public void enter() {
35-
super.enter();
36-
}
37-
38-
@Override
39-
public void leave() {
40-
super.leave();
41-
}
42-
43-
@Override
44-
public <T> T leave(T result) {
45-
return super.leave(result);
46-
}
47-
48-
@Override
49-
public void doWithin(Runnable runnable) {
50-
super.doWithin(runnable);
51-
}
52-
53-
@Override
54-
public <T> T doWithin(RunnableWithResult<T> runnable) {
55-
return super.doWithin(runnable);
56-
}
57-
58-
@Override
59-
public Condition makeCondition() {
60-
return super.makeCondition();
61-
}
62-
63-
@Override
64-
public Condition makeCondition(Assertion assertion) {
65-
return super.makeCondition(assertion);
66-
}
67-
68-
@Override
69-
public Condition makeCondition(String name) {
70-
return super.makeCondition(name);
71-
}
72-
73-
@Override
74-
public Condition makeCondition(String name, Assertion assertion) {
75-
return super.makeCondition(name, assertion);
76-
}
7754
}

monitor-object/src/main/java/com/iluwatar/monitor/MonitorListener.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
123
package com.iluwatar.monitor;
224

25+
/**
26+
* Interface for Monitor Listener which lists all methods required for a listener to monitor object
27+
*/
328
public interface MonitorListener {
429

530
void nameThisThread(String name);
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
123
package com.iluwatar.monitor;
224

25+
/**
26+
* Interface which contains the run method which is executed within the protection of the monitor.
27+
* When the run method returns, if the thread still occupies the monitor, it leaves the monitor.
28+
* Thus the signalAndLeave method may be called within the run method.
29+
*
30+
* @param <T> the expected return value of the run method
31+
*/
332
public interface RunnableWithResult<T> {
4-
public T run();
33+
T run();
534
}

monitor-object/src/main/java/com/iluwatar/monitor/Semaphore.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
123
package com.iluwatar.monitor;import java.util.LinkedList;import java.util.ListIterator;/** * A FIFO semaphore. */public class Semaphore { // Each queue element is a a single use semaphore class QueueElement { final int priority; volatile boolean enabled = false; QueueElement(int priority) { this.priority = priority; } synchronized void acquire() { while (!enabled) { try { wait(); } catch (InterruptedException e) { throw new RuntimeException("Unexpected interruption of " + "thread in monitor.Semaphore.acquire"); } } } synchronized void release() { enabled = true; notify(); } } volatile int s1; final LinkedList<QueueElement> queue = new LinkedList<QueueElement>(); // Invariant. All elements on the queue are in an unenabled state. /** Initialize the semaphore to a value greater or equal to 0. */ public Semaphore(int initialvalue) { Assertion.check(initialvalue >= 0); this.s1 = initialvalue; } /** * The P operation. If two threads are blocked at the same time, they will be * served in FIFO order. <kbd>sem.acquire()</kbd> is equivalent to <kbd>acquire( * Integer.MAX_VALUE )</kbd>. */ public void acquire() { acquire(Integer.MAX_VALUE); } /** * The P operation with a priority. * * @param priority * The larger the integer, the less urgent the priority. If two * thread are waiting with equal priority, they will complete acquire * in FIFO order. */ public void acquire(int priority) { QueueElement mine; synchronized (this) { if (s1 > 0) { --s1; return; } mine = new QueueElement(priority); if (priority == Integer.MAX_VALUE) { queue.add(mine); } else { ListIterator<QueueElement> it = queue.listIterator(0); int i = 0; while (it.hasNext()) { QueueElement elem = it.next(); if (elem.priority > priority) { break; } ++i; } queue.add(i, mine); } } mine.acquire(); } /** The V operation. */ public synchronized void release() { QueueElement first = queue.poll(); if (first != null) { first.release(); } else { ++s1; } }}

monitor-object/src/main/java/com/iluwatar/monitor/TrueAssertion.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
package com.iluwatar.monitor;/** * An assertion that is always true. */public class TrueAssertion extends Assertion { public boolean isTrue() { return true; } public static final TrueAssertion singleton = new TrueAssertion();}
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
package com.iluwatar.monitor;/** * An assertion that is always true. */public class TrueAssertion extends Assertion { public boolean isTrue() { return true; } public static final TrueAssertion SINGLETON = new TrueAssertion();}

monitor-object/src/main/java/com/iluwatar/monitor/examples/Queue.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
123
package com.iluwatar.monitor.examples;
224

325
import com.iluwatar.monitor.AbstractMonitor;

0 commit comments

Comments
 (0)