1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.accounts; 18 19 import android.os.Parcelable; 20 import android.os.Parcel; 21 import android.text.TextUtils; 22 23 /** 24 * Value type that represents an Account in the {@link AccountManager}. This object is 25 * {@link Parcelable} and also overrides {@link #equals} and {@link #hashCode}, making it 26 * suitable for use as the key of a {@link java.util.Map} 27 */ 28 public class Account implements Parcelable { 29 public final String name; 30 public final String type; 31 32 public boolean equals(Object o) { 33 if (o == this) return true; 34 if (!(o instanceof Account)) return false; 35 final Account other = (Account)o; 36 return name.equals(other.name) && type.equals(other.type); 37 } 38 39 public int hashCode() { 40 int result = 17; 41 result = 31 * result + name.hashCode(); 42 result = 31 * result + type.hashCode(); 43 return result; 44 } 45 46 public Account(String name, String type) { 47 if (TextUtils.isEmpty(name)) { 48 throw new IllegalArgumentException("the name must not be empty: " + name); 49 } 50 if (TextUtils.isEmpty(type)) { 51 throw new IllegalArgumentException("the type must not be empty: " + type); 52 } 53 this.name = name; 54 this.type = type; 55 } 56 57 public Account(Parcel in) { 58 this.name = in.readString(); 59 this.type = in.readString(); 60 } 61 62 public int describeContents() { 63 return 0; 64 } 65 66 public void writeToParcel(Parcel dest, int flags) { 67 dest.writeString(name); 68 dest.writeString(type); 69 } 70 71 public static final Creator<Account> CREATOR = new Creator<Account>() { 72 public Account createFromParcel(Parcel source) { 73 return new Account(source); 74 } 75 76 public Account[] newArray(int size) { 77 return new Account[size]; 78 } 79 }; 80 81 public String toString() { 82 return "Account {name=" + name + ", type=" + type + "}"; 83 } 84 } 85