aspose file tools*
The moose likes JSP and the fly likes HashSet and the empty operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "HashSet and the empty operator" Watch "HashSet and the empty operator" New topic
Author

HashSet and the empty operator

Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
hi all
i am having a HashSet object as the request attribute.
All i need is to display the values it hold. which i need to do using JSTL.

TO check whether its empty or not i used something like ${empty objHashSet}
but it didn't return true even when the objHashSet is empty...

i donno where i made mistake. any clue....

[ July 11, 2006: Message edited by: Parameswaran Thangavel ]
[ July 11, 2006: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

Why did you change your subject from one that was perfectly appropriate to one that was nonsense?

I've changed it back to something that makes sense.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

My own observations do not support your findings.

The test page:



yeilds:

Is aMap empty? true

Is aSet empty? true
Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
bear,
when i tried the following


i am getting following

is aList empty : true
is aSet empty : true
is aMap empty : true
is PubTrans empty : false // pubTrans is empty
is Non-PubTrans empty : false

pubTrans which is in request scope is empty (which i checked by printing it on the page), but the result it printed is false i donno why???

And also the code below resulted as true....


will setting the object in request scope and retrieving it change their behaviours.......
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

Originally posted by Parameswaran Thangavel:

will setting the object in request scope and retrieving it change their behaviours.......


No.

I have no idea what pubTrans is or how it got set up, so I can't say why you are getting the behavior that you are. You can see from the "aSet test" that empty works as expected when an empty HashSet is tested.
Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
i doubt the way the pubTrans got populated has to do with this bizzare behaviour. bcoz the below lines says it is empty. true is printed in console.


To have more understanding i pasted the code snippet of how the pubTrans and noPubTrans get populated....




i am creating two HashSet object and based on the boolean values returned by
reprocessHelper.publish(pubDetails); i am adding object to one of the hashset. in my case, pubTrans is not populated at all...
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Try to explicitly look into the request scope :
${empty requestScope.pubTrans}

I'm wondering if you have another pubTrans variable already set in the page scope.


[My Blog]
All roads lead to JavaRanch
Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
nope. there is no ohter pubTrans variable available.

And also when i tried the below


the following is displayed in the page.
PubTrans: []
Non-PubTrans: [com.cccis.interfaces.iatpa.reprocess.dataobj.ReprocessResults@2af631, com.cccis.interfaces.iatpa.reprocess.dataobj.ReprocessResults@1ff0777]

but when i tried

it returns false...
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Which web container are you using ?
Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
weblogic server 8.1
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

You're using JSTL 1.0. right ?
I'm not sure how empty works with collections...
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I've just looked at the implementation of JSTL 1.0 by jakarta's taglib:
It checks for null, "", Array, List and Map.
All other collections(like HashSet) will return false.

I can't see this behaviour specified in the spec...
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Oh, found it in the spec:

A.3.8 Empty Operator - empty A
The empty operator is a prefix operator that can be used to determine if a value is
null or empty.
To evaluate empty A
If A is null, return true,
Otherwise, if A is the empty string, then return true.
Otherwise, if A is an empty array, then return true.
Otherwise, if A is an empty Map, return true
Otherwise, if A is an empty List, return true,
Otherwise return false.
Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
hi all
i got the problem hashSet is not supported for ${empty objHashSet}.

But i am surprised how Bear got "Is aSet empty? true".
is this has to do with any version problem. but empty is supported for ArrayList and HashMap,not for HashSet why it is so???


Posted by Bear

My own observations do not support your findings.

The test page:

code:

<%
request.setAttribute( "aMap", new java.util.HashMap() );
request.setAttribute( "aSet", new java.util.HashSet() );
%>
<html>
<body>
<p>Is aMap empty? ${empty aMap}</p>
<p>Is aSet empty? ${empty aSet}</p>
</body>
</html>





yeilds:

quote:Is aMap empty? true

Is aSet empty? true

--------------------
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

First, look at your sample:

You've written aList instead of aSet !

About Bear's result, he is probably using JSP2.0, which supports all type of Collection.
Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
hi Satou
Thanks for your effort.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashSet and the empty operator