OSGi 拍卖应用开发与优化全解析
1. 拍卖应用的实现
1.1 AuctionWrapper 类
AuctionWrapper 类实现了标准的包装器设计模式,将所有方法调用委托给原始的拍卖和参与者对象实例。以下是该类的部分代码:
public AuctionWrapper(Auctioneer delegate, Collection<Auditor> auditors) {
this.delegate = delegate;
this.auditors = auditors;
}
public Float ask(String item, float price, Participant seller) throws InvalidOfferException {
ask = price;
return delegate.getAuction().ask(item, price, new ParticipantWrapper(seller));
}
public Float bid(String item, float price, Participant buyer) throws InvalidOfferException {
List<Float> bids = bidsPerItem.get(item);
if (bids == null) {
bids = new LinkedList<Float>();
bidsPerItem.put(item, bids);
}
bids