Account.java revision 603073430bbcb1bd29db7afb9b14e2732ad589fb
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
17package android.accounts;
18
19import android.os.Parcelable;
20import android.os.Parcel;
21
22/**
23 * Value type that represents an Account in the {@link AccountManager}. This object is
24 * {@link Parcelable} and also overrides {@link #equals} and {@link #hashCode}, making it
25 * suitable for use as the key of a {@link java.util.Map}
26 */
27public class Account implements Parcelable {
28    public final String mName;
29    public final String mType;
30
31    public boolean equals(Object o) {
32        if (o == this) return true;
33        if (!(o instanceof Account)) return false;
34        final Account other = (Account)o;
35        return mName.equals(other.mName) && mType.equals(other.mType);
36    }
37
38    public int hashCode() {
39        int result = 17;
40        result = 31 * result + mName.hashCode();
41        result = 31 * result + mType.hashCode();
42        return result;
43    }
44
45    public Account(String name, String type) {
46        mName = name;
47        mType = type;
48    }
49
50    public Account(Parcel in) {
51        mName = in.readString();
52        mType = in.readString();
53    }
54
55    public int describeContents() {
56        return 0;
57    }
58
59    public void writeToParcel(Parcel dest, int flags) {
60        dest.writeString(mName);
61        dest.writeString(mType);
62    }
63
64    public static final Creator<Account> CREATOR = new Creator<Account>() {
65        public Account createFromParcel(Parcel source) {
66            return new Account(source);
67        }
68
69        public Account[] newArray(int size) {
70            return new Account[size];
71        }
72    };
73
74    public String toString() {
75        return "Account {name=" + mName + ", type=" + mType + "}";
76    }
77}
78