/*********************************************
*Holder Class by: Christian Olienick Plourde*
*********************************************
*Designed to be used to hold values, *
*without having to declare variables. *
*********************************************
*/
public class Holder
{
int[] intValueHolder =
new int[10000];
int[] intValueHolderID =
new int [10000];
String [] intValueName =
new String [10000];
int intLength =
0;
double[] doubleValueHolder =
new double [10000];
int[] doubleValueHolderID =
new int [10000];
String [] doubleValueName =
new String [10000];
int doubleLength =
0;
/*******************************************************
*Creates several integer holders with the same name.
*This also can be accomplished with createIntHolder,
*but it may cause undesired effects to arrays.
*To use, set the name of the holder and number of
*holders to add to the name.
*/
public void addToIntHolder
(String name,
int numValues
){
int preIntLength = intLength+
1+numValues;
for (int i = intLength ; i < preIntLength;i++
){
if (i <
10000){
intValueHolderID
[i
] =
10000+i;
intValueName
[i
] = name;
intLength = i;
}
else if (i ==
10000){
System.
out.
println ("Cannot create holder for "+ name+
".");
}
}
}
/********************************************************
*Creates several double holders with the same name.
*This also can be accomplished with createDoubleHolder,
*but it may cause undesired effects to arrays.
*To use, set the name of the holder and number of
*holders to add to the name.
*/
public void addToDoubleHolder
(String name,
int numValues
){
int preDoubleLength = doubleLength+
1+numValues;
for (int i = doubleLength ; i < preDoubleLength;i++
){
if (i <
10000){
doubleValueHolderID
[i
] =
10000+i;
doubleValueName
[i
] = name;
doubleLength = i;
}
else if (i ==
10000){
System.
out.
println ("Cannot create holder for "+ name+
".");
}
}
}
/********************************************************
*Creates an integer holder for a spesified name, and
*sets the initial value of the holder.
*To use set the name of the holder, then the initial
*value of the holder.
*/
public void createIntHolder
(String name,
int value
){
for (int i =
0;i < intLength+
2; i++
){
if (intValueHolderID
[i
] ==
10000+i
){
if (i ==
10000){
System.
out.
println ("Cannot create a referrence for "+ name+
". Exceeds array Int holder length.");
i = intLength+
2;
}
}
else if (intValueHolderID
[i
] ==
0){
intValueHolderID
[i
] =
10000+i;
intValueName
[i
] = name;
intValueHolder
[i
] = value;
if (intLength > i
) {
}
else if (intLength < i
){
intLength = i;
}
i = intLength+
2;
}
}
}
/********************************************************
*Creates an double holder for a spesified name, and
*sets the initial value of the holder.
*To use set the name of the holder, then the initial
*value of the holder.
*/
public void createDoubleHolder
(String name,
double value
){
for (int i =
0;i < doubleLength+
2; i++
){
if (doubleValueHolderID
[i
] ==
10000+i
){
if (i ==
10000){
System.
out.
println ("Cannot create a referrence for "+ name+
". Exceeds array Int holder length.");
i = doubleLength+
2;
}
}
else if (doubleValueHolderID
[i
] ==
0){
doubleValueHolderID
[i
] =
10000+i;
doubleValueName
[i
] = name;
doubleValueHolder
[i
] = value;
if (doubleLength > i
) {
}
else if (doubleLength < i
){
doubleLength = i;
}
i = doubleLength+
2;
}
}
}
/********************************************************
*Sets a holder's value to what is specified.
*To use, set the name of the holder then the value to
*set the integer value of the holder, and then the
*array value of the holder. If the holder isn't an
*array set the value to 0.
*/
public void setIntHolder
(String name,
int value,
int arrayValue
){
int count =
0;
for (int i =
0; i < intLength+
1;i++
){
if (intValueHolderID
[i
] ==
10000+i & intValueName
[i
] == name
){
if (count == arrayValue
){
intValueHolder
[i
] = value;
i = intLength+
1;
}
else if (count != arrayValue & i == intLength
){
System.
out.
println ("Cannot find holder "+ name +
"of array index "+ value+
".");
}
}
else if (intValueHolderID
[i
] !=
10000+i || intValueName
[i
] != name
){
if (i == intLength
){
System.
out.
println ("Cannot find holder "+ name +
". The holder has not been created.");
}
}
}
}
/********************************************************
*Sets a holder's value to what is specified.
*To use, set the name of the holder then the value to
*set the double value of the holder, and then the
*array value of the holder. If the holder isn't an
*array set the value to 0.
*/
public void setDoubleHolder
(String name,
double value,
int arrayValue
){
int count =
0;
for (int i =
0; i < doubleLength+
1;i++
){
if (doubleValueHolderID
[i
] ==
10000+i & doubleValueName
[i
] == name
){
if (count == arrayValue
){
doubleValueHolder
[i
] = value;
i = doubleLength+
1;
}
else if (count != arrayValue & i == doubleLength
){
System.
out.
println ("Cannot find holder "+ name +
"of array index "+ value+
".");
}
}
else if (doubleValueHolderID
[i
] !=
10000+i || doubleValueName
[i
] != name
){
if (i == doubleLength
){
System.
out.
println ("Cannot find holder "+ name +
". The holder has not been created.");
}
}
}
}
/********************************************************
*Gathers values from a holder and returns them as an
*array. The number of values returned must be specified.
*If there are fewer values avalible then the number of
*values to be returned the values will be set to 0.
*To use set the name of the holder, then the value for
*the length of the array.
*/
public int[] returnArrayIntHolder
(String name,
int scope
){
int[] returnValue =
new int[scope
];
int count =
0;
for (int i =
0; i < intLength+
1; i++
){
if (name == intValueName
[i
]){
returnValue
[count
] = intValueHolder
[i
];
count = count +
1;
if (count > scope
){
i = intLength+
1;
}
}
}
return returnValue;
}
/********************************************************
*Gathers values from a holder and returns them as an
*array. The number of values returned must be specified.
*If there are fewer values avalible then the number of
*values to be returned the values will be set to 0.
*To use set the name of the holder, then the value for
*the length of the array.
*/
public double[] returnArrayDoubleHolder
(String name,
int scope
){
double[] returnValue =
new double[scope
];
int count =
0;
for (int i =
0; i < doubleLength+
1; i++
){
if (name == doubleValueName
[i
]){
returnValue
[count
] = doubleValueHolder
[i
];
count = count +
1;
if (count > scope
){
i = doubleLength+
1;
}
}
}
return returnValue;
}
/********************************************************
*Returns a single integer value from a holder name.
*To use set the name of the holder and the array number.
*If the holder isn't an array, set the array number as 0.
*/
public int returnIntHolder
(String name,
int arrayNum
) {
int returnValue =
0;
int countArrayNum =
0;
boolean returnIsTrue =
false;
for (int i =
0;i < intLength+
1;i++
){
if (name == intValueName
[i
]){
if (countArrayNum == arrayNum
) {
returnValue = intValueHolder
[i
];
returnIsTrue =
true;
}
else if (countArrayNum != arrayNum
) {
countArrayNum = countArrayNum+
1;
}
}
else if (name != intValueName
[i
]){
}
}
if (returnIsTrue ==
false){
System.
out.
println ("Unable to find "+ name +
"of array value "+ arrayNum+
".");
}
return returnValue;
}
/********************************************************
*Returns a single double value from a holder name.
*To use set the name of the holder and the array number.
*If the holder isn't an array, set the array number as 0.
*/
public double returnDoubleHolder
(String name,
int arrayNum
) {
double returnValue =
0;
int countArrayNum =
0;
boolean returnIsTrue =
false;
for (int i =
0;i < doubleLength+
1;i++
){
if (name == doubleValueName
[i
]){
if (countArrayNum == arrayNum
) {
returnValue = doubleValueHolder
[i
];
returnIsTrue =
true;
}
else if (countArrayNum != arrayNum
) {
countArrayNum = countArrayNum+
1;
}
}
else if (name != doubleValueName
[i
]){
}
}
if (returnIsTrue ==
false){
System.
out.
println ("Unable to find "+ name +
"of array value "+ arrayNum+
".");
}
return returnValue;
}
/********************************************************
*Removes an integer holder.
*To use, set the name of the holder to remove.
*This removes array variables and normal.
*/
public void removeIntHolder
(String name
){
for (int i =
0; i < intLength+
1; i++
){
if (name == intValueName
[i
]){
intValueName
[i
] =
"";
intValueHolderID
[i
] =
0;
intValueHolder
[i
] =
0;
}
}
}
/********************************************************
*Removes an real holder.
*To use, set the name of the holder to remove.
*This removes array variables and normal.
*/
public void removeDoubleHolder
(String name
){
for (int i =
0; i < doubleLength+
1; i++
){
if (name == doubleValueName
[i
]){
doubleValueName
[i
] =
"";
doubleValueHolderID
[i
] =
0;
doubleValueHolder
[i
] =
0;
}
}
}
public static void main
(String[] args
){
}
}