/*
 * [TestArraysAsListBacking.java]
 *
 * Summary: Explore Arrays.asList(int[]) backing feature.
 *
 * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.8+
 *
 * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
 *
 * Version History:
 *  1.0 2007-10-03
 */
package com.mindprod.example;

import java.util.Arrays;
import java.util.List;

import static java.lang.System.*;

/**
 * Explore Arrays.asList(int[]) backing feature.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2007-10-03
 * @since 2007-10-03
 */
public class TestArraysAsListBacking
    {
    private static final int DECKSIZE = 52;

    /**
     * main method
     *
     * @param args not used
     */
    public static void main( String[] args )
        {
        Integer deck[] = new Integer[ DECKSIZE ];
        for ( int i = 0; i < DECKSIZE; i++ )
            {
            // autobox
            deck[ i ] = i;
            }
        List<Integer> list = Arrays.asList( deck );
        out.println( list.getClass() );
        // output is:
        // class java.util.Arrays$ArrayList
        // as expected if you look at the asList source code.
        out.println( list.size() );
        // output is:
        // 52
        // as expected
        Object elem = list.get( 0 );
        out.println( elem.getClass() );
        // class java.lang.Integer
        // as you would expect
        // test if backing array store truly tracks as advertised.
        list.set( 0, -1 );
        out.println( list.get( 0 ) );
        // output is:
        // -1
        // as expected
        out.println( deck[ 0 ] );
        // output is:
        // -1
        // as advertised!
        // try growing the List improperly.
        list.add( -2 );
        // Throws UnsupportedOperationException
        }
    }