class SubscriptionBuilder {

  @SuppressWarnings("unchecked")
  public <T> Function<Subscription, T> mapToSubscriptionClass(final Class<T> clazz) {
    return subscription -> {
      if (clazz.isAssignableFrom(subscription.getClass())) {
        return (T) subscription;
      } else {
        final String msg =
            String.format(
                "%s instance can't be mapped to type %s",
                subscription.getClass().getSimpleName(), clazz.getSimpleName());
        throw new IllegalArgumentException(msg);
      }
    };
  }

}