package de.lmu.ifi.tcs; import java.util.ArrayList; import java.util.Iterator; class HundeschuleKorrekt { private ArrayList roster; public HundeschuleKorrekt() { roster = new ArrayList(); } private static boolean isAdmissable(Tier tier) { if (tier.getClass().equals(Hund.class)) return true; return false; } public boolean add(Tier tier) { if (! isAdmissable(tier)) return false; return roster.add(tier); } public boolean addAll(ArrayList tiere) { // Ugh. Iterator it = roster.iterator(); ArrayList admissable = new ArrayList(); while (it.hasNext()) { Tier tier = it.next(); if (isAdmissable(tier)) admissable.add(tier); } return roster.addAll(admissable); } public boolean remove(Tier tier) { return roster.remove(tier); } public ArrayList getTiere() { return roster; } }