public class Pet{
private String type;
public Pet(String type){this.type = type;}
public String getType(){ return type;}
}
public class Cat {
public Cat(){ super("cat");}
}
public class Dog {
public Dog(){ super("dog");}
}
public class PetQueenElement{
private Pet pet;
private int order;
PetQueenElement(Pet pet, int order){
PetQueenElement element = new PetQueenElement(pet, order);
}
public Pet getPet(){
return this.pet;
}
public int getOrder(){
return this.order;
}
}
public class PetQueen{
private int order;
private Queen<PetQueenElement> cats;
private Queen<PetQueenElement> dogs;
public PetQueen(){
this.cats = new LinkedList<>();
this.dogs = new LinkedList<>();
this.order = 0;
}
public void add(Pet pet){
if(pet instanceof Cat){
cats.add(new PetQueenElement(pet, order)));
}else{
dogs.add(new PetQueenElement(pet, order)));;
}
allPets.add(pet);
}
public Pet pollAll(){
if (!cats.isEmpty() && !dogs.isEmpty()){
if (cats.peek().getOrder() > dogs.peek().getOrder()){
return cats.poll().getPet();
}else if(!cat.isEmpty()){
return cats.poll().getPet();
}else if(!dogs.isEmpty()){
return dogs.poll().getPet();
}else{
throw new RuntimeException("err, no pet!!!")
}
}
}
public Cat pollCat(){
if(!cat.isEmpty()){
return cats.poll().getPet();
}
throw new RuntimeException("err, not cat")
}
// 余下省略...
}