samples/reentrant/src/org/apidesign/reentrant/CriticalSectionSynchronized.java
changeset 111 3905a2e66b9b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/reentrant/src/org/apidesign/reentrant/CriticalSectionSynchronized.java	Sat Jun 14 09:54:36 2008 +0200
     1.3 @@ -0,0 +1,25 @@
     1.4 +package org.apidesign.reentrant;
     1.5 +
     1.6 +import java.util.Collection;
     1.7 +
     1.8 +public class CriticalSectionSynchronized<T extends Comparable<T>> implements CriticalSection<T> {
     1.9 +    private T pilot;
    1.10 +    private int cnt;
    1.11 +    
    1.12 +    public synchronized void assignPilot(T pilot) {
    1.13 +        this.pilot = pilot;
    1.14 +    }
    1.15 +
    1.16 +    public int sumBigger(Collection<T> args) {
    1.17 +        for (T cmp : args) {
    1.18 +            if (pilot.compareTo(cmp) < 0) {
    1.19 +                cnt++;
    1.20 +            }
    1.21 +        }
    1.22 +        return cnt;
    1.23 +    }
    1.24 +
    1.25 +    public int getCount() {
    1.26 +        return cnt;
    1.27 +    }
    1.28 +}