You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Johannes Schneider (JIRA)" <ji...@apache.org> on 2008/04/10 15:32:07 UTC

[jira] Created: (WICKET-1512) Widen Generics for Lists/Iteratos

Widen Generics for Lists/Iteratos
---------------------------------

                 Key: WICKET-1512
                 URL: https://issues.apache.org/jira/browse/WICKET-1512
             Project: Wicket
          Issue Type: Bug
          Components: wicket
    Affects Versions: 1.4-M1
            Reporter: Johannes Schneider


It is important to widen the generics for collections.
For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:

Iterator<? extends T> iterator(int first, int count);

I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WICKET-1512) Widen Generics for Lists/Iteratos

Posted by "Johannes Schneider (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Johannes Schneider updated WICKET-1512:
---------------------------------------

    Attachment: Widening_Generics_for_IDataProvider.patch

Widening Generics for IDataProvider. Everything compiles fine. I changed ContactDataProvider to show the consequences.....

> Widen Generics for Lists/Iteratos
> ---------------------------------
>
>                 Key: WICKET-1512
>                 URL: https://issues.apache.org/jira/browse/WICKET-1512
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-M1
>            Reporter: Johannes Schneider
>            Assignee: Johan Compagner
>         Attachments: Widening_Generics_for_IDataProvider.patch
>
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-1512) Widen Generics for Lists/Iteratos

Posted by "Johannes Schneider (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12588731#action_12588731 ] 

Johannes Schneider commented on WICKET-1512:
--------------------------------------------

Two things: Why didn't you add the type parameter to org.apache.wicket.markup.repeater.data.IDataProviderExample.NumberProvider#model?
I think it is missing there.

And here comes the example showing the problem with the missing "? extends". 

[code]
public class IDataProviderExample {
  public static void main( String[] args ) {
    List<Integer> integers = Arrays.asList( 1, 2, 3, 4 );
    List<Double> doubles = Arrays.asList( 1.0, 2.0, 3.0, 4.0 );

    IDataProvider<Number> myProvider0 = new NumberProvider( integers );
    IDataProvider<Number> myProvider1 = new NumberProvider( doubles );

  }

  private static class NumberProvider implements IDataProvider<Number> {
    private final List<? extends Number> backingList;

    private NumberProvider( List<? extends Number> backingList ) {
      this.backingList = backingList;
    }

    public Iterator<Number> iterator( int first, int count ) {
      return backingList.subList( first, first + count ).iterator();
    }

    public int size() {
      return backingList.size();
    }

    public IModel<Number> model( Number object ) {
      return new Model( object );
    }

    public void detach() {
    }
  }
}
[/code]

Explanation: http://blog.cedarsoft.eu/


And yes, I know that it is annoying to type the additional "? extends" all the time. But remember that a Collection<? extends Foo> is something completely different than Collection<Foo>.

Many times programmers the programmers avoid using "? extends" to realize later that they should fix that later (but now it is an incomaptible change). 
GlazedList is such an example where the things went completely wrong. They fixed some issues within the latest snapshots - but not all...

And poorly used Generics are the root of all evil ;-) - at least things are messed up...




> Widen Generics for Lists/Iteratos
> ---------------------------------
>
>                 Key: WICKET-1512
>                 URL: https://issues.apache.org/jira/browse/WICKET-1512
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-M1
>            Reporter: Johannes Schneider
>            Assignee: Igor Vaynberg
>             Fix For: 1.4-M1
>
>         Attachments: two_parameters.patch, Widening_Generics_for_IDataProvider.patch
>
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (WICKET-1512) Widen Generics for Lists/Iteratos

Posted by "Johan Compagner (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Johan Compagner reassigned WICKET-1512:
---------------------------------------

    Assignee: Johan Compagner

i wait for your patch..

> Widen Generics for Lists/Iteratos
> ---------------------------------
>
>                 Key: WICKET-1512
>                 URL: https://issues.apache.org/jira/browse/WICKET-1512
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-M1
>            Reporter: Johannes Schneider
>            Assignee: Johan Compagner
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WICKET-1512) Widen Generics for Lists/Iteratos

Posted by "Johannes Schneider (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Johannes Schneider updated WICKET-1512:
---------------------------------------

    Attachment: widening_collections.patch

One more patch that widens some other collections, too.

> Widen Generics for Lists/Iteratos
> ---------------------------------
>
>                 Key: WICKET-1512
>                 URL: https://issues.apache.org/jira/browse/WICKET-1512
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-M1
>            Reporter: Johannes Schneider
>            Assignee: Igor Vaynberg
>             Fix For: 1.4-M1
>
>         Attachments: two_parameters.patch, widening_collections.patch, Widening_Generics_for_IDataProvider.patch
>
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (WICKET-1512) Widen Generics for Lists/Iteratos

Posted by "Johannes Schneider (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12587638#action_12587638 ] 

shake edited comment on WICKET-1512 at 4/10/08 6:41 AM:
---------------------------------------------------------------------

...

      was (Author: shake):
    Okay, the example is stupid. IDataProvider misses one parameter. So forget that method...
  
> Widen Generics for Lists/Iteratos
> ---------------------------------
>
>                 Key: WICKET-1512
>                 URL: https://issues.apache.org/jira/browse/WICKET-1512
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-M1
>            Reporter: Johannes Schneider
>            Assignee: Johan Compagner
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (WICKET-1512) Widen Generics for Lists/Iteratos

Posted by "Johan Compagner (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Johan Compagner reassigned WICKET-1512:
---------------------------------------

    Assignee: Igor Vaynberg  (was: Johan Compagner)

igor: IDataprovider is more you baby.
Can you check these generics..

