Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , , ,

Sponsored Links



Listener support for a HashSet

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 10-02-2010
Member
 
Join Date: Dec 2009
Posts: 192
Listener support for a HashSet

Hello,
Is there a way to keep informed of changes (add and remove) that undergoes a HashSet (or more generally a class implementing the interface Set)? I found nothing other than extending the HashSet class and add support for listeners, Is there a different way to do this, if there is one then i am interested. Thank you in advance for your help.
Reply With Quote
  #2  
Old 10-02-2010
Member
 
Join Date: Nov 2009
Posts: 331
Re: Listener support for a HashSet

Hello,
- First, rather than inheriting it more flexible to delegate a set that you pass a parameter, so you can intercept any set. (the same kind of operation that take Stream as a parameter a Stream)
Then, for the achievement is not so galley
- or you quit Eclipse generates allows you to automatically create the delegation on all methods of a member.
-is the fact you through introspection (less fit) using a Proxy class: method "invoke" is called for all method calls of an interface, and then you can remember the true implementation always thinking.
Reply With Quote
  #3  
Old 10-02-2010
Member
 
Join Date: Dec 2009
Posts: 192
Re: Listener support for a HashSet

Hello,
Firstly thank you for your reply. I think I'm going to take a class that delegates the work without going through the Mechanisms of reflection. This is really too heavy I think for such classes. I started in eclipse, how you generate the delegate methods? Thank you again. If you have any answer for this then help let me know.
Reply With Quote
  #4  
Old 10-02-2010
Member
 
Join Date: Nov 2009
Posts: 344
Re: Listener support for a HashSet

Hello,
In another class, you declare an attribute of type Set. You did right "Sources" - "Generate Delegate Methods" and you select all the methods of the Set. Then you can be set to implement your class, and it should compile. I hope you are understanding what I am trying to explain to you. If you have any queries regrading this then do post back and we will try to solve your query.
Reply With Quote
  #5  
Old 10-02-2010
Member
 
Join Date: Nov 2009
Posts: 347
Re: Listener support for a HashSet

Hello,
I have a code with me, just check it out, hopefully it will help you, I think so. Here is the code
Code:
Public class DelegateSet
{
   / / The set 
   private Set sets;
   
   / / Play events
   private Listener lst;
   
    Public DelegateSet(Set sets, Listenet list)
    {
              this.sets  = Sets;
              lst = list;
    } 
 
    Public boolean add(Object e) {
        lst.add(e);
        return sets.add(e);
    }
    
      .........
 
}
Reply With Quote
  #6  
Old 10-02-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: Listener support for a HashSet

Hello,
Here is another code performing the same task, this is almost similar to the above code but I think this is more effective.
Code:
Public class MyClass{
Public void monTraitement(String name, Object o){
/ / Here I capture the method will "name" applied to the object "o"
}
}
Public class delset implements Set
{
   / / The set 
   private Set set;
   
   / / Play events
   private MyClass lst;
   
    Public delset(Set set)
    {this.set = Set;
lst = new MyClass();
}
 
 Public boolean add(Object e) {
       myClass.mntr("add"e);
        return sets.add(e);
    }
 
...
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Listener support for a HashSet"
Thread Thread Starter Forum Replies Last Post
JMS listener or MDB Lyandon Software Development 5 25-07-2010 04:29 AM
Non-unique element in HashSet New ID Software Development 5 20-02-2010 12:57 AM
Listener utility in database Lachlann Software Development 5 16-02-2010 11:01 PM
Difference between hashset and hashmap in java ScarFace 01 Software Development 5 02-02-2010 09:04 AM
Session Event Listener Adrina_g Software Development 5 01-02-2010 08:34 PM


All times are GMT +5.5. The time now is 04:16 AM.