1 /*
2  * Copyright (C) 2016 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 androidx.room.integration.testapp.database;
18 
19 import androidx.annotation.NonNull;
20 import androidx.recyclerview.widget.DiffUtil;
21 import androidx.room.Entity;
22 import androidx.room.PrimaryKey;
23 
24 /**
25  * Sample entity
26  */
27 @Entity
28 public class Customer {
29 
30     @PrimaryKey(autoGenerate = true)
31     private int mId;
32 
33     private String mName;
34 
35     private String mLastName;
36 
getId()37     public int getId() {
38         return mId;
39     }
40 
setId(int id)41     public void setId(int id) {
42         this.mId = id;
43     }
44 
getName()45     public String getName() {
46         return mName;
47     }
48 
setName(String name)49     public void setName(String name) {
50         this.mName = name;
51     }
52 
getLastName()53     public String getLastName() {
54         return mLastName;
55     }
56 
setLastName(String lastName)57     public void setLastName(String lastName) {
58         this.mLastName = lastName;
59     }
60 
61     @Override
equals(Object o)62     public boolean equals(Object o) {
63         if (this == o) {
64             return true;
65         }
66         if (o == null || getClass() != o.getClass()) {
67             return false;
68         }
69 
70         Customer customer = (Customer) o;
71 
72         if (mId != customer.mId) {
73             return false;
74         }
75         if (mName != null ? !mName.equals(customer.mName) : customer.mName != null) {
76             return false;
77         }
78         return mLastName != null ? mLastName.equals(customer.mLastName)
79                 : customer.mLastName == null;
80     }
81 
82     @Override
hashCode()83     public int hashCode() {
84         int result = mId;
85         result = 31 * result + (mName != null ? mName.hashCode() : 0);
86         result = 31 * result + (mLastName != null ? mLastName.hashCode() : 0);
87         return result;
88     }
89 
90     @Override
toString()91     public String toString() {
92         return "Customer{"
93                 + "mId=" + mId
94                 + ", mName='" + mName + '\''
95                 + ", mLastName='" + mLastName + '\''
96                 + '}';
97     }
98 
99     public static final DiffUtil.ItemCallback<Customer> DIFF_CALLBACK =
100             new DiffUtil.ItemCallback<Customer>() {
101         @Override
102         public boolean areContentsTheSame(@NonNull Customer oldItem, @NonNull Customer newItem) {
103             return oldItem.equals(newItem);
104         }
105 
106         @Override
107         public boolean areItemsTheSame(@NonNull Customer oldItem, @NonNull Customer newItem) {
108             return oldItem.getId() == newItem.getId();
109         }
110     };
111 }
112