I several sets of arrays. The first array contains the ID of an item (in the example below, it would be the ID of a particular animal). The second array contains the QTY of that item.
public int[] animals;
public int[] animalsQTY
These are used in the following manner:
animals[0] = 123; // ID for pig, for e.g.
animalsQTY[0] = 4; // 4 pigs
I load values into these arrays from a MySQL database and have several sets of the data so I don't want to write the same loading code over and over again.
The problem is that if I do not load a value from the database into one of these fields, it must be a default value. In a language that allows passing variables by reference, I would send the variables to be updated to the loading method:
Sub LoadFromMySQL(ByVal TableName As String, ByRef UpdateA() As Integer, ByRef UpdateB() As Integer)
Then only change items in the provided arrays when a relating record is found in the MySQL database.
If I only had the one pair of arrays, I would do something similar to:
results = getMySQLresults();
foreach results as result
animals[result['slot']] = result['id'];
animalsQTY[result['slot']] = result['qty'];
end foreach
Yet I have lots of arrays to update. How can I turn the above pseudocode into a Java function / method?