publicvoidadd(Pet pet) { if (pet.getPetType().equals("dog")) { this.dogQueue.add(newPetBox(pet, this.count++)); } elseif (pet.getPetType().equals("cat")) { this.catQueue.add(newPetBox(pet, this.count++)); } else { thrownewRuntimeException("err, not dog or cat"); } }
public Pet pollAll() { if (!this.dogQueue.isEmpty() && !this.catQueue.isEmpty()) { if (this.dogQueue.peek().getCount() < this.catQueue.peek().getCount()) { returnthis.dogQueue.poll().getPet(); } else { returnthis.catQueue.poll().getPet(); } } elseif (!this.dogQueue.isEmpty()) { returnthis.dogQueue.poll().getPet(); } elseif (!this.catQueue.isEmpty()) { returnthis.catQueue.poll().getPet(); } else { thrownewRuntimeException("err, queue is empty!"); } }
public Dog pollDog() { if (!this.isDogQueueEmpty()) { return (Dog) this.dogQueue.poll().getPet(); } else { thrownewRuntimeException("Dog queue is empty!"); } }
public Cat pollCat() { if (!this.isCatQueueEmpty()) { return (Cat) this.catQueue.poll().getPet(); } else { thrownewRuntimeException("Cat queue is empty!"); } }
publicvoidadd(Pet pet) { if (pet.getPetType().equals("dog")) { this.dogQueue.add(newPetBox(pet, this.count++)); } elseif (pet.getPetType().equals("cat")) { this.catQueue.add(newPetBox(pet, this.count++)); } else { thrownewRuntimeException("err, not dog or cat"); } }
public Pet pollAll() { if (!this.dogQueue.isEmpty() && !this.catQueue.isEmpty()) { if (this.dogQueue.peek().getCount() < this.catQueue.peek().getCount()) { returnthis.dogQueue.poll().getPet(); } else { returnthis.catQueue.poll().getPet(); } } elseif (!this.dogQueue.isEmpty()) { returnthis.dogQueue.poll().getPet(); } elseif (!this.catQueue.isEmpty()) { returnthis.catQueue.poll().getPet(); } else { thrownewRuntimeException("err, queue is empty!"); } }
public Dog pollDog() { if (!this.isDogQueueEmpty()) { return (Dog) this.dogQueue.poll().getPet(); } else { thrownewRuntimeException("Dog queue is empty!"); } }
public Cat pollCat() { if (!this.isCatQueueEmpty()) { return (Cat) this.catQueue.poll().getPet(); } else { thrownewRuntimeException("Cat queue is empty!"); } }