Discussion:
CollectionComponentParameter works differently with generic Collection types?
Daniel Wellman
2008-11-25 01:05:27 UTC
Permalink
Has the behavior of CollectionComponentParameter changed now that Pico 2
recognizes generic collection parameter types?

In the example below, I expected that adding a CollectionComponentParameter
with a componentValueType of Cod.class would only have Cod fish in the bowl,
but I observe that it gets both Cod and Shark.

If I repeat the experiment by making the Bowl have a type-erased List, the
test works as I expect -- I only get a Cod.

Is this the expected behavior for typed collections?

Test below:


public void testRegisteringSubsetOfGenericCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Cod.class, false));


GenericBowl bowl = pico.getComponent(GenericBowl.class);
// FAILS with PicoContainer 2.7-SNAPSHOT, returns 2
assertEquals(1, bowl.fishes.size());
}

// Types

public static interface Fish {
}

public static class Cod implements Fish {
}

public static class Shark implements Fish {
}

public static class GenericBowl {
List<Fish> fishes;

public GenericBowl(List<Fish> fishes) {
this.fishes = fishes;
}
}



... but this one passes:



public void testRegisteringSubsetOfTypeErasedCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Fish.class, false));


GenericBowl bowl = pico.getComponent(GenericBowl.class);
assertEquals(2, bowl.fishes.size());
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Cod.class)));
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Shark.class)));
}


public static class TypeErasedListBowl {
List fishes;

public TypeErasedListBowl(List fishes) {
this.fishes = fishes;
}
}
--
View this message in context: http://www.nabble.com/CollectionComponentParameter-works-differently-with-generic-Collection-types--tp20673363p20673363.html
Sent from the NanoContainer - PicoContainer - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Paul Hammant
2008-11-26 00:15:56 UTC
Permalink
It could be Daniel. Ill compare your case for PicoContainer 2.4 and
latest to observe (and fix?) the difference.

Regards,

- Paul
Post by Daniel Wellman
Has the behavior of CollectionComponentParameter changed now that Pico 2
recognizes generic collection parameter types?
In the example below, I expected that adding a
CollectionComponentParameter
with a componentValueType of Cod.class would only have Cod fish in the bowl,
but I observe that it gets both Cod and Shark.
If I repeat the experiment by making the Bowl have a type-erased List, the
test works as I expect -- I only get a Cod.
Is this the expected behavior for typed collections?
public void testRegisteringSubsetOfGenericCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Cod.class, false));
GenericBowl bowl = pico.getComponent(GenericBowl.class);
// FAILS with PicoContainer 2.7-SNAPSHOT, returns 2
assertEquals(1, bowl.fishes.size());
}
// Types
public static interface Fish {
}
public static class Cod implements Fish {
}
public static class Shark implements Fish {
}
public static class GenericBowl {
List<Fish> fishes;
public GenericBowl(List<Fish> fishes) {
this.fishes = fishes;
}
}
public void
testRegisteringSubsetOfTypeErasedCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Fish.class, false));
GenericBowl bowl = pico.getComponent(GenericBowl.class);
assertEquals(2, bowl.fishes.size());
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Cod.class)));
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Shark.class)));
}
public static class TypeErasedListBowl {
List fishes;
public TypeErasedListBowl(List fishes) {
this.fishes = fishes;
}
}
--
View this message in context: http://www.nabble.com/CollectionComponentParameter-works-differently-with-generic-Collection-types--tp20673363p20673363.html
Sent from the NanoContainer - PicoContainer - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Paul Hammant
2008-11-27 12:00:55 UTC
Permalink
Well I can reproduce this easily enough. I'm playing with
alternatives for fixing it Daniel...

Regards,

