<commit_before>/*<license>
  Copyright 2004, PeopleWare n.v.
  NO RIGHTS ARE GRANTED FOR THE USE OF THIS SOFTWARE, EXCEPT, IN WRITING,
  TO SELECTED PARTIES.
</license>*/

package be.peopleware.i18n_I;


import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;


/**
 * A simple resource bundle load strategy. We use the default class
 * loader strategy with a given locale. For properties files, if there
 * is no match with the given locale * (<code>basename + &quot;_&quot;
 * + getLocale().toString() + &quot;.properties&quot;</code>) or
 * {@link #getLocale()}returns <code>null</code>, we try the system default
 * locale (<code>basename + &quot;_&quot;
 * + {@link java.util.Locale#getDefault()}.toString()
 * + &quot;.properties&quot;</code>).
 * If there is no match still, the default properties file is used
 * (<code>basename + &quot;.properties&quot;</code>).
 *
 * @author    <NAME>
 * @author    PeopleWare n.v.
 */
public class DefaultResourceBundleLoadStrategy
    implements ResourceBundleLoadStrategy {

  /* <section name="Meta Information"> */
  //------------------------------------------------------------------

  /** {@value} */
  public static final String CVS_REVISION = "$Revision$"; //$NON-NLS-1$
  /** {@value} */
  public static final String CVS_DATE = "$Date$"; //$NON-NLS-1$
  /** {@value} */
  public static final String CVS_STATE = "$State$"; //$NON-NLS-1$
  /** {@value} */
  public static final String CVS_TAG = "$Name$"; //$NON-NLS-1$

  /* </section> */



  /* <construction> */
  //------------------------------------------------------------------

  /**
   * @post      new.getLocale() == null;
   */
  public DefaultResourceBundleLoadStrategy() {
    // NOP
  }

  /* </construction> */



  /* <property name="locale"> */
  //------------------------------------------------------------------

  /**
   * @basic
   */
  public final Locale getLocale() {
    return $locale;
  }

  /**
   * @param     locale
   *            The new value for the locale.
   * @post      new.getLocale() == locale;
   */
  public final void setLocale(final Locale locale) {
    $locale = locale;
  }

  private Locale $locale;

  /* </property> */

  private static final String EMPTY = ""; //$NON-NLS-1$

  /**
   * <p>Load a resource bundle with the given <code>basename</code>,
   * according to this strategy.</p>
   * <p>For properties files, if there is no match with the given locale (
   *  <code>basename + &quot;_&quot; + getLocale().toString()
   *  + &quot;.properties&quot;</code>) or
   *  {@link #getLocale()}returns <code>null</code>, we try the system default
   *  locale (<code>basename + &quot;_&quot;
   *  + Locale.{@link java.util.Locale#getDefault()}.toString()
   *  + &quot;.properties&quot;</code>).</p>
   * <p>If there is no match still, the default properties file is used (
   * <code>basename + &quot;.properties&quot;</code>).</p>
   * <p>The method returns <code>null</code> if no resource bundle was found.</p>
   */
  public ResourceBundle loadResourceBundle(final String basename) {
    ResourceBundle result = null;
    if ((basename != null) && (!basename.equals(EMPTY))) { //$NON-NLS-1$
      Locale locale = null;
      if (getLocale() != null) {
        locale = getLocale();
      }
      else {
        locale = Locale.getDefault();
      }
      try {
        result = ResourceBundle.getBundle(basename, locale);
        // throws MissingResourceException
      }
      catch (MissingResourceException mrExc) {
        // NOP we will return null
      }
    }
    return result;
  }

}
<commit_msg>cleanup done; semantics unchanged, but comment was not correct (changed)<commit_after>/*<license>
Copyright 2004 - $Date$ by PeopleWare n.v..

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</license>*/

package org.ppwcode.i18n_I;


import java.util.Locale;
import static org.ppwcode.metainfo_I.License.Type.APACHE_V2;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.ppwcode.metainfo_I.Copyright;
import org.ppwcode.metainfo_I.License;
import org.ppwcode.metainfo_I.vcs.SvnInfo;
import org.toryt.annotations_I.Basic;
import org.toryt.annotations_I.Expression;
import org.toryt.annotations_I.MethodContract;


/**
 * A simple resource bundle load strategy. We use the default class
 * loader strategy with a given locale, or the default locale if no
 * locale is given.
 *
 * @author    <NAME>
 * @author    PeopleWare n.v.
 */
@Copyright("2004 - $Date$, PeopleWare n.v.")
@License(APACHE_V2)
@SvnInfo(revision = "$Revision$",
         date     = "$Date$")
public class DefaultResourceBundleLoadStrategy
    implements ResourceBundleLoadStrategy {

  /* <property name="locale"> */
  //------------------------------------------------------------------

  @Basic(
    init = @Expression("null")
  )
  public final Locale getLocale() {
    return $locale;
  }

  /**
   * @param     locale
   *            The new value for the locale.
   */
  @MethodContract(post = @Expression("locale == _locale"))
  public final void setLocale(final Locale locale) {
    $locale = locale;
  }

  private Locale $locale;

  /* </property> */



  private static final String EMPTY = "";

  /**
   * <p>Load a resource bundle with the given <code>basename</code>,
   *   according to this strategy.</p>
   * <p>If the {@ink #getLocale()} is not {@code null}, we try to retrieve
   *   the {@link ResourceBundle}-tree for the resource
   *   <code><var>basename</var> + &quot;_&quot; + {@link #getLocale()}.toString()</code>.
   *   If the {@ink #getLocale()} is {@code null}, we try to retrieve
   *   the {@link ResourceBundle}-tree for the resource
   *   <code><var>basename</var> + &quot;_&quot; + {@link Locale#getDefault()}.toString()</code>.
   *   The method returns <code>null</code> if no resource bundle was found.</p>
   */
  @MethodContract(
    post = {
      @Expression("_basename == null || _basename == EMPTY ? null"),
      @Expression("locale != null ? ResourceBundle.getBundle(_basename, locale)"),
      @Expression("locale == null ? ResourceBundle.getBundle(_basename, Locale.default)")
    }
  )
  public ResourceBundle loadResourceBundle(final String basename) {
    ResourceBundle result = null;
    if ((basename != null) && (!basename.equals(EMPTY))) {
      Locale locale = null;
      if (getLocale() != null) {
        locale = getLocale();
      }
      else {
        locale = Locale.getDefault();
      }
      try {
        result = ResourceBundle.getBundle(basename, locale);
        // throws MissingResourceException
      }
      catch (MissingResourceException mrExc) {
        // NOP we will return null
      }
    }
    return result;
  }

}

{'fraction_non_alphanumeric': 0.17122621858075268, 'fraction_numerical': 0.003888348840438828, 'mean_word_length': 2.708547888774459, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6206969', 'n_tokens_mistral': 2180, 'n_tokens_neox': 2116, 'n_words': 612}