My reply was a bit to general. Sorry. btw: the fooCollection.visit
should be called visitAll.
Basically it is
public class CountingVisitor extends
DefaultBindingTargetVisitor<Object,Object>{
public int nrOfLinked = 0;
public Object visitLinkedKey(LinkedKeyBinding<?> binding)
{nrOfLinked++; return binding;}
}
CountingVisitor visitor = new CountingVisitor();
for (Binding<?> binding : injector.getBindings().values()) {
binding.acceptTargetVisitor(visitor);
}
sout("There are " + visitor.nrOfLinked + " linked bindings known");
vs.
int nrOfLinked = 0;
for (Binding<?> binding : injector.getBindings().values()) {
if(binding instanceof LinkedKeyBinding){nrOfLinked++;}
}
sout("There are " + nrOfLinked + " linked bindings known");
in this case the second is shorter but normally the visitor is better
idea.
Cheers,
Alen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---