
// ObjektVektorInUt.java

import java.util.*;

/******************************************************************************
/ ObjektVektorInUt.java demonstrerar metoder som tar vektorer med objekt som
/ parameter ocgh returnerar vektor med objekt.
/
/*****************************************************************************/

public class ObjektVektorInUt
{

    public static void main(String[] args)
    {
		StringBuilder[]		s = create();
		
		System.out.println (Arrays.toString (s));
		System.out.println ();
		
		changeByReference (s);
		System.out.println (Arrays.toString (s));
		System.out.println ();
		
		System.out.println (Arrays.toString (changeAndReturnCopy (s)));
		System.out.println ();
		
		System.out.println ("Men originalet är oförändrat:");
		System.out.println (Arrays.toString (s));
		
		System.out.println();
    }


/******************************************************************************
/ create() skapar ett nytt StringBuilder-objekt.
/
/ IN : (-)
/
/ UT : (StringBuilder[])
******************************************************************************/

    public static StringBuilder[] create()
    {
		StringBuilder[]	sb = new StringBuilder[4];
		sb[0] = new StringBuilder("A");
		sb[1] = new StringBuilder("B");
		sb[2] = new StringBuilder("C");
		sb[3] = new StringBuilder("D");
		
		return sb;
	}


/******************************************************************************
/ changeByReferencee() ändrar genom referens det StringBuilder-objekt som ges
/ som parameter.
/
/ IN : (StringBuilder[]) sb : StringBuilder-objekt som skall ändras.
/
/ UT : (void)
/
******************************************************************************/
    public static void changeByReference(StringBuilder[] sb)
    {
		sb[1].append (" <== Modifierad");
	}


/******************************************************************************
/ changeAndReturnCopy() skapar en kopia av det StringBuilder-objekt som ges som
/ parameter, ändrar kopian och returnerar kopian.
/
/ IN : (StringBuilder[]) sb : Originalobjekt (påverkas inte av metoden).
/
/ UT : (StringBuilder[])    : Ändrat objekt.
/
******************************************************************************/
    public static StringBuilder[] changeAndReturnCopy(StringBuilder[] sb)
    {
		StringBuilder[]	s2 = new StringBuilder[sb.length];
		
		for (int i = 0; i < sb.length; i++)
		{
			s2[i] = new StringBuilder (sb[i].toString());
		}
		
		s2[0].append (" <== Också modifierad");
		
		return s2;
	}

}