src/main/java/pityoulish/i18n/CatalogHelper.java
public static final String format(TextRef tref, Object... params)
    throws RuntimeException
  {
    if (tref == null)
       throw new NullPointerException("TextRef");

    if (tref.getParamCount() < 0)
       throw new IllegalArgumentException("TextRef: "+tref);
    if (params.length != tref.getParamCount())
       throw new IllegalArgumentException("Object...");

    String result = null;
    try {
      ResourceBundle bundle = getBundle(tref);
      String pattern = bundle.getString(tref.getKey());

      if (pattern.length() > 0)
       {
         // This call parses the pattern. If patterns are used frequently, they
         // should be parsed only once and the resulting MessageFormat cached.
         // That's not necessary for the programming exercises though.
         result = MessageFormat.format(pattern, params);
       }
      else
       {
         // an empty pattern is an invalid catalog entry, provide a fallback
         result = fallbackFormat(tref, params);
       }

    } catch (MissingResourceException mre) {
      // the lookup failed, provide a fallback
      result = fallbackFormat(tref, params);
    }
    // ClassCastException from bundle.getString intentionally not handled here,
    // because TextRef should always refer to a text.
    // IllegalArgumentException intentionally not handled here,
    // because it indicates a bad resource or a mismatch
    // between resource bundle and code.

    return result;
  }
/**
   * Formats parameters with a pattern looked up in the default locale.
   *
   * @param tref        text ref of the pattern to look up.
   *                    This must be a reference for formatting,
   *                    with non-negative parameter count.
   * @param params      appropriate number of parameters to format
   *
   * @return the formatted text, or a fallback if the lookup failed
   *
   * @throws RuntimeException   if something other than the lookup fails
   */
Formats parameters with a pattern looked up in the default locale.
@param tref        text ref of the pattern to look up.
This must be a reference for formatting,
with non-negative parameter count.
@param params      appropriate number of parameters to format

@return the formatted text, or a fallback if the lookup failed

@throws RuntimeException   if something other than the lookup fails
Formats parameters with a pattern looked up in the default locale . @param tref text ref of the pattern to look up . This must be a reference for formatting with non - negative parameter count . @param params appropriate number of parameters to format @return the formatted text or a fallback if the lookup failed @throws RuntimeException if something other than the lookup fails
public static final String format(TextRef tref, Object... params)
    throws RuntimeException
  {
    if (tref == null)
       throw new NullPointerException("TextRef");
    if (tref.getParamCount() < 0)
       throw new IllegalArgumentException("TextRef: "+tref);
    if (params.length != tref.getParamCount())
       throw new IllegalArgumentException("Object...");
    String result = null;
    try {
      ResourceBundle bundle = getBundle(tref);
      String pattern = bundle.getString(tref.getKey());
      if (pattern.length() > 0)
       {
         result = MessageFormat.format(pattern, params);
       }
      else
       {
         result = fallbackFormat(tref, params);
       }
    } catch (MissingResourceException mre) {
      result = fallbackFormat(tref, params);
    }
    return result;
  }
public static final String format ( TextRef tref , Object ... params ) throws RuntimeException { if ( tref == null ) throw new NullPointerException ( "TextRef" ) ; if ( tref . getParamCount ( ) < 0 ) throw new IllegalArgumentException ( "TextRef: " + tref ) ; if ( params . length != tref . getParamCount ( ) ) throw new IllegalArgumentException ( "Object..." ) ; String result = null ; try { ResourceBundle bundle = getBundle ( tref ) ; String pattern = bundle . getString ( tref . getKey ( ) ) ; if ( pattern . length ( ) > 0 ) { result = MessageFormat . format ( pattern , params ) ; } else { result = fallbackFormat ( tref , params ) ; } } catch ( MissingResourceException mre ) { result = fallbackFormat ( tref , params ) ; } return result ; }
Formats parameters with a pattern looked up in the default locale.
Formats parameters with a pattern looked up in the default locale .
// This call parses the pattern. If patterns are used frequently, they // should be parsed only once and the resulting MessageFormat cached. // That's not necessary for the programming exercises though. // an empty pattern is an invalid catalog entry, provide a fallback // the lookup failed, provide a fallback // ClassCastException from bundle.getString intentionally not handled here, // because TextRef should always refer to a text. // IllegalArgumentException intentionally not handled here, // because it indicates a bad resource or a mismatch // between resource bundle and code.