import Buffer from "./Buffer"; import APISample from "../common/data/APISample"; class SimpleBuffer implements Buffer { private arrayBlockingQueue: APISample[]; private readonly size: number; constructor(capacity: number) { this.size = capacity; this.arrayBlockingQueue = []; } offer(apiSample: APISample): boolean { if (this.canOffer()) { this.arrayBlockingQueue.push(apiSample); return true; } return false; } canOffer(): boolean { return this.size > 0 && this.arrayBlockingQueue.length < this.size; } poll(): APISample | undefined { if (this.arrayBlockingQueue.length > 0) { return this.arrayBlockingQueue.shift(); } return undefined; } getContentCount(): number { return this.arrayBlockingQueue.length; } clear(): boolean { this.arrayBlockingQueue = []; return true; } } export default SimpleBuffer;