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.vo;
18 
19 import androidx.room.ColumnInfo;
20 import androidx.room.Entity;
21 import androidx.room.PrimaryKey;
22 import androidx.room.TypeConverters;
23 import androidx.room.integration.testapp.TestDatabase;
24 
25 import java.util.Date;
26 import java.util.HashSet;
27 import java.util.Set;
28 
29 @Entity
30 @TypeConverters({TestDatabase.Converters.class})
31 public class User {
32 
33     @PrimaryKey
34     private int mId;
35 
36     private String mName;
37 
38     private String mLastName;
39 
40     private int mAge;
41 
42     private boolean mAdmin;
43 
44     private float mWeight;
45 
46     private Date mBirthday;
47 
48     @ColumnInfo(name = "custommm", collate = ColumnInfo.NOCASE)
49     private String mCustomField;
50 
51     // bit flags
52     private Set<Day> mWorkDays = new HashSet<>();
53 
getId()54     public int getId() {
55         return mId;
56     }
57 
setId(int id)58     public void setId(int id) {
59         this.mId = id;
60     }
61 
getName()62     public String getName() {
63         return mName;
64     }
65 
setName(String name)66     public void setName(String name) {
67         this.mName = name;
68     }
69 
getLastName()70     public String getLastName() {
71         return mLastName;
72     }
73 
setLastName(String lastName)74     public void setLastName(String lastName) {
75         this.mLastName = lastName;
76     }
77 
getAge()78     public int getAge() {
79         return mAge;
80     }
81 
setAge(int age)82     public void setAge(int age) {
83         this.mAge = age;
84     }
85 
isAdmin()86     public boolean isAdmin() {
87         return mAdmin;
88     }
89 
setAdmin(boolean admin)90     public void setAdmin(boolean admin) {
91         mAdmin = admin;
92     }
93 
getWeight()94     public float getWeight() {
95         return mWeight;
96     }
97 
setWeight(float weight)98     public void setWeight(float weight) {
99         mWeight = weight;
100     }
101 
getBirthday()102     public Date getBirthday() {
103         return mBirthday;
104     }
105 
setBirthday(Date birthday)106     public void setBirthday(Date birthday) {
107         mBirthday = birthday;
108     }
109 
getCustomField()110     public String getCustomField() {
111         return mCustomField;
112     }
113 
setCustomField(String customField)114     public void setCustomField(String customField) {
115         mCustomField = customField;
116     }
117 
getWorkDays()118     public Set<Day> getWorkDays() {
119         return mWorkDays;
120     }
121 
setWorkDays( Set<Day> workDays)122     public void setWorkDays(
123             Set<Day> workDays) {
124         mWorkDays = workDays;
125     }
126 
127     @Override
equals(Object o)128     public boolean equals(Object o) {
129         if (this == o) return true;
130         if (o == null || getClass() != o.getClass()) return false;
131 
132         User user = (User) o;
133 
134         if (mId != user.mId) return false;
135         if (mAge != user.mAge) return false;
136         if (mAdmin != user.mAdmin) return false;
137         if (Float.compare(user.mWeight, mWeight) != 0) return false;
138         if (mName != null ? !mName.equals(user.mName) : user.mName != null) return false;
139         if (mLastName != null ? !mLastName.equals(user.mLastName) : user.mLastName != null) {
140             return false;
141         }
142         if (mBirthday != null ? !mBirthday.equals(user.mBirthday) : user.mBirthday != null) {
143             return false;
144         }
145         if (mCustomField != null ? !mCustomField.equals(user.mCustomField)
146                 : user.mCustomField != null) {
147             return false;
148         }
149         return mWorkDays != null ? mWorkDays.equals(user.mWorkDays) : user.mWorkDays == null;
150     }
151 
152     @Override
hashCode()153     public int hashCode() {
154         int result = mId;
155         result = 31 * result + (mName != null ? mName.hashCode() : 0);
156         result = 31 * result + (mLastName != null ? mLastName.hashCode() : 0);
157         result = 31 * result + mAge;
158         result = 31 * result + (mAdmin ? 1 : 0);
159         result = 31 * result + (mWeight != +0.0f ? Float.floatToIntBits(mWeight) : 0);
160         result = 31 * result + (mBirthday != null ? mBirthday.hashCode() : 0);
161         result = 31 * result + (mCustomField != null ? mCustomField.hashCode() : 0);
162         result = 31 * result + (mWorkDays != null ? mWorkDays.hashCode() : 0);
163         return result;
164     }
165 
166     @Override
toString()167     public String toString() {
168         return "User{"
169                 + "mId=" + mId
170                 + ", mName='" + mName + '\''
171                 + ", mLastName='" + mLastName + '\''
172                 + ", mAge=" + mAge
173                 + ", mAdmin=" + mAdmin
174                 + ", mWeight=" + mWeight
175                 + ", mBirthday=" + mBirthday
176                 + ", mCustomField='" + mCustomField + '\''
177                 + ", mWorkDays=" + mWorkDays
178                 + '}';
179     }
180 }
181