<commit_before>package com.metova.android.util;

import android.os.Bundle;

public class BundleChecker {

    /**
     * Convenience method for retrieving an object (no primitives) from a {@link android.os.Bundle}.
     * If more than one of the Bundles passed contains an entry with the given key, the first object found is returned.
     * <p>An {@link java.lang.IllegalArgumentException} is thrown if there is no entry with the given key.
     * 
     * <p><b>Sample use in a Fragment:</b>
     * <p>
     * <pre>
      public void onActivityCreated( Bundle savedInstanceState ) {
     
        super.onActivityCreated( savedInstanceState );
        News news = BundleChecker.getExtraOrThrow( "key", new Bundle[]{ getArguments(), savedInstanceState } );
      }
      </pre>
     * 
     * @param key - The key with which to search for in the given <b>bundles</b>
     * @param bundles - an array of {@link android.os.Bundle} to look for an entry with the given <b>key</b>
     * @return The entry with the given key 
     * @throws IllegalArgumentException if there is no entry with the given key
     */
    public static <T> T getExtraOrThrow( final String key, final Bundle... bundles ) {

        T object = getExtra( key, bundles );

        if ( object == null ) {

            throw new IllegalArgumentException( "Key '" + key + "' not contained in bundles." );
        }

        return object;
    }

    /**
     * Convenience method for retrieving an object (no primitives) from a {@link android.os.Bundle}.
     * If more than one of the Bundles passed contains an entry with the given key, the first object found is returned.
     * 
     * <p><b>Sample use in a Fragment:</b>
     * <p>
     * <pre>
      public void onActivityCreated( Bundle savedInstanceState ) {
     
        super.onActivityCreated( savedInstanceState );
        String key = BundleChecker.getExtra( "key", new Bundle[]{ getArguments(), savedInstanceState } );
        if(key != null) {
        
            //...
        }
      }
      </pre>
     * 
     * @param key - The key with which to search for in the given <b>bundles</b>
     * @param bundles - an array of {@link android.os.Bundle} to look for an entry with the given <b>key</b>
     * @return The entry with the given key, or {@code null} if there is no entry with the given key 
     */
    public static <T> T getExtra( final String key, final Bundle... bundles ) {

        Bundle bundle = null;

        for (Bundle b : bundles) {

            if ( b != null && b.containsKey( key ) ) {

                bundle = b;
                break;
            }
        }

        @SuppressWarnings( "unchecked" )
        T object = ( bundle == null ) ? null : (T) bundle.get( key );

        return object;
    }<commit_msg>Added method to BundleChecker to allow passing in a default value<commit_after>package com.metova.android.util;

import android.os.Bundle;

public class BundleChecker {

    /**
     * Convenience method for retrieving an object (no primitives) from a {@link android.os.Bundle}.
     * If more than one of the Bundles passed contains an entry with the given key, the first object found is returned.
     * <p>An {@link java.lang.IllegalArgumentException} is thrown if there is no entry with the given key.
     *
     * <p><b>Sample use in a Fragment:</b>
     * <p>
     * <pre>
      public void onActivityCreated( Bundle savedInstanceState ) {

        super.onActivityCreated( savedInstanceState );
        News news = BundleChecker.getExtraOrThrow( "key", new Bundle[]{ getArguments(), savedInstanceState } );
      }
      </pre>
     *
     * @param key - The key with which to search for in the given <b>bundles</b>
     * @param bundles - an array of {@link android.os.Bundle} to look for an entry with the given <b>key</b>
     * @return The entry with the given key
     * @throws IllegalArgumentException if there is no entry with the given key
     */
    public static <T> T getExtraOrThrow( final String key, final Bundle... bundles ) {

        T object = getExtra( key, bundles );

        if ( object == null ) {

            throw new IllegalArgumentException( "Key '" + key + "' not contained in bundles." );
        }

        return object;
    }

    /**
     * Convenience method for retrieving an object (no primitives) from a {@link android.os.Bundle}.
     * If more than one of the Bundles passed contains an entry with the given key, the first object found is returned.
     *
     * <p><b>Sample use in a Fragment:</b>
     * <p>
     * <pre>
      public void onActivityCreated( Bundle savedInstanceState ) {

        super.onActivityCreated( savedInstanceState );
        String key = BundleChecker.getExtra( "key", new Bundle[]{ getArguments(), savedInstanceState } );
        if(key != null) {

            //...
        }
      }
      </pre>
     *
     * @param key - The key with which to search for in the given <b>bundles</b>
     * @param bundles - an array of {@link android.os.Bundle} to look for an entry with the given <b>key</b>
     * @return The entry with the given key, or {@code null} if there is no entry with the given key
     */
    public static <T> T getExtra( final String key, final Bundle... bundles ) {

        Bundle bundle = null;

        for (Bundle b : bundles) {

            if ( b != null && b.containsKey( key ) ) {

                bundle = b;
                break;
            }
        }

        @SuppressWarnings( "unchecked" )
        T object = ( bundle == null ) ? null : (T) bundle.get( key );

        return object;
    }

	/**
	 * Convenience method for retrieving an object (no primitives) from a
	 * {@link android.os.Bundle}. If more than one of the Bundles passed
	 * contains an entry with the given key, the first object found is returned.
	 * <p>
	 * <b>Sample use in a Fragment:</b>
	 * <p>
	 * 
	 * <pre>
	 * public void onActivityCreated(Bundle savedInstanceState){
	 * 
	 * 	super.onActivityCreated(savedInstanceState);
	 * 	long id = BundleChecker.getExtra(&quot;id&quot;, -1L, getArguments(), savedInstanceState);
	 * }
	 * </pre>
	 * 
	 * @param key
	 *            - The key with which to search for in the given <b>bundles</b>
	 * @param defaultValue
	 *            - The value returned if the <b>key</b> cannot be found in a
	 *            bundle
	 * @param bundles
	 *            - an array of {@link android.os.Bundle} to look for an entry
	 *            with the given <b>key</b>
	 * @return The entry with the given key, or {@code null} if there is no
	 *         entry with the given key
	 */
	public static <T> T getExtra(final String key, T defaultValue, final Bundle... bundles){

		Bundle bundle = null;

		for(Bundle b : bundles) {

			if(b != null && b.containsKey(key)) {

				bundle = b;
				break;
			}
		}

		@SuppressWarnings("unchecked")
		T object = (bundle == null) ? defaultValue : (T) bundle.get(key);

		return object;
	}
{'fraction_non_alphanumeric': 0.10608469431998843, 'fraction_numerical': 0.00014452955629426219, 'mean_word_length': 2.301526717557252, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1463387', 'n_tokens_mistral': 2041, 'n_tokens_neox': 1891, 'n_words': 756}