> Widen Generics for Lists/Iteratos
> ---------------------------------
>
>                 Key: WICKET-1512
>                 URL: https://issues.apache.org/jira/browse/WICKET-1512
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-M1
>            Reporter: Johannes Schneider
>            Assignee: Igor Vaynberg
>         Attachments: two_parameters.patch, Widening_Generics_for_IDataProvider.patch
>
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WICKET-1512) Widen Generics for Lists/Iteratos

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Vaynberg resolved WICKET-1512.
-----------------------------------

    Resolution: Fixed

> Widen Generics for Lists/Iteratos
> ---------------------------------
>
>                 Key: WICKET-1512
>                 URL: https://issues.apache.org/jira/browse/WICKET-1512
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-M1
>            Reporter: Johannes Schneider
>            Assignee: Igor Vaynberg
>             Fix For: 1.4-M1
>
>         Attachments: two_parameters.patch, widening_collections.patch, Widening_Generics_for_IDataProvider.patch
>
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WICKET-1512) Widen Generics for Lists/Iteratos

Posted by "Johannes Schneider (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Johannes Schneider updated WICKET-1512:
---------------------------------------

    Attachment: two_parameters.patch

Maybe I am wrong - so please correct me.
But I think this version is more correct.

org.apache.wicket.markup.repeater.data.IDataProvider#iterator doesn't return the same type as model() in every case. There could happen some magic within the model() method that creates some sort of representation.


> Widen Generics for Lists/Iteratos
> ---------------------------------
>
>                 Key: WICKET-1512
>                 URL: https://issues.apache.org/jira/browse/WICKET-1512
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-M1
>            Reporter: Johannes Schneider
>            Assignee: Johan Compagner
>         Attachments: two_parameters.patch, Widening_Generics_for_IDataProvider.patch
>
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WICKET-1512) Widen Generics for Lists/Iteratos

Posted by "Johannes Schneider (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Johannes Schneider updated WICKET-1512:
---------------------------------------

    Comment: was deleted

> Widen Generics for Lists/Iteratos
> ---------------------------------
>
>                 Key: WICKET-1512
>                 URL: https://issues.apache.org/jira/browse/WICKET-1512
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-M1
>            Reporter: Johannes Schneider
>            Assignee: Johan Compagner
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-1512) Widen Generics for Lists/Iteratos

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12588325#action_12588325 ] 

Igor Vaynberg commented on WICKET-1512:
---------------------------------------

i definitely do not like the two types on idataprovider. any mentioned transformation can occur as an iterator adapter returned from iterator() method. 99% of cases declaring idataprovider<person,person> will get incredibly annoying.

also widening i am not sure about. what is the usecase there? in order for widening to be needed you have to explicitly return a super-typed iterator. so why not properly declare the idataprovider type in the first place?

> Widen Generics for Lists/Iteratos
> ---------------------------------
>
>                 Key: WICKET-1512
>                 URL: https://issues.apache.org/jira/browse/WICKET-1512
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-M1
>            Reporter: Johannes Schneider
>            Assignee: Igor Vaynberg
>             Fix For: 1.4-M1
>
>         Attachments: two_parameters.patch, Widening_Generics_for_IDataProvider.patch
>
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-1512) Widen Generics for Lists/Iteratos

Posted by "Johannes Schneider (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12588596#action_12588596 ] 

Johannes Schneider commented on WICKET-1512:
--------------------------------------------

You are right: Having two types is very, very annoying. I suggest to avoid that (I just created that patch - didn't apply it at my local code base - nobody wants to apply it ;-).

I just wanted to start a discussion about that. I think it *is* possible to return an iterator of foo while the getModel() method returns a model containing bar.
I don't know if that is a misuse or not. But if you decide to add only *one* parameter, you should know that you might break some code...


About the widening: I will create a sample that shows the problem...

> Widen Generics for Lists/Iteratos
> ---------------------------------
>
>                 Key: WICKET-1512
>                 URL: https://issues.apache.org/jira/browse/WICKET-1512
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-M1
>            Reporter: Johannes Schneider
>            Assignee: Igor Vaynberg
>             Fix For: 1.4-M1
>
>         Attachments: two_parameters.patch, Widening_Generics_for_IDataProvider.patch
>
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-1512) Widen Generics for Lists/Iteratos

Posted by "Johannes Schneider (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12587638#action_12587638 ] 

Johannes Schneider commented on WICKET-1512:
--------------------------------------------

Okay, the example is stupid. IDataProvider misses one parameter. So forget that method...

> Widen Generics for Lists/Iteratos
> ---------------------------------
>
>                 Key: WICKET-1512
>                 URL: https://issues.apache.org/jira/browse/WICKET-1512
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-M1
>            Reporter: Johannes Schneider
>            Assignee: Johan Compagner
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WICKET-1512) Widen Generics for Lists/Iteratos

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-1512?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Vaynberg updated WICKET-1512:
----------------------------------

    Fix Version/s: 1.4-M1

> Widen Generics for Lists/Iteratos
> ---------------------------------
>
>                 Key: WICKET-1512
>                 URL: https://issues.apache.org/jira/browse/WICKET-1512
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-M1
>            Reporter: Johannes Schneider
>            Assignee: Igor Vaynberg
>             Fix For: 1.4-M1
>
>         Attachments: two_parameters.patch, Widening_Generics_for_IDataProvider.patch
>
>
> It is important to widen the generics for collections.
> For example it is better (and sometimes necessary) to change the signature of  org.apache.wicket.markup.repeater.data.IDataProvider#iterator to:
> Iterator<? extends T> iterator(int first, int count);
> I will create and add a patch later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.