Actually, the code below would not achieve quite what Rafael suggests, as it
would throw an IllegalArgumentException if null is passed in.

Stephen

----- Original Message -----
From: "Mark Drew" <[EMAIL PROTECTED]>
Actually, this could be accomplished like this:

  Collection coll = PredicatedCollection.decorate(new ArrayList(),
NotNullPredicate.INSTANCE);

(from the Javadocs for PredicatedCollection).

-----Original Message-----
From: Mark Drew [mailto:[EMAIL PROTECTED]
Sent: Friday, July 09, 2004 1:48 PM
To: 'Jakarta Commons Users List'
Subject: RE: [Collections] Add Object to Collection if not null


You could easily subclass
org.apache.commons.collections.collection.AbstractCollectionDecorator to add
this functionality to any Collection.

-----Original Message-----
From: Rafael U. C. Afonso [mailto:[EMAIL PROTECTED]
Sent: Friday, July 09, 2004 11:33 AM
To: Commons Jakarta User
Subject: [Collections] Add Object to Collection if not null


Hello:

I was looking for a method that adds a object in a Collection

if this object is not null, but I did not find it in
Collections. I thought that this method would be useful in
CollectionUtils class. Is there a method like this? If it
does not exist I would like suggest this. It could be
implemented like this:

public static boolean addNotNull(Collection c, Object o) {
   return (o != null)? c.add(o): false;
}


Like Collection.add(Object) returns boolean, this method will
boolean too.
What is your opinion?

Thanks,

Rafael Ubiratam Clemente Afonso
[EMAIL PROTECTED]
---------------------------------
Where is Debug?
Debug is on the Table!

__________________________________________________________________________
Acabe com aquelas janelinhas que pulam na sua tela.
AntiPop-up UOL - � gr�tis!
http://antipopup.uol.com.br/



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


NOTICE: This communication contains information which is confidential to
Realm Business Solutions, Inc. or its subsidiary ("Realm"). If you are not
the intended recipient of this communication, please delete and destroy all
copies. If you are the intended recipient of this communication, you should
not copy, disclose or distribute this communication without Realm's
authority. Any views expressed in this communication are those of the
individual sender, except where the sender specifically states them to be
Realm's views. Except as required by law, Realm does not represent, warrant
or guarantee that the integrity of this communication has been maintained
nor that the communication is free of errors, virus, interception or
interference.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


NOTICE: This communication contains information which is confidential to
Realm Business Solutions, Inc. or its subsidiary ("Realm"). If you are not
the intended recipient of this communication, please delete and destroy all
copies. If you are the intended recipient of this communication, you should
not copy, disclose or distribute this communication without Realm's
authority. Any views expressed in this communication are those of the
individual sender, except where the sender specifically states them to be
Realm's views. Except as required by law, Realm does not represent, warrant
or guarantee that the integrity of this communication has been maintained
nor that the communication is free of errors, virus, interception or
interference.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to