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