// Path: third_party/ios_driver/org/uiautomation/ios/wkrdp/model/NodeId.java
// public final class NodeId {
//   private final int id;
// 
//   public NodeId(int id) {
//     this.id = id;
//   }
// 
//   public int getId() {
//     return id;
//   }
// 
//   @Override
//   public String toString() {
//     return "" + id;
//   }
// 
//   @Override
//   public int hashCode() {
//     final int prime = 31;
//     int result = 1;
//     result = prime * result + id;
//     return result;
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (this == obj) {
//       return true;
//     }
//     if (obj == null) {
//       return false;
//     }
//     if (getClass() != obj.getClass()) {
//       return false;
//     }
//     NodeId other = (NodeId) obj;
//     if (id != other.id) {
//       return false;
//     }
//     return true;
//   }
// 
//   public boolean exist() {
//     return id > 0;
//   }
// }


import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Logger;
import org.uiautomation.ios.wkrdp.model.NodeId;
/*
 * Copyright 2012-2013 eBay Software Foundation and ios-driver committers
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package org.uiautomation.ios.wkrdp.events;


public class EventHistory {
  private static final Logger log = Logger.getLogger(EventHistory.class.getName());

  private static final long MAX_AGE = 10 * 1000;

  private final List<Event> events = new CopyOnWriteArrayList<>();

  public EventHistory() {}

  public void add(Event e) {
    if (events.size() >= 50) {
      removeOldEvents();
    }
    events.add(e);
  }

  public void removeEvent(Event e) {
    events.remove(e);
  }

  private void removeOldEvents() {
    int removed = 0;
    for (Event e : events) {
      if (e.getAge() > MAX_AGE) {
        if (events.remove(e)) {
          removed++;
        }
      }
    }
    if (removed == 0) {
      log.warning("events history is growing too fast.");
    }
  }

// Path: third_party/ios_driver/org/uiautomation/ios/wkrdp/model/NodeId.java
// public final class NodeId {
//   private final int id;
// 
//   public NodeId(int id) {
//     this.id = id;
//   }
// 
//   public int getId() {
//     return id;
//   }
// 
//   @Override
//   public String toString() {
//     return "" + id;
//   }
// 
//   @Override
//   public int hashCode() {
//     final int prime = 31;
//     int result = 1;
//     result = prime * result + id;
//     return result;
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (this == obj) {
//       return true;
//     }
//     if (obj == null) {
//       return false;
//     }
//     if (getClass() != obj.getClass()) {
//       return false;
//     }
//     NodeId other = (NodeId) obj;
//     if (id != other.id) {
//       return false;
//     }
//     return true;
//   }
// 
//   public boolean exist() {
//     return id > 0;
//   }
// }


// Path: third_party/ios_driver/org/uiautomation/ios/wkrdp/events/EventHistory.java
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Logger;
import org.uiautomation.ios.wkrdp.model.NodeId;

/*
 * Copyright 2012-2013 eBay Software Foundation and ios-driver committers
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package org.uiautomation.ios.wkrdp.events;


public class EventHistory {
  private static final Logger log = Logger.getLogger(EventHistory.class.getName());

  private static final long MAX_AGE = 10 * 1000;

  private final List<Event> events = new CopyOnWriteArrayList<>();

  public EventHistory() {}

  public void add(Event e) {
    if (events.size() >= 50) {
      removeOldEvents();
    }
    events.add(e);
  }

  public void removeEvent(Event e) {
    events.remove(e);
  }

  private void removeOldEvents() {
    int removed = 0;
    for (Event e : events) {
      if (e.getAge() > MAX_AGE) {
        if (events.remove(e)) {
          removed++;
        }
      }
    }
    if (removed == 0) {
      log.warning("events history is growing too fast.");
    }
  }

  public List<ChildIframeInserted> getInsertedFrames(NodeId parent) {