You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Geoffrey De Smet (JIRA)" <ji...@apache.org> on 2008/02/19 16:52:43 UTC

[jira] Created: (COLLECTIONS-286) New util method: CollectionUtils.getSingleton(List singletonList) which returns the single object in the list or throws an exception

New util method: CollectionUtils.getSingleton(List<T> singletonList) which returns the single object in the list or throws an exception
---------------------------------------------------------------------------------------------------------------------------------------

                 Key: COLLECTIONS-286
                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-286
             Project: Commons Collections
          Issue Type: New Feature
            Reporter: Geoffrey De Smet
             Fix For: 3.3



    public <T> T getSingleton(List<T> singletonList)
    {
        if (singletonList.size() != 1)
        {
            throw new IllegalArgumentException("The singletonList size ("
                    + singletonList.size() + ") should be 1.");
        }
        return singletonList.get(0);
    }

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


[jira] Commented: (COLLECTIONS-286) New util method: CollectionUtils.getSingleton(List singletonList) which returns the single object in the list or throws an exception

Posted by "François LEIBER (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COLLECTIONS-286?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12752054#action_12752054 ] 

François LEIBER commented on COLLECTIONS-286:
---------------------------------------------

This would be incredibly useful if indeed it takes a Collection instead of a List, otherwise I don't see the point.
Voting for it, if the title is changed.

> New util method: CollectionUtils.getSingleton(List<T> singletonList) which returns the single object in the list or throws an exception
> ---------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-286
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-286
>             Project: Commons Collections
>          Issue Type: New Feature
>            Reporter: Geoffrey De Smet
>             Fix For: Generics
>
>         Attachments: extract.svn.diff
>
>
>     public <T> T getSingleton(List<T> singletonList)
>     {
>         if (singletonList.size() != 1)
>         {
>             throw new IllegalArgumentException("The singletonList size ("
>                     + singletonList.size() + ") should be 1.");
>         }
>         return singletonList.get(0);
>     }

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


[jira] Commented: (COLLECTIONS-286) New util method: CollectionUtils.getSingleton(List singletonList) which returns the single object in the list or throws an exception

Posted by "Geoffrey De Smet (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COLLECTIONS-286?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12570279#action_12570279 ] 

Geoffrey De Smet commented on COLLECTIONS-286:
----------------------------------------------

that method should be static

> New util method: CollectionUtils.getSingleton(List<T> singletonList) which returns the single object in the list or throws an exception
> ---------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-286
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-286
>             Project: Commons Collections
>          Issue Type: New Feature
>            Reporter: Geoffrey De Smet
>             Fix For: 3.3
>
>
>     public <T> T getSingleton(List<T> singletonList)
>     {
>         if (singletonList.size() != 1)
>         {
>             throw new IllegalArgumentException("The singletonList size ("
>                     + singletonList.size() + ") should be 1.");
>         }
>         return singletonList.get(0);
>     }

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


[jira] Updated: (COLLECTIONS-286) New util method: CollectionUtils.getSingleton(List singletonList) which returns the single object in the list or throws an exception

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

John Curtis updated COLLECTIONS-286:
------------------------------------

    Attachment: extract.svn.diff

This method should take any collection type, and perhaps be called something more descriptive so that its usage is obvious. For example:

public static <T> T extractSoleObject(Collection<T> collection)

I have attached a patch which implements this signature and some simple test cases. I am new to this and unsure of how to go about getting this included in the trunk. Is posting the patch here sufficient to have someone with commit access review and decide whether to include?

> New util method: CollectionUtils.getSingleton(List<T> singletonList) which returns the single object in the list or throws an exception
> ---------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-286
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-286
>             Project: Commons Collections
>          Issue Type: New Feature
>            Reporter: Geoffrey De Smet
>             Fix For: Generics
>
>         Attachments: extract.svn.diff
>
>
>     public <T> T getSingleton(List<T> singletonList)
>     {
>         if (singletonList.size() != 1)
>         {
>             throw new IllegalArgumentException("The singletonList size ("
>                     + singletonList.size() + ") should be 1.");
>         }
>         return singletonList.get(0);
>     }

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


[jira] Commented: (COLLECTIONS-286) New util method: CollectionUtils.getSingleton(List singletonList) which returns the single object in the list or throws an exception

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COLLECTIONS-286?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12754245#action_12754245 ] 

Matt Benson commented on COLLECTIONS-286:
-----------------------------------------

My preference is for a compromise:  extractSingleton.  This seems to me the best complement to Collections.singleton().

> New util method: CollectionUtils.getSingleton(List<T> singletonList) which returns the single object in the list or throws an exception
> ---------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-286
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-286
>             Project: Commons Collections
>          Issue Type: New Feature
>            Reporter: Geoffrey De Smet
>             Fix For: Generics
>
>         Attachments: extract.svn.diff
>
>
>     public <T> T getSingleton(List<T> singletonList)
>     {
>         if (singletonList.size() != 1)
>         {
>             throw new IllegalArgumentException("The singletonList size ("
>                     + singletonList.size() + ") should be 1.");
>         }
>         return singletonList.get(0);
>     }

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


[jira] Resolved: (COLLECTIONS-286) New util method: CollectionUtils.getSingleton(List singletonList) which returns the single object in the list or throws an exception

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

Matt Benson resolved COLLECTIONS-286.
-------------------------------------

    Resolution: Fixed

Committed revision 813951.

> New util method: CollectionUtils.getSingleton(List<T> singletonList) which returns the single object in the list or throws an exception
> ---------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-286
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-286
>             Project: Commons Collections
>          Issue Type: New Feature
>            Reporter: Geoffrey De Smet
>             Fix For: Generics
>
>         Attachments: extract.svn.diff
>
>
>     public <T> T getSingleton(List<T> singletonList)
>     {
>         if (singletonList.size() != 1)
>         {
>             throw new IllegalArgumentException("The singletonList size ("
>                     + singletonList.size() + ") should be 1.");
>         }
>         return singletonList.get(0);
>     }

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


[jira] Updated: (COLLECTIONS-286) New util method: CollectionUtils.getSingleton(List singletonList) which returns the single object in the list or throws an exception

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

Henri Yandell updated COLLECTIONS-286:
--------------------------------------

      Description: 
    public <T> T getSingleton(List<T> singletonList)
    {
        if (singletonList.size() != 1)
        {
            throw new IllegalArgumentException("The singletonList size ("
                    + singletonList.size() + ") should be 1.");
        }
        return singletonList.get(0);
    }

  was:

    public <T> T getSingleton(List<T> singletonList)
    {
        if (singletonList.size() != 1)
        {
            throw new IllegalArgumentException("The singletonList size ("
                    + singletonList.size() + ") should be 1.");
        }
        return singletonList.get(0);
    }

    Fix Version/s:     (was: 3.3)
                   Generics

> New util method: CollectionUtils.getSingleton(List<T> singletonList) which returns the single object in the list or throws an exception
> ---------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-286
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-286
>             Project: Commons Collections
>          Issue Type: New Feature
>            Reporter: Geoffrey De Smet
>             Fix For: Generics
>
>
>     public <T> T getSingleton(List<T> singletonList)
>     {
>         if (singletonList.size() != 1)
>         {
>             throw new IllegalArgumentException("The singletonList size ("
>                     + singletonList.size() + ") should be 1.");
>         }
>         return singletonList.get(0);
>     }

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