/*--------------------------------------------------------------------------+ | 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.Comparator; /** * Data about a Facebook friend. This is a simple data container object. Adjust * it to suit your application, adding or removing fields as needed. */ public class FacebookFriend implements Cloneable, Serializable, Comparable { /** The friend's full name. */ public String name; /** The friend's first name. */ public String firstName; /** The friend's Facebook user ID. */ public String uid; /** * The default sort order is by full name. If you want to sort by a * different criterion, use one of the provided comparators. */ public int compareTo(FacebookFriend o) { return ALPHABETICAL_NAME.compare(this, o); } @Override public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { // Should never happen since we implement Cloneable return null; } } /** * Utility method for comparing two strings with null handling. */ private static int compareStrings(String val1, String val2, boolean caseSensitive) { if (val1 == null && val2 == null) return 0; if (val1 == null) return -1; if (val2 == null) return 1; if (caseSensitive) return val1.compareTo(val2); else return val1.compareToIgnoreCase(val2); } /** * Comparator for sorting by full name. */ public static Comparator ALPHABETICAL_NAME = new Comparator() { public int compare(FacebookFriend f1, FacebookFriend f2) { if (f1 == null && f2 == null) return 0; if (f1 == null) return -1; if (f2 == null) return 1; return compareStrings(f1.name, f2.name, false); } }; /** * Comparator for sorting by Facebook user ID. */ public static Comparator ALPHABETICAL_UID = new Comparator() { public int compare(FacebookFriend f1, FacebookFriend f2) { if (f1 == null && f2 == null) return 0; if (f1 == null) return -1; if (f2 == null) return 1; return compareStrings(f1.uid, f2.uid, true); } }; }