extracting the name of a passed array
is it at all possible to extract the name of an array that is being 'passed' by a method?
examaple:
privatevoidsomemethod (String[] a)
{
......
}
what i want to do is compare this array name with my instance variables (which are arrays as well) through a switch statement, and depending which array it is, perform whatever the method is meant do to.
thanks
[423 byte] By [
aauera] at [2007-10-3 11:55:15]

> is it at all possible to extract the name of an array
> that is being 'passed' by a method?
>
> examaple:
>
> private void somemethod (String[] a)
> {
>......
>
> what i want to do is compare this array name with my
> instance variables (which are arrays as well) through
> a switch statement, and depending which array it is,
> perform whatever the method is meant do to.
>
> thanks
You should never need to do anything like that. Sounds like you have a design issue.
//add the cards to the Win Pile of the player who had the highest card when they have been compared
private void winPile(String[] a, String x, String y)
{
int scan = 0;
while((scan < a.length) && (a[scan] != null))
scan++;
if (a[scan] == null)
{
a[scan] = x;
a[scan+1] = y;
}
}
//add the cards to the War Pile if both cards have equivalent value (suits are not taken into account)
private void warPile(String[] a, String x)
{
int scan = 0;
while((scan < a.length) && (a[scan] != null))
scan++;
if (a[scan] == null)
{
a[scan] = x;
}
}
so both the methods are part of this next method:
//comparing player Hand decks
private void compareDeck(String[] a, String[] b, int i, int round, boolean war)
{
String card1 = a[i];
String card2 = b[i];
if (cardValue(card1) == cardValue(card2))
{
war = !war;
warPile(this.warPile1, card1);warPile(this.warPile2, card2);
System.out.println("Round: " +round+ '\t'+ " Player1: " +card1+
'\t'+ " Player2: " +card2+ '\t'+ " Result: War is on baby! Woohoo!!");
}
else
{
if (cardValue(card1) > cardValue(card2))
{
winPile(this.winPile1, card1, card2);
if (war == true)
{
winWar(this.winPile1, this.warPile1, this.warPile2, card1, card2 );
}
System.out.println("Round: " +round+ '\t'+ " Player1: " +card1+
'\t'+ " Player2: " +card2+ '\t'+ " Result: Player 1 wins");
}
else
{
winPile(this.winPile2, card2, card1);
System.out.println("Round: " +round+ '\t'+ " Player1: " +card1+
'\t'+ " Player2: " +card2+ '\t'+ " Result: Player 2 wins");
}
}
}
now i've just started working on method winWar which if there was a war in the previous round, the next round determines who wins if the cards aren't of equal value. So it performs a similar task, but with different parameters. So that's why I tought there was a way to 'join' all three methods into one hehe.
Message was edited by:
aauer
aauera at 2007-7-15 14:30:19 >
