try { MaintainedItem item = (MaintainedItem)pp.getIndirectObject(); if (!(item.getMaintainedItemType().equals("Inventory"))) { return true; } } catch (ClassCastException exc) { return false; }
  private boolean taskPredicate(Object o, Verb verb, Set resourceTypes) {    if (o instanceof Task) {      Task task = (Task) o;      if (task.getVerb().equals(verb)) {        boolean maintainingOk = false;        boolean forOk = false;        boolean forSelf = false;        boolean isRefill = false;        boolean resourceTypesOk = resourceTypes == null;        for (Enumeration e = task.getPrepositionalPhrases(); e.hasMoreElements(); ) {          PrepositionalPhrase pp = (PrepositionalPhrase) e.nextElement();          String prep = pp.getPreposition();          if (prep.equals(Constants.Preposition.MAINTAINING)) {            if (pp.getIndirectObject() instanceof Inventory) return false;            maintainingOk = true;          } else if (prep.equals(Constants.Preposition.FOR)) {            String orgName = (String) pp.getIndirectObject();            forSelf = orgName.equals(selfOrgName);            if (forSelf && isRefill) return false;            forOk = true;          } else if (prep.equals(Constants.Preposition.REFILL)) {            isRefill = true;            if (forSelf) return false;          } else if (prep.equals(Constants.Preposition.OFTYPE)) {            Object type = pp.getIndirectObject();            if (resourceTypes != null && !resourceTypes.contains(type)) {                return false;            }            resourceTypesOk = true;          }          if (maintainingOk && resourceTypesOk && forOk && !(isRefill && forSelf)) return true;        }      }    }    return false;  }