| /* |
| * Copyright (C) 2016 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package android.arch.persistence.room.integration.testapp.database; |
| |
| import android.arch.persistence.room.Entity; |
| import android.arch.persistence.room.PrimaryKey; |
| import android.support.annotation.NonNull; |
| import android.support.v7.recyclerview.extensions.DiffCallback; |
| |
| /** |
| * Sample entity |
| */ |
| @Entity |
| public class Customer { |
| |
| @PrimaryKey(autoGenerate = true) |
| private int mId; |
| |
| private String mName; |
| |
| private String mLastName; |
| |
| public int getId() { |
| return mId; |
| } |
| |
| public void setId(int id) { |
| this.mId = id; |
| } |
| |
| public String getName() { |
| return mName; |
| } |
| |
| public void setName(String name) { |
| this.mName = name; |
| } |
| |
| public String getLastName() { |
| return mLastName; |
| } |
| |
| public void setLastName(String lastName) { |
| this.mLastName = lastName; |
| } |
| |
| @Override |
| public boolean equals(Object o) { |
| if (this == o) { |
| return true; |
| } |
| if (o == null || getClass() != o.getClass()) { |
| return false; |
| } |
| |
| Customer customer = (Customer) o; |
| |
| if (mId != customer.mId) { |
| return false; |
| } |
| if (mName != null ? !mName.equals(customer.mName) : customer.mName != null) { |
| return false; |
| } |
| return mLastName != null ? mLastName.equals(customer.mLastName) |
| : customer.mLastName == null; |
| } |
| |
| @Override |
| public int hashCode() { |
| int result = mId; |
| result = 31 * result + (mName != null ? mName.hashCode() : 0); |
| result = 31 * result + (mLastName != null ? mLastName.hashCode() : 0); |
| return result; |
| } |
| |
| @Override |
| public String toString() { |
| return "Customer{" |
| + "mId=" + mId |
| + ", mName='" + mName + '\'' |
| + ", mLastName='" + mLastName + '\'' |
| + '}'; |
| } |
| |
| public static final DiffCallback<Customer> DIFF_CALLBACK = new DiffCallback<Customer>() { |
| @Override |
| public boolean areContentsTheSame(@NonNull Customer oldItem, @NonNull Customer newItem) { |
| return oldItem.equals(newItem); |
| } |
| |
| @Override |
| public boolean areItemsTheSame(@NonNull Customer oldItem, @NonNull Customer newItem) { |
| return oldItem.getId() == newItem.getId(); |
| } |
| }; |
| } |