Results 1 to 6 of 6

Thread: Listener support for a HashSet

  1. #1
    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.

  2. #2
    Join Date
    Nov 2009
    Posts
    330

    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.

  3. #3
    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.

  4. #4
    Join Date
    Nov 2009
    Posts
    343

    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.

  5. #5
    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);
        }
        
          .........
     
    }

  6. #6
    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);
        }
     
    ...

Similar Threads

  1. JMS listener or MDB
    By Lyandon in forum Software Development
    Replies: 5
    Last Post: 25-07-2010, 03:29 AM
  2. Non-unique element in HashSet
    By New ID in forum Software Development
    Replies: 5
    Last Post: 20-02-2010, 12:57 AM
  3. Listener utility in database
    By Lachlann in forum Software Development
    Replies: 5
    Last Post: 16-02-2010, 11:01 PM
  4. Difference between hashset and hashmap in java
    By ScarFace 01 in forum Software Development
    Replies: 5
    Last Post: 02-02-2010, 09:04 AM
  5. Session Event Listener
    By Adrina_g in forum Software Development
    Replies: 5
    Last Post: 01-02-2010, 08:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,285,069.78753 seconds with 17 queries