The 'best' (IMHO, YMMV) way to handle a situation like this is to think
not in terms of data elements, but rather in terms of the container.
What you're after is a container with the properties of a Vector, but
which quietly rejects attempts to add items already in the Vector (for
the appropriate sense of equality).  Make the globally-referenced
container be an instance of such a type, and you get the right behavior
everywhere, with no extraneous code changes.

-----Original Message-----
From: Diethelm Guallar, Gonzalo [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 04, 2000 12:53 PM
To: 'Turbine'
Subject: RE: Are things much slower? [LONG]


> > Quick solution: would it be Ok to replace that code with
> > 
> > Vector packages = TurbineResources.getVector("module.packages");
> > String basePackage = GenericLoader.getBasePackage();
> > if (! vector.contains(basePackage))
> > packages.addElement( basePackage );
> > 
> > everywhere? If yes, would this be a candidate for a utility
> > function, and where (what class)?
> 
> That is totally the right way to do it.

I just tested this, and it seems to work. What's best, I'm back
to the original observed performance. Hurrah!

> Send a patch. :-)

Better than that, I'll commit this myself! However, I have
a (code-commit-newbie) question: this could be a routine like

  public static boolean addOnce(Vector v, Object o)
  {
    if (! v.contains( o ))
      v.addElement( o );
  }

Where would this go? Or should I just write those lines
everywhere it's needed (bad form)?

> -jon


-- 
Gonzalo A. Diethelm
[EMAIL PROTECTED]


------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to