/*--------------------------------------------------------------------------+ | Copyright (c) 2006 Facebook, Inc. | | All rights reserved. | | | | Redistribution and use in source and binary forms, with or without | | modification, are permitted provided that the following conditions | | are met: | | | | 1. Redistributions of source code must retain the above copyright | | notice, this list of conditions and the following disclaimer. | | 2. Redistributions in binary form must reproduce the above copyright | | notice, this list of conditions and the following disclaimer in the | | documentation and/or other materials provided with the distribution. | | | | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +---------------------------------------------------------------------------+ | For help with this library, contact api-help@facebook.com | +--------------------------------------------------------------------------*/ package com.moochspot.util; import java.io.Serializable; import java.util.*; /** * A list of Facebook friends. This allows quick lookups by ID and searching * of names. */ public class FacebookFriends implements Cloneable, Serializable { private Map _uidToNameMap = new HashMap(); private SortedSet _friendSet = new TreeSet(); private Set _uidSet = new HashSet(); /** * Adds a friend. */ public void add(FacebookFriend friend) { _uidToNameMap.put(friend.uid, friend); _friendSet.add(friend); _uidSet.add(friend.uid); } /** * Returns a friend with a given user ID. */ public FacebookFriend getByUserId(String uid) { return _uidToNameMap.get(uid); } /** * Returns a sorted set of friends. */ public SortedSet getAll() { return _friendSet; } /** * Returns a list of all the user IDs. */ public Collection getAllUserIds() { return _uidSet; } /** * Clones the friends list. */ public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { // We implement Cloneable, so this should never happen. return null; } } }