samples/reentrant/src/org/apidesign/reentrant/CriticalSectionSynchronized.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 30 Oct 2014 21:30:10 +0100
changeset 409 40cabcdcd2be
permissions -rw-r--r--
Updating to NBMs from NetBeans 8.0.1 as some of them are required to run on JDK8
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
}