1 /*
2  * Copyright (C) 2015, 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.aidl.tests;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 
22 public class SimpleParcelable implements Parcelable {
23     private String mName;
24     private int mNumber;
25 
SimpleParcelable()26     SimpleParcelable() {}
SimpleParcelable(String name, int number)27     SimpleParcelable(String name, int number) {
28         mName = name;
29         mNumber = number;
30     }
31 
describeContents()32     public int describeContents() { return 0; }
33 
writeToParcel(Parcel dest, int flags)34     public void writeToParcel(Parcel dest, int flags) {
35         dest.writeString(mName);
36         dest.writeInt(mNumber);
37     }
38 
readFromParcel(Parcel source)39     public void readFromParcel(Parcel source) {
40         mName = source.readString();
41         mNumber = source.readInt();
42     }
43 
equals(Object o)44     public boolean equals(Object o) {
45         if (o == null) {
46             return false;
47         }
48         if (!(o instanceof SimpleParcelable)) {
49             return false;
50         }
51         SimpleParcelable p = (SimpleParcelable)o;
52         if ((mName == null && p.mName != null) ||
53             (mName != null && !mName.equals(p.mName))) {
54             return false;
55         }
56         return mNumber == p.mNumber;
57     }
58 
toString()59     public String toString() {
60         return "SimpleParcelable(" + mName + ", " + mNumber + ")";
61     }
62 
63     public static final Parcelable.Creator<SimpleParcelable> CREATOR =
64             new Parcelable.Creator<SimpleParcelable>() {
65         public SimpleParcelable createFromParcel(Parcel source) {
66             String name = source.readString();
67             int number = source.readInt();
68             return new SimpleParcelable(name, number);
69         }
70 
71         public SimpleParcelable[] newArray(int size) {
72             return new SimpleParcelable[size];
73         }
74     };
75 }
76