Customer.java revision 9fd8e6171bbdc37f5516fe15b2d96f4ae926ef1a
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.arch.persistence.room.TypeConverters; 22import android.arch.util.paging.DiffCallback; 23import android.support.annotation.NonNull; 24 25/** 26 * Sample entity 27 */ 28@Entity 29public class Customer { 30 31 @PrimaryKey 32 private int mId; 33 34 private String mName; 35 36 private String mLastName; 37 38 public int getId() { 39 return mId; 40 } 41 42 public void setId(int id) { 43 this.mId = id; 44 } 45 46 public String getName() { 47 return mName; 48 } 49 50 public void setName(String name) { 51 this.mName = name; 52 } 53 54 public String getLastName() { 55 return mLastName; 56 } 57 58 public void setLastName(String lastName) { 59 this.mLastName = lastName; 60 } 61 62 @Override 63 public boolean equals(Object o) { 64 if (this == o) { 65 return true; 66 } 67 if (o == null || getClass() != o.getClass()) { 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 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 92 public String toString() { 93 return "Customer{" 94 + "mId=" + mId 95 + ", mName='" + mName + '\'' 96 + ", mLastName='" + mLastName + '\'' 97 + '}'; 98 } 99 100 public static final DiffCallback<Customer> DIFF_CALLBACK = new DiffCallback<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