author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 09:54:36 +0200 | |
changeset 111 | 3905a2e66b9b |
permissions | -rw-r--r-- |
jtulach@111 | 1 |
package org.apidesign.reentrant; |
jtulach@111 | 2 |
|
jtulach@111 | 3 |
import java.util.Collection; |
jtulach@111 | 4 |
|
jtulach@111 | 5 |
public class CriticalSectionSynchronized<T extends Comparable<T>> implements CriticalSection<T> { |
jtulach@111 | 6 |
private T pilot; |
jtulach@111 | 7 |
private int cnt; |
jtulach@111 | 8 |
|
jtulach@111 | 9 |
public synchronized void assignPilot(T pilot) { |
jtulach@111 | 10 |
this.pilot = pilot; |
jtulach@111 | 11 |
} |
jtulach@111 | 12 |
|
jtulach@111 | 13 |
public int sumBigger(Collection<T> args) { |
jtulach@111 | 14 |
for (T cmp : args) { |
jtulach@111 | 15 |
if (pilot.compareTo(cmp) < 0) { |
jtulach@111 | 16 |
cnt++; |
jtulach@111 | 17 |
} |
jtulach@111 | 18 |
} |
jtulach@111 | 19 |
return cnt; |
jtulach@111 | 20 |
} |
jtulach@111 | 21 |
|
jtulach@111 | 22 |
public int getCount() { |
jtulach@111 | 23 |
return cnt; |
jtulach@111 | 24 |
} |
jtulach@111 | 25 |
} |