J
Jeff Kish
I'm a rookie.
I have mostly simplistic java experience and deeper c++ experience.
Working with java j2sdk1.4.1_06 I believe.
I don't know what the equivalent of templates is for java.
I'm trying to figure out the best way to determine if a problem occurs, and I
assume it would be by keeping a pair of lists and doing some finds after they
are populated.
Ths situation is I have a method that calls some api I have access to to get
rows from a set of data rows like this:
for (x = 0; x < dataSet.size; x++)
{
Data entry = dataSet.getEntry(x);
String theID = entry.getData("theID"); //dups allowed for "theID"
String theField1 = entry.getData("theField1");
String theField2 = entry.getData("theField2");
}
I would like to build a vector/list/whatever (I think) to keep track of all
the Data entries that have one of two characteristics:
either:
Strings from theField1 and theField2 are both null OR
the Strings from one or both are not null
After I've examined the list I plan on throwning an exception for a business
rule validation - the business rule says:
if any Data entry identified by "theID" has both fields null and there
is any other Data entry with the same "theID" that has either one or
both not null, an exception is thrown.
I was thinking that something like this is reasonable:
Vector String atLeastOneFieldNotNull;
Vector String bothFieldsNull;
for(...)
{
if both field strings null
{
bothFieldsNull.push_back(new String entry.getData("theID"));
}
else
{
atLeastOneFieldNotNull.push_back(new String
entry.getData("theID"));
}
}
boolean foundBadSituation = false;
int nIndex = 0;
int nSize = bothFieldsNull.size();
int nSize2 = atLeastOneFieldNotNull.size();
if ((nSize < 0) && (nSize2 > 0))
{
for (nIndex = 0; nIndex < nSize2; nIndex++)
{
if (atLeastOneFieldNotNull.find(bothFieldsNull[nIndex])
{
throw exception;
}
}
}
comments on the approach, and the "right" java way to do this are both
appreciated.
Thanks
Jeff Kish
I have mostly simplistic java experience and deeper c++ experience.
Working with java j2sdk1.4.1_06 I believe.
I don't know what the equivalent of templates is for java.
I'm trying to figure out the best way to determine if a problem occurs, and I
assume it would be by keeping a pair of lists and doing some finds after they
are populated.
Ths situation is I have a method that calls some api I have access to to get
rows from a set of data rows like this:
for (x = 0; x < dataSet.size; x++)
{
Data entry = dataSet.getEntry(x);
String theID = entry.getData("theID"); //dups allowed for "theID"
String theField1 = entry.getData("theField1");
String theField2 = entry.getData("theField2");
}
I would like to build a vector/list/whatever (I think) to keep track of all
the Data entries that have one of two characteristics:
either:
Strings from theField1 and theField2 are both null OR
the Strings from one or both are not null
After I've examined the list I plan on throwning an exception for a business
rule validation - the business rule says:
if any Data entry identified by "theID" has both fields null and there
is any other Data entry with the same "theID" that has either one or
both not null, an exception is thrown.
I was thinking that something like this is reasonable:
Vector String atLeastOneFieldNotNull;
Vector String bothFieldsNull;
for(...)
{
if both field strings null
{
bothFieldsNull.push_back(new String entry.getData("theID"));
}
else
{
atLeastOneFieldNotNull.push_back(new String
entry.getData("theID"));
}
}
boolean foundBadSituation = false;
int nIndex = 0;
int nSize = bothFieldsNull.size();
int nSize2 = atLeastOneFieldNotNull.size();
if ((nSize < 0) && (nSize2 > 0))
{
for (nIndex = 0; nIndex < nSize2; nIndex++)
{
if (atLeastOneFieldNotNull.find(bothFieldsNull[nIndex])
{
throw exception;
}
}
}
comments on the approach, and the "right" java way to do this are both
appreciated.
Thanks
Jeff Kish