• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 package com.example.android.autofill.service.model;
17 
18 import android.arch.persistence.room.ColumnInfo;
19 import android.arch.persistence.room.Entity;
20 import android.arch.persistence.room.ForeignKey;
21 import android.arch.persistence.room.Ignore;
22 import android.support.annotation.NonNull;
23 
24 import javax.annotation.Nullable;
25 
26 @Entity(primaryKeys = {"datasetId", "fieldTypeName"}, foreignKeys = {
27         @ForeignKey(entity = AutofillDataset.class, parentColumns = "id",
28                 childColumns = "datasetId", onDelete = ForeignKey.CASCADE),
29         @ForeignKey(entity = FieldType.class, parentColumns = "typeName",
30                 childColumns = "fieldTypeName", onDelete = ForeignKey.CASCADE)
31 })
32 public class FilledAutofillField {
33 
34     @NonNull
35     @ColumnInfo(name = "datasetId")
36     private final String mDatasetId;
37 
38     @Nullable
39     @ColumnInfo(name = "textValue")
40     private final String mTextValue;
41 
42     @Nullable
43     @ColumnInfo(name = "dateValue")
44     private final Long mDateValue;
45 
46     @Nullable
47     @ColumnInfo(name = "toggleValue")
48     private final Boolean mToggleValue;
49 
50     @NonNull
51     @ColumnInfo(name = "fieldTypeName")
52     private final String mFieldTypeName;
53 
FilledAutofillField(@onNull String datasetId, @NonNull String fieldTypeName, @Nullable String textValue, @Nullable Long dateValue, @Nullable Boolean toggleValue)54     public FilledAutofillField(@NonNull String datasetId, @NonNull String fieldTypeName,
55                                @Nullable String textValue, @Nullable Long dateValue,
56                                @Nullable Boolean toggleValue) {
57         mDatasetId = datasetId;
58         mFieldTypeName = fieldTypeName;
59         mTextValue = textValue;
60         mDateValue = dateValue;
61         mToggleValue = toggleValue;
62     }
63 
64     @Ignore
FilledAutofillField(@onNull String datasetId, @NonNull String fieldTypeName, @Nullable String textValue, @Nullable Long dateValue)65     public FilledAutofillField(@NonNull String datasetId,
66             @NonNull String fieldTypeName, @Nullable String textValue, @Nullable Long dateValue) {
67         this(datasetId, fieldTypeName, textValue, dateValue, null);
68     }
69 
70     @Ignore
FilledAutofillField(@onNull String datasetId, @NonNull String fieldTypeName, @Nullable String textValue)71     public FilledAutofillField(@NonNull String datasetId, @NonNull String fieldTypeName,
72                                @Nullable String textValue) {
73         this(datasetId, fieldTypeName, textValue, null, null);
74     }
75 
76     @Ignore
FilledAutofillField(@onNull String datasetId, @NonNull String fieldTypeName, @Nullable Long dateValue)77     public FilledAutofillField(@NonNull String datasetId, @NonNull String fieldTypeName,
78                                @Nullable Long dateValue) {
79         this(datasetId, fieldTypeName, null, dateValue, null);
80     }
81 
82     @Ignore
FilledAutofillField(@onNull String datasetId, @NonNull String fieldTypeName, @Nullable Boolean toggleValue)83     public FilledAutofillField(@NonNull String datasetId, @NonNull String fieldTypeName,
84                                @Nullable Boolean toggleValue) {
85         this(datasetId, fieldTypeName, null, null, toggleValue);
86     }
87 
88     @Ignore
FilledAutofillField(@onNull String datasetId, @NonNull String fieldTypeName)89     public FilledAutofillField(@NonNull String datasetId, @NonNull String fieldTypeName) {
90         this(datasetId, fieldTypeName, null, null, null);
91     }
92 
93     @NonNull
getDatasetId()94     public String getDatasetId() {
95         return mDatasetId;
96     }
97 
98     @Nullable
getTextValue()99     public String getTextValue() {
100         return mTextValue;
101     }
102 
103     @Nullable
getDateValue()104     public Long getDateValue() {
105         return mDateValue;
106     }
107 
108     @Nullable
getToggleValue()109     public Boolean getToggleValue() {
110         return mToggleValue;
111     }
112 
113     @NonNull
getFieldTypeName()114     public String getFieldTypeName() {
115         return mFieldTypeName;
116     }
117 
isNull()118     public boolean isNull() {
119         return mTextValue == null && mDateValue == null && mToggleValue == null;
120     }
121 
122     @Override
equals(Object o)123     public boolean equals(Object o) {
124         if (this == o) return true;
125         if (o == null || getClass() != o.getClass()) return false;
126 
127         FilledAutofillField that = (FilledAutofillField) o;
128 
129         if (mTextValue != null ? !mTextValue.equals(that.mTextValue) : that.mTextValue != null)
130             return false;
131         if (mDateValue != null ? !mDateValue.equals(that.mDateValue) : that.mDateValue != null)
132             return false;
133         if (mToggleValue != null ? !mToggleValue.equals(that.mToggleValue) : that.mToggleValue != null)
134             return false;
135         return mFieldTypeName.equals(that.mFieldTypeName);
136     }
137 
138     @Override
hashCode()139     public int hashCode() {
140         int result = mTextValue != null ? mTextValue.hashCode() : 0;
141         result = 31 * result + (mDateValue != null ? mDateValue.hashCode() : 0);
142         result = 31 * result + (mToggleValue != null ? mToggleValue.hashCode() : 0);
143         result = 31 * result + mFieldTypeName.hashCode();
144         return result;
145     }
146 }
147