Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 43
Registered: ‎11-14-2011
My Device: Cure 9300 3G
My Carrier: Vodacom South Africa
Accepted Solution

Can this method be optimized any further?

This method tests if a specific root is mounted. Can it be optimized any further or structured differently? 

 

public boolean rootExists(String root)
{
for (Enumeration e = FileSystemRegistry.listRoots(); e.hasMoreElements();)
if (root.equals( e.nextElement() ) ) return true;
return false;
}

 

 

Developer
Posts: 206
Registered: ‎02-22-2011
My Device: BB TORCH & 9800
My Carrier: idea

Re: Can this method be optimized any further?

can you specify clearly whats the requirement.
*****************************************************************************
* Give kudos when you like it
* Mark it as a solution if it fixes your issue
Contributor
Posts: 43
Registered: ‎11-14-2011
My Device: Cure 9300 3G
My Carrier: Vodacom South Africa

Re: Can this method be optimized any further?

The method's contract is simply to return true if a spefic root is mounted. The reason can be performance or readablilty. I am just cuirious to see if this method can be structed differently. 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Can this method be optimized any further?

I guess my question is why is this important? 

 

This routine will, in most programs anyway, be executed infrequently, so the performance aspect is not that relevant.  I guess its performance could be improved marginally perhaps by retaining the selected list and putting them in some Hashtable that can be searched faster

 

I don't think it is particularly readable, I always like to see brackets around even single statement ifs, but it is OK.  And readability is often personal preference. 

 

So yes it can be structured differently and yes it could perform faster, but why would you bother?

Contributor
Posts: 43
Registered: ‎11-14-2011
My Device: Cure 9300 3G
My Carrier: Vodacom South Africa

Re: Can this method be optimized any further?

Thanks for the reply Peter. I am just quering that what I deem straight forward.