class NumberConverter implements ConditionalConverter<Object, Number> {
  public Number convert(MappingContext<Object, Number> context) {
    Object source = context.getSource();
    if (source == null)
      return null;

    Class<?> destinationType = Primitives.wrapperFor(context.getDestinationType());

    if (source instanceof Number)
      return numberFor((Number) source, destinationType);
    if (source instanceof Boolean)
      return numberFor(((Boolean) source).booleanValue() ? 1 : 0, destinationType);
    if (source instanceof Date && Long.class.equals(destinationType))
      return Long.valueOf(((Date) source).getTime());
    if (source instanceof Calendar && Long.class.equals(destinationType))
      return Long.valueOf(((Calendar) source).getTime().getTime());
    if (source instanceof XMLGregorianCalendar && Long.class.equals(destinationType))
      return ((XMLGregorianCalendar) source).toGregorianCalendar().getTimeInMillis();
    return numberFor(source.toString(), destinationType);
  }

  public MatchResult match(Class<?> sourceType, Class<?> destinationType) {
    boolean destMatch = Number.class.isAssignableFrom(Primitives.wrapperFor(destinationType));
    if (destMatch) {
      return Number.class.isAssignableFrom(Primitives.wrapperFor(sourceType))
          || sourceType == Boolean.class || sourceType == Boolean.TYPE
          || sourceType == String.class || Date.class.isAssignableFrom(sourceType)
          || Calendar.class.isAssignableFrom(sourceType)
          || XMLGregorianCalendar.class.isAssignableFrom(sourceType) ? MatchResult.FULL : MatchResult.PARTIAL;
    } else
      return MatchResult.NONE;
  }

  /**
   * Creates a Number for the {@code source} and {@code destinationType}.
   */
  Number numberFor(Number source, Class<?> destinationType) {<FILL_FUNCTION_BODY>}

  /**
   * Creates a Number for the {@code source} and {@code destinationType}.
   */
  Number numberFor(String source, Class<?> destinationType) {
    String sourceString = source.trim();
    if (sourceString.length() == 0)
      return null;

    try {
      if (destinationType.equals(Byte.class))
        return Byte.valueOf(source);
      if (destinationType.equals(Short.class))
        return Short.valueOf(source);
      if (destinationType.equals(Integer.class))
        return Integer.valueOf(source);
      if (destinationType.equals(Long.class))
        return Long.valueOf(source);
      if (destinationType.equals(Float.class))
        return Float.valueOf(source);
      if (destinationType.equals(Double.class))
        return Double.valueOf(source);
      if (destinationType.equals(BigDecimal.class))
        return new BigDecimal(source);
      if (destinationType.equals(BigInteger.class))
        return new BigInteger(source);
    } catch (Exception e) {
      throw new Errors().errorMapping(source, destinationType, e).toMappingException();
    }

    throw new Errors().errorMapping(source, destinationType).toMappingException();
  }
}

    if (destinationType.equals(source.getClass()))
      return source;

    if (destinationType.equals(Byte.class)) {
      long longValue = source.longValue();
      if (longValue > Byte.MAX_VALUE)
        throw new Errors().errorTooLarge(source, destinationType).toMappingException();
      if (longValue < Byte.MIN_VALUE)
        throw new Errors().errorTooSmall(source, destinationType).toMappingException();
      return Byte.valueOf(source.byteValue());
    }

    if (destinationType.equals(Short.class)) {
      long longValue = source.longValue();
      if (longValue > Short.MAX_VALUE)
        throw new Errors().errorTooLarge(source, destinationType).toMappingException();
      if (longValue < Short.MIN_VALUE)
        throw new Errors().errorTooSmall(source, destinationType).toMappingException();
      return Short.valueOf(source.shortValue());
    }

    if (destinationType.equals(Integer.class)) {
      long longValue = source.longValue();
      if (longValue > Integer.MAX_VALUE)
        throw new Errors().errorTooLarge(source, destinationType).toMappingException();
      if (longValue < Integer.MIN_VALUE)
        throw new Errors().errorTooSmall(source, destinationType).toMappingException();
      return Integer.valueOf(source.intValue());
    }

    if (destinationType.equals(Long.class))
      return Long.valueOf(source.longValue());

    if (destinationType.equals(Float.class)) {
      if (source.doubleValue() > Float.MAX_VALUE)
        throw new Errors().errorTooLarge(source, destinationType).toMappingException();
      return Float.valueOf(source.floatValue());
    }

    if (destinationType.equals(Double.class))
      return Double.valueOf(source.doubleValue());

    if (destinationType.equals(BigDecimal.class)) {
      if (source instanceof Float || source instanceof Double)
        return new BigDecimal(source.toString());
      else if (source instanceof BigInteger)
        return new BigDecimal((BigInteger) source);
      else
        return BigDecimal.valueOf(source.longValue());
    }

    if (destinationType.equals(BigInteger.class)) {
      if (source instanceof BigDecimal)
        return ((BigDecimal) source).toBigInteger();
      else
        return BigInteger.valueOf(source.longValue());
    }

    throw new Errors().errorMapping(source, destinationType).toMappingException();
  
<no_super_class>