|
| |||||||||
| Tags: hashset, java, javautil, listner, programming language, tools, utilities |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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);
}
... |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |