Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

recursion Performance , Global Var

 
EM. Lashkar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a mehod in a bean which returns a Set of "All" generations of subBusinesses ( Children) for a given business.
/************************************/
public Set getAllChildren3( String p_orgId){

Object l_busParentObj1 = null;


Map l_tempMap1 = new HashMap();
Set l_tempSet1 = new TreeSet();



// Getting all the 1st gen children
l_tempMap1= (Map)getChildBusMap( p_orgId) ;


if ( l_tempMap1.size()>0)
{
tempSet.addAll(l_tempMap1.keySet());
l_tempSet1.addAll(l_tempMap1.keySet());
for (Iterator iTemp1=l_tempSet1.iterator(); iTemp1.hasNext(); )
{
l_busParentObj1= iTemp1.next();
if ( isThereChildBus(l_busParentObj1.toString()))
getAllChildren3( l_busParentObj1.toString());
}
}
return tempSet ;
}
/************************************/
// the method "getChildBusMap(" returns the immediate subBusiness( 1st generation Children) for a given Business
// where "tempSet" is a global reUsable Set Object, currently using only in this method.
The method works just fine , but I hate the fact that I had to use aglobal variable ! Its lot of work to keep track of global variables . Do you have any suggestion as to HOW I COULD USE A LOCAL VARIABLE in this recursion in place of "tempSet".
Any other design suggestion ?
Thx in dvance for reading this.
ML
[ February 22, 2003: Message edited by: EM. Lashkar ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic