#466: Fix Checkstyle Issues

This commit is contained in:
nikhilbarar committed 2018-06-13 02:54:09 +05:30
1 parent 4456a440bc
commit d54e29051f
18 files changed
+420 -57

No files matched your search

+24
View File
@@ -1,4 +1,28 @@
<?xml version="1.0"?>
<!--
The MIT License
Copyright (c) 2014 Ilkka Seppälä
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
@@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor;
import java.util.ArrayList;
@@ -135,7 +157,7 @@ public abstract class AbstractMonitor {
* Create a condition queue with no associated checked Assertion.
*/
protected Condition makeCondition() {
return makeCondition(null, TrueAssertion.singleton);
return makeCondition(null, TrueAssertion.SINGLETON);
}
/**
@@ -150,7 +172,7 @@ public abstract class AbstractMonitor {
* Create a condition queue with no associated checked Assertion.
*/
protected Condition makeCondition(String name) {
return makeCondition(name, TrueAssertion.singleton);
return makeCondition(name, TrueAssertion.SINGLETON);
}
/** Register a listener. */
@@ -1 +1,23 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
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);␍ }␍ }␍}
@@ -1 +1,23 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor; /** * A condition queue. * Uses the signal and wait discipline (SW) or signal and leave (SL). * Each Condition object is associated with a single {@link Assertion} object * and a single <code>AbstractMonitor</code> object. To construct a condition * use the <code>makeCondition</code> methods from * <code>{@link AbstractMonitor}</code> or {@link Monitor} * Threads can wait for the assertion represented by the Assertion object to * become true by calling method <code>await()</code>. Threads can indicate that * the assertion has become true by calling either method <code>signal()</code> * (SW) or <code>signalAndLeave()</code> (SL). All these methods check the * assertion and the monitor's invariant as appropriate. * Threads which wait on a Condition may supply a priority. In the absence of * priority, waiting is fair -- in fact first-in last-out (FIFO). * Each of the <code>await()</code>, <code>signal()</code>, and * <code>signalAndLeave()</code> methods have corresponding conditional * versions, which first check the assertion before awaiting or signalling. * These are: <code>conditionalAwait()</code>, <code>conditionalSignal()</code>, * and <code>conditionalSignalAndLeave()</code>. * Conditions also support a {@link #count} accessor to determine the number of * threads waiting on the condition. * Condition objects are intended to be used only by the thread which occupies * the monitor which created them. */ public class Condition { private final AbstractMonitor homeMonitor; private final Assertion assertion; private final Semaphore queue; private volatile int count; private final String name; Condition(String name, AbstractMonitor homeMonitor, Assertion assertion) { this.name = name; this.homeMonitor = homeMonitor; this.assertion = assertion; this.queue = new Semaphore(0); this.count = 0; } public String getName() { return name; } /** * Just like await, but with a priority. Threads awaiting with a lesser priority * value are re-admitted to the monitor in preference to threads awaiting with a * greater priority value. When priority values are the same, the order is FIFO. * * @param priority * Lower value means more urgent. * @throws AssertionError * if the current thread is not the occupant. * @throws AssertionError * if the invariant is not true to start * @throws AssertionError * if the assertion is not true on return * @see #await() */ public void await(int priority) { homeMonitor.notifyCallAwait(this); Assertion.check(homeMonitor.occupant == Thread.currentThread(), "Thread is not occupant"); count += 1; Assertion.check(homeMonitor.invariant(), "Invariant of monitor " + homeMonitor.getName()); homeMonitor.occupant = null; homeMonitor.entrance.release(); queue.acquire(priority); count -= 1; homeMonitor.occupant = Thread.currentThread(); // It's not clear that the following check is needed anymore, // as there is now a check made on the signal. assertion.check(); homeMonitor.notifyReturnFromAwait(this); } /** * Wait until a condition is signalled. The thread waits outside the monitor * until the condition is signalled. * Precondition: Increasing the count by 1 must make the invariant true. This * thread is in the monitor. * Postcondition: The assertion associated with this condition queue. This * thread is in the monitor. * Note: threads are queued in a FIFO manner unless a priority is used; * <kbd>cond.await()</kbd> is equivalent to <kbd>cond.await( Integer.MAX_VALUE * )</kbd>. * * @throws AssertionError * if the current thread is not the occupant. * @throws AssertionError * if the invariant is not true to start * @throws AssertionError * if the assertion is not true on return */ public void await() { await(Integer.MAX_VALUE); } /** * Wait only if the condition is not already true. * * @throws AssertionError * if neither the invariant nor the assertion associated with this * object is true * @throws AssertionError * if the current thread is not the occupant. * @throws AssertionError * if the assertion is not true on return * @see #await() */ public void conditionalAwait() { conditionalAwait(Integer.MAX_VALUE); } /** * Just like conditionalAwait, but with a priority. * * @param priority * Lower value means more urgent. * @throws AssertionError * if neither the invariant nor the assertion associated with this * object is true * @throws AssertionError * if the current thread is not the occupant. * @throws AssertionError * if the assertion is not true on return * @see #conditionalALine truncated
@@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor;
/**
@@ -9,7 +31,7 @@ public final class Monitor extends AbstractMonitor {
private Assertion invariant;
public Monitor() {
this(TrueAssertion.singleton);
this(TrueAssertion.SINGLETON);
}
public Monitor(Assertion invariant) {
@@ -17,7 +39,7 @@ public final class Monitor extends AbstractMonitor {
}
public Monitor(String name) {
this(name, TrueAssertion.singleton);
this(name, TrueAssertion.SINGLETON);
}
public Monitor(String name, Assertion invariant) {
@@ -29,49 +51,4 @@ public final class Monitor extends AbstractMonitor {
public boolean invariant() {
return invariant.isTrue();
}
@Override
public void enter() {
super.enter();
}
@Override
public void leave() {
super.leave();
}
@Override
public <T> T leave(T result) {
return super.leave(result);
}
@Override
public void doWithin(Runnable runnable) {
super.doWithin(runnable);
}
@Override
public <T> T doWithin(RunnableWithResult<T> runnable) {
return super.doWithin(runnable);
}
@Override
public Condition makeCondition() {
return super.makeCondition();
}
@Override
public Condition makeCondition(Assertion assertion) {
return super.makeCondition(assertion);
}
@Override
public Condition makeCondition(String name) {
return super.makeCondition(name);
}
@Override
public Condition makeCondition(String name, Assertion assertion) {
return super.makeCondition(name, assertion);
}
}
@@ -1,5 +1,30 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor;
/**
* Interface for Monitor Listener which lists all methods required for a listener to monitor object
*/
public interface MonitorListener {
void nameThisThread(String name);
@@ -1,5 +1,34 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor;
/**
* Interface which contains the run method which is executed within the protection of the monitor.
* When the run method returns, if the thread still occupies the monitor, it leaves the monitor.
* Thus the signalAndLeave method may be called within the run method.
*
* @param <T> the expected return value of the run method
*/
public interface RunnableWithResult<T> {
public T run();
T run();
}
@@ -1 +1,23 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
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;␍ }␍ }␍}
@@ -1 +1,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();␍}
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
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,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor.examples;
import com.iluwatar.monitor.AbstractMonitor;
@@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor.examples;
/**
@@ -5,5 +27,5 @@ package com.iluwatar.monitor.examples;
*/
public interface VoteInterface {
public boolean castVoteAndWaitForResult(boolean vote);
boolean castVoteAndWaitForResult(boolean vote);
}
@@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor.examples;
import com.iluwatar.monitor.AbstractMonitor;
@@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -28,7 +50,7 @@ public class AssertionTest {
@Test
public void testAssertionError() {
assertThrows(NullPointerException.class, () -> {
assertThrows(AssertionError.class, () -> {
Assertion a = new MyAssertion();
a.check();
varX = 1;
@@ -1,13 +1,35 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import com.iluwatar.monitor.examples.VoteInterface;
import com.iluwatar.monitor.examples.VoteMonitor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Test Case for Thread Signaling.
*/
@@ -20,7 +42,7 @@ public class ThreadSignalTest {
/**
* Setup method for Test Case.
*/
@BeforeAll
@BeforeEach
public void setUp() {
VoteInterface vm = new VoteMonitor(3);
v0 = new Voter0(vm);
@@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor;
import com.iluwatar.monitor.examples.VoteInterface;
@@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor;
import com.iluwatar.monitor.examples.VoteInterface;
@@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor;
import com.iluwatar.monitor.examples.VoteInterface;
@@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.monitor;
import com.iluwatar.monitor.examples.VoteInterface;