winterwell.jtwitter
Class TwitterList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<User>
          extended by winterwell.jtwitter.TwitterList
All Implemented Interfaces:
java.lang.Iterable<User>, java.util.Collection<User>, java.util.List<User>

public class TwitterList
extends java.util.AbstractList<User>

A Twitter list, which uses lazy-fetching of its members.

The methods of this object will call Twitter when they need to, and store the results. E.g. the first call to size() might require a call to Twitter, but subsequent calls will not.

WARNING: Twitter only returns list members in batches of 20. So reading a large list can be slow and use quite a few calls to Twitter.

To find out what lists you or another user has, see Twitter.getLists() and Twitter.getLists(String).
To find out what lists you or another user are *in*, see Twitter.getListsContainingMe() and Twitter.getListsContaining(String, boolean).

See Also:
Twitter

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
TwitterList(java.lang.String ownerScreenName, java.lang.String slug, Twitter jtwit)
          Deprecated. Due to the potential for confusion with TwitterList(String, Twitter, boolean, String) Use get(String, String, Twitter) instead.
TwitterList(java.lang.String listName, Twitter jtwit, boolean isPublic, java.lang.String description)
          CREATE a brand new Twitter list.
 
Method Summary
 boolean add(User user)
          Add a user to the list.
 boolean addAll(java.util.Collection<? extends User> newUsers)
           
 void delete()
          Delete this list!
 User get(int index)
           
static TwitterList get(java.lang.String ownerScreenName, java.lang.String slug, Twitter jtwit)
          A lazy-loading list viewer.
 java.lang.String getDescription()
           
 java.lang.String getName()
           
 User getOwner()
           
 java.util.List<Status> getStatuses()
          Returns a list of statuses from this list.
 int getSubscriberCount()
           
 java.util.List<User> getSubscribers()
           
 boolean isPrivate()
           
 boolean remove(java.lang.Object o)
          Remove a user from the list.
 void setDescription(java.lang.String description)
           
 void setPrivate(boolean isPrivate)
           
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray
 

Constructor Detail

TwitterList

@Deprecated
public TwitterList(java.lang.String ownerScreenName,
                              java.lang.String slug,
                              Twitter jtwit)
Deprecated. Due to the potential for confusion with TwitterList(String, Twitter, boolean, String) Use get(String, String, Twitter) instead.

A lazy-loading list viewer. This will fetch some details here, but the list of members will be loaded from Twitter on demand (to minimise the API calls). This is for access to an existing list - it does NOT create a new list on Twitter.

Parameters:
owner - .screenName The Twitter screen-name for the list's owner.
slug - The list's name. Technically the slug and the name needn't be the same, but they usually are.
jtwit - a JTwitter object (this must be able to authenticate).
Throws:
Twitter.Exception.E404 - if the list does not exist
See Also:
which creates new lists.

TwitterList

public TwitterList(java.lang.String listName,
                   Twitter jtwit,
                   boolean isPublic,
                   java.lang.String description)
CREATE a brand new Twitter list. Accounts are limited to 20 lists.

Parameters:
listName - The list's name.
jtwit - a JTwitter object (this must be able to authenticate).
description - A description for this list. Can be null.
See Also:
which views existing lists.
Method Detail

get

public static TwitterList get(java.lang.String ownerScreenName,
                              java.lang.String slug,
                              Twitter jtwit)
A lazy-loading list viewer. This will fetch details from Twitter when you call it's methods. This is for access to an existing list - it does NOT create a new list on Twitter.

Parameters:
ownerScreenName -
owner - .screenName The Twitter screen-name for the list's owner.
slug - The list's name. Technically the slug and the name needn't be the same, but they usually are.
jtwit - a JTwitter object (this must be able to authenticate).
Throws:
Twitter.Exception.E404 - if the list does not exist

add

public boolean add(User user)
Add a user to the list. List size is limited to 500 users.

Specified by:
add in interface java.util.Collection<User>
Specified by:
add in interface java.util.List<User>
Overrides:
add in class java.util.AbstractList<User>
Returns:
testing for membership could be slow, so this is usually true.

addAll

public boolean addAll(java.util.Collection<? extends User> newUsers)
Specified by:
addAll in interface java.util.Collection<User>
Specified by:
addAll in interface java.util.List<User>
Overrides:
addAll in class java.util.AbstractCollection<User>

delete

public void delete()
Delete this list!

Throws:
TwitterException - on failure

get

public User get(int index)
Specified by:
get in interface java.util.List<User>
Specified by:
get in class java.util.AbstractList<User>

getDescription

public java.lang.String getDescription()

getName

public java.lang.String getName()

getOwner

public User getOwner()

getStatuses

public java.util.List<Status> getStatuses()
                                   throws TwitterException
Returns a list of statuses from this list.

Returns:
List a list of Status objects for the list
Throws:
TwitterException

getSubscriberCount

public int getSubscriberCount()

getSubscribers

public java.util.List<User> getSubscribers()
Returns:
users who follow this list. Currently this is just the first 20 users. TODO cursor support for more than 20 users.

isPrivate

public boolean isPrivate()

remove

public boolean remove(java.lang.Object o)
Remove a user from the list.

Specified by:
remove in interface java.util.Collection<User>
Specified by:
remove in interface java.util.List<User>
Overrides:
remove in class java.util.AbstractCollection<User>
Returns:
testing for membership could be slow, so this is always true.

setDescription

public void setDescription(java.lang.String description)

setPrivate

public void setPrivate(boolean isPrivate)

size

public int size()
Specified by:
size in interface java.util.Collection<User>
Specified by:
size in interface java.util.List<User>
Specified by:
size in class java.util.AbstractCollection<User>

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection<User>