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
17package android.arch.persistence.room.integration.testapp.database;
18
19import android.arch.persistence.room.Entity;
20import android.arch.persistence.room.PrimaryKey;
21import android.support.annotation.NonNull;
22import android.support.v7.recyclerview.extensions.DiffCallback;
23
24/**
25 * Sample entity
26 */
27@Entity
28public class Customer {
29
30    @PrimaryKey(autoGenerate = true)
31    private int mId;
32
33    private String mName;
34
35    private String mLastName;
36
37    public int getId() {
38        return mId;
39    }
40
41    public void setId(int id) {
42        this.mId = id;
43    }
44
45    public String getName() {
46        return mName;
47    }
48
49    public void setName(String name) {
50        this.mName = name;
51    }
52
53    public String getLastName() {
54        return mLastName;
55    }
56
57    public void setLastName(String lastName) {
58        this.mLastName = lastName;
59    }
60
61    @Override
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
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
91    public String toString() {
92        return "Customer{"
93                + "mId=" + mId
94                + ", mName='" + mName + '\''
95                + ", mLastName='" + mLastName + '\''
96                + '}';
97    }
98
99    public static final DiffCallback<Customer> DIFF_CALLBACK = new DiffCallback<Customer>() {
100        @Override
101        public boolean areContentsTheSame(@NonNull Customer oldItem, @NonNull Customer newItem) {
102            return oldItem.equals(newItem);
103        }
104
105        @Override
106        public boolean areItemsTheSame(@NonNull Customer oldItem, @NonNull Customer newItem) {
107            return oldItem.getId() == newItem.getId();
108        }
109    };
110}
111