- Paul
Post by Daniel Wellman
Has the behavior of CollectionComponentParameter changed now that Pico 2
recognizes generic collection parameter types?
In the example below, I expected that adding a
CollectionComponentParameter
with a componentValueType of Cod.class would only have Cod fish in the bowl,
but I observe that it gets both Cod and Shark.
If I repeat the experiment by making the Bowl have a type-erased List, the
test works as I expect -- I only get a Cod.
Is this the expected behavior for typed collections?
public void testRegisteringSubsetOfGenericCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Cod.class, false));
GenericBowl bowl = pico.getComponent(GenericBowl.class);
// FAILS with PicoContainer 2.7-SNAPSHOT, returns 2
assertEquals(1, bowl.fishes.size());
}
// Types
public static interface Fish {
}
public static class Cod implements Fish {
}
public static class Shark implements Fish {
}
public static class GenericBowl {
List<Fish> fishes;
public GenericBowl(List<Fish> fishes) {
this.fishes = fishes;
}
}
public void
testRegisteringSubsetOfTypeErasedCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Fish.class, false));
GenericBowl bowl = pico.getComponent(GenericBowl.class);
assertEquals(2, bowl.fishes.size());
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Cod.class)));
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Shark.class)));
}
public static class TypeErasedListBowl {
List fishes;
public TypeErasedListBowl(List fishes) {
this.fishes = fishes;
}
}
--
View this message in context: http://www.nabble.com/CollectionComponentParameter-works-differently-with-generic-Collection-types--tp20673363p20673363.html
Sent from the NanoContainer - PicoContainer - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Daniel Wellman
2008-11-27 14:29:18 UTC
Permalink
Paul,
Thanks for taking a look at this!

Cheers,
Dan
Well I can reproduce this easily enough. I'm playing with alternatives for
fixing it Daniel...
Regards,
- Paul
Post by Daniel Wellman
Has the behavior of CollectionComponentParameter changed now that Pico 2
recognizes generic collection parameter types?
In the example below, I expected that adding a
CollectionComponentParameter
with a componentValueType of Cod.class would only have Cod fish in the bowl,
but I observe that it gets both Cod and Shark.
If I repeat the experiment by making the Bowl have a type-erased List, the
test works as I expect -- I only get a Cod.
Is this the expected behavior for typed collections?
public void testRegisteringSubsetOfGenericCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Cod.class, false));
GenericBowl bowl = pico.getComponent(GenericBowl.class);
// FAILS with PicoContainer 2.7-SNAPSHOT, returns 2
assertEquals(1, bowl.fishes.size());
}
// Types
public static interface Fish {
}
public static class Cod implements Fish {
}
public static class Shark implements Fish {
}
public static class GenericBowl {
List<Fish> fishes;
public GenericBowl(List<Fish> fishes) {
this.fishes = fishes;
}
}
public void testRegisteringSubsetOfTypeErasedCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Fish.class, false));
GenericBowl bowl = pico.getComponent(GenericBowl.class);
assertEquals(2, bowl.fishes.size());
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Cod.class)));
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Shark.class)));
}
public static class TypeErasedListBowl {
List fishes;
public TypeErasedListBowl(List fishes) {
this.fishes = fishes;
}
}
--
http://www.nabble.com/CollectionComponentParameter-works-differently-with-generic-Collection-types--tp20673363p20673363.html
Sent from the NanoContainer - PicoContainer - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Paul Hammant
2008-11-29 14:01:45 UTC
Permalink
Fixed I think. Jar by separate email.


Regards,

- Paul
Post by Daniel Wellman
Paul,
Thanks for taking a look at this!
Cheers,
Dan
Well I can reproduce this easily enough. I'm playing with
alternatives for fixing it Daniel...
Regards,
- Paul
Has the behavior of CollectionComponentParameter changed now that Pico 2
recognizes generic collection parameter types?
In the example below, I expected that adding a
CollectionComponentParameter
with a componentValueType of Cod.class would only have Cod fish in the bowl,
but I observe that it gets both Cod and Shark.
If I repeat the experiment by making the Bowl have a type-erased List, the
test works as I expect -- I only get a Cod.
Is this the expected behavior for typed collections?
public void testRegisteringSubsetOfGenericCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Cod.class, false));
GenericBowl bowl = pico.getComponent(GenericBowl.class);
// FAILS with PicoContainer 2.7-SNAPSHOT, returns 2
assertEquals(1, bowl.fishes.size());
}
// Types
public static interface Fish {
}
public static class Cod implements Fish {
}
public static class Shark implements Fish {
}
public static class GenericBowl {
List<Fish> fishes;
public GenericBowl(List<Fish> fishes) {
this.fishes = fishes;
}
}
public void testRegisteringSubsetOfTypeErasedCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Fish.class, false));
GenericBowl bowl = pico.getComponent(GenericBowl.class);
assertEquals(2, bowl.fishes.size());
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Cod.class)));
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Shark.class)));
}
public static class TypeErasedListBowl {
List fishes;
public TypeErasedListBowl(List fishes) {
this.fishes = fishes;
}
}
--
View this message in context: http://www.nabble.com/CollectionComponentParameter-works-differently-with-generic-Collection-types--tp20673363p20673363.html
Sent from the NanoContainer - PicoContainer - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Loading...