I'm not thrilled with this implementation, but it seemed less evil than dragging e.g. Commons Collections or Guava in to do this..