예제 #1
0
 @Override
 public void add(int index, Outcrosser element) {
   if (index < males.size()) {
     if (element.isFemale())
       throw new IllegalArgumentException(
           "Element in index " + index + " is a male, cannot be replaced by a female");
     males.add(index, element);
   } else {
     if (!element.isFemale())
       throw new IllegalArgumentException(
           "Element in index " + index + " is a female, cannot be replaced by a male");
     females.add(index - males.size(), element);
   }
 }
예제 #2
0
 @Override
 public boolean add(Outcrosser e) {
   if (e.isFemale()) return females.add(e);
   else return males.add(e);
 }