//: generics/BankTeller.java
II Очень простая имитация банковского обслуживания.
import java.util.*;
import net.mindview.util.*;
class Customer {
private static long counter = 1; private final long id = counter++; private Customer() {}
public String toStringO { return "Customer " + id; } // Метод для получения объектов Generator: public static Generator<Customer> generatorO { return new Generator<Customer>()
public Customer nextO { return new CustomerO; }
class Teller {
private static long counter = 1; private final long id = counter++; private TellerO {}
public String toStringO { return "Teller " + id; } // Синглетный объект Generator: public static Generator<Teller> generator = new Generator<Teller>() {
public Teller next О { return new TellerO; }
}:
}
public class BankTeller {
public static void serve(Teller t, Customer c) {
System.out.printin(t + " обслуживает " + с);
}
public static void main(String[] args) { Random rand = new Random(47); Queue<Customer> line = new LinkedList<Customer>(); Generators.fillOine, Customer, generator 0, 15): List<Teller> tellers = new ArrayList<Teller>(); Generators.filKtellers, Teller.generator, 4); for(Customer с : line)
serve(tellers.get(rand.nextlnt(tellers.size())), c);
}
} /* Output:
Teller
3
обслуживает
Customer
1
Teller
2