avatar

463

More synchronization, to avoid throwing random concurrently modified exceptions. by mrs, 27 Apr, 2008 12:15 PM
Diff this changeset:
AuctionList.java
      package com.jbidwatcher.auction;

import com.jbidwatcher.util.Comparison;

import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

/**
 * Created by IntelliJ IDEA.
* User: Morgan
* Date: Apr 6, 2008
* Time: 3:32:10 PM
* To change this template use File | Settings | File Templates.
*/
public class AuctionList {
  private final List<AuctionEntry> mList = Collections.synchronizedList(new ArrayList<AuctionEntry>());

  public int size() { synchronized(mList) { return mList.size(); } }
  public AuctionEntry get(int i) { synchronized (mList) { return mList.get(i); } }
  public AuctionEntry remove(int i) { synchronized (mList) { return mList.remove(i); } }
  public boolean add(AuctionEntry e) { synchronized (mList) { return mList.add(e); } }

  public AuctionEntry find(Comparison c) {
    synchronized (mList) {
      for (AuctionEntry entry : mList) {
        if (c.match(entry)) return entry;
      }
    }
    return null;
  }

  public List<AuctionEntry> getList() {
    return mList;
  }
}

    

Check out the code: svn co jbidwatcher/trunk/src/com/jbidwatcher/auction/AuctionList.java