1996775af841578ead235540eb383f114b4e0eb00Christopher Wiley/*
2996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * Copyright (C) 2015, The Android Open Source Project
3996775af841578ead235540eb383f114b4e0eb00Christopher Wiley *
4996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * Licensed under the Apache License, Version 2.0 (the "License");
5996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * you may not use this file except in compliance with the License.
6996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * You may obtain a copy of the License at
7996775af841578ead235540eb383f114b4e0eb00Christopher Wiley *
8996775af841578ead235540eb383f114b4e0eb00Christopher Wiley *     http://www.apache.org/licenses/LICENSE-2.0
9996775af841578ead235540eb383f114b4e0eb00Christopher Wiley *
10996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * Unless required by applicable law or agreed to in writing, software
11996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * distributed under the License is distributed on an "AS IS" BASIS,
12996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * See the License for the specific language governing permissions and
14996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * limitations under the License.
15996775af841578ead235540eb383f114b4e0eb00Christopher Wiley */
16996775af841578ead235540eb383f114b4e0eb00Christopher Wiley
17996775af841578ead235540eb383f114b4e0eb00Christopher Wileypackage android.aidl.tests;
18996775af841578ead235540eb383f114b4e0eb00Christopher Wiley
19996775af841578ead235540eb383f114b4e0eb00Christopher Wileyimport android.os.Parcel;
20996775af841578ead235540eb383f114b4e0eb00Christopher Wileyimport android.os.Parcelable;
21996775af841578ead235540eb383f114b4e0eb00Christopher Wiley
22996775af841578ead235540eb383f114b4e0eb00Christopher Wileypublic class SimpleParcelable implements Parcelable {
23996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    private String mName;
24996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    private int mNumber;
25996775af841578ead235540eb383f114b4e0eb00Christopher Wiley
26996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    SimpleParcelable() {}
27996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    SimpleParcelable(String name, int number) {
28996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        mName = name;
29996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        mNumber = number;
30996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    }
31996775af841578ead235540eb383f114b4e0eb00Christopher Wiley
32996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    public int describeContents() { return 0; }
33996775af841578ead235540eb383f114b4e0eb00Christopher Wiley
34996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    public void writeToParcel(Parcel dest, int flags) {
35996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        dest.writeString(mName);
36996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        dest.writeInt(mNumber);
37996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    }
38996775af841578ead235540eb383f114b4e0eb00Christopher Wiley
39996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    public void readFromParcel(Parcel source) {
40996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        mName = source.readString();
41996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        mNumber = source.readInt();
42996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    }
43996775af841578ead235540eb383f114b4e0eb00Christopher Wiley
44996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    public boolean equals(Object o) {
45996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        if (o == null) {
46996775af841578ead235540eb383f114b4e0eb00Christopher Wiley            return false;
47996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        }
48996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        if (!(o instanceof SimpleParcelable)) {
49996775af841578ead235540eb383f114b4e0eb00Christopher Wiley            return false;
50996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        }
51996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        SimpleParcelable p = (SimpleParcelable)o;
52996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        if ((mName == null && p.mName != null) ||
53996775af841578ead235540eb383f114b4e0eb00Christopher Wiley            (mName != null && !mName.equals(p.mName))) {
54996775af841578ead235540eb383f114b4e0eb00Christopher Wiley            return false;
55996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        }
56996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        return mNumber == p.mNumber;
57996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    }
58996775af841578ead235540eb383f114b4e0eb00Christopher Wiley
59996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    public String toString() {
60996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        return "SimpleParcelable(" + mName + ", " + mNumber + ")";
61996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    }
62996775af841578ead235540eb383f114b4e0eb00Christopher Wiley
63996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    public static final Parcelable.Creator<SimpleParcelable> CREATOR =
64996775af841578ead235540eb383f114b4e0eb00Christopher Wiley            new Parcelable.Creator<SimpleParcelable>() {
65996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        public SimpleParcelable createFromParcel(Parcel source) {
66996775af841578ead235540eb383f114b4e0eb00Christopher Wiley            String name = source.readString();
67996775af841578ead235540eb383f114b4e0eb00Christopher Wiley            int number = source.readInt();
68996775af841578ead235540eb383f114b4e0eb00Christopher Wiley            return new SimpleParcelable(name, number);
69996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        }
70996775af841578ead235540eb383f114b4e0eb00Christopher Wiley
71996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        public SimpleParcelable[] newArray(int size) {
72996775af841578ead235540eb383f114b4e0eb00Christopher Wiley            return new SimpleParcelable[size];
73996775af841578ead235540eb383f114b4e0eb00Christopher Wiley        }
74996775af841578ead235540eb383f114b4e0eb00Christopher Wiley    };
75996775af841578ead235540eb383f114b4e0eb00Christopher Wiley}
76