/**
   * Find a foreground event consumer by ID.
   *
   * @param displayId ID of the display
   * @return a foreground event consumer object or null if not found
   */
  public ForegroundEventConsumer findForegroundEventConsumer(int displayId) {
    DisplayAccess da = findDisplayById(displayId);

    if (da == null) {
      return null;
    }

    return da.getForegroundEventConsumer();
  }
  /**
   * Removes display objects by the owner name from the container.
   *
   * @param owner the MIDlet that owns this display
   * @return true if display has been succcessfully removed, false, if display object has not been
   *     found in the container.
   */
  public synchronized boolean removeDisplaysByOwner(Object owner) {
    int size = displays.size();

    for (int i = size; --i >= 0; ) {
      DisplayAccess current = (DisplayAccess) displays.elementAt(i);

      if (current.getOwner() == owner) {
        displays.removeElementAt(i);
      }
    }
    return (displays.size() < size);
  }
  /**
   * Find a display by ID.
   *
   * @param displayId ID of the display
   * @return a display access object or null if not found
   */
  public synchronized DisplayAccess findDisplayById(int displayId) {
    int size = displays.size();

    for (int i = 0; i < size; i++) {
      DisplayAccess current = (DisplayAccess) displays.elementAt(i);

      if (current.getDisplayId() == displayId) {
        return current;
      }
    }

    return null;
  }
  /**
   * Find a primary display by owner.
   *
   * @param owner class of the MIDlet that owns this display
   * @return a display access object or null if not found
   */
  public synchronized DisplayAccess findPrimaryDisplayByOwner(Object owner) {
    int size = displays.size();
    DisplayAccess d = null;

    for (int i = 0; i < size; i++) {
      DisplayAccess current = (DisplayAccess) displays.elementAt(i);

      if ((current.getOwner() == owner) && current.getDisplayDevice().isPrimaryDisplay()) {
        d = current;
        break;
      }
    }

    return d;
  }
 /**
  * Adds a display object to the container and sets a the display's ID to new unique value for this
  * isolate, as a single atomic operation.
  *
  * <p>Intended to be called from Display constructor.
  *
  * @param da display object to add
  */
 public synchronized void addDisplay(DisplayAccess da) {
   if (displays.indexOf(da) == -1) {
     int newId = createDisplayId();
     da.setDisplayId(newId);
     displays.addElement(da);
   }
 }
  /**
   * Find all display event consumers.
   *
   * @return a display event consumer array object
   */
  public DisplayEventConsumer[] getAllDisplayEventConsumers() {

    int size = displays.size();
    DisplayEventConsumer[] consumers = new DisplayEventConsumer[size];
    DisplayAccess da;

    for (int i = 0; i < size; i++) {
      da = (DisplayAccess) displays.elementAt(i);

      if (da != null) {
        consumers[i] = da.getDisplayEventConsumer();
      }
    }

    return consumers;
  }
  /**
   * Find the displays by hardwareId.
   *
   * @return array of display access objects or null if not found
   */
  public synchronized DisplayAccess[] findDisplaysByHardwareId(int hardwareId) {
    int size = displays.size();
    Vector v = new Vector(2, 2);
    System.out.println("size = " + size);

    for (int i = 0; i < size; i++) {
      DisplayAccess current = (DisplayAccess) displays.elementAt(i);

      if (current.getDisplayDevice().getHardwareId() == hardwareId) {
        v.addElement(current);
      }
    }

    DisplayAccess[] ret = null;
    if (v.size() > 0) {
      ret = new DisplayAccess[v.size()];
      v.copyInto(ret);
    }

    return ret;
  }
  /**
   * Find the displays by owner.
   *
   * @param owner the object that owns the display
   * @param capabilities display device capbilities filter
   * @return array of display access objects or null if not found
   */
  public synchronized DisplayAccess[] findDisplaysByOwner(Object owner, int capabilities) {
    int size = displays.size();
    Vector v = new Vector(2, 2);

    for (int i = 0; i < size; i++) {
      DisplayAccess current = (DisplayAccess) displays.elementAt(i);

      if ((current.getOwner() == owner)
          && (current.getDisplayDevice().getCapabilities() & capabilities) == capabilities) {
        v.addElement(current);
      }
    }

    DisplayAccess[] ret = null;
    if (v.size() > 0) {
      ret = new DisplayAccess[v.size()];
      v.copyInto(ret);
    }

    return ret;
  }