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
17package androidx.room.migration.bundle;
18
19import androidx.annotation.RestrictTo;
20
21import com.google.gson.annotations.SerializedName;
22
23/**
24 * Data class that holds the schema information for an
25 * {@link androidx.room.Entity Entity} field.
26 *
27 * @hide
28 */
29@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
30public class FieldBundle implements SchemaEquality<FieldBundle> {
31    @SerializedName("fieldPath")
32    private String mFieldPath;
33    @SerializedName("columnName")
34    private String mColumnName;
35    @SerializedName("affinity")
36    private String mAffinity;
37    @SerializedName("notNull")
38    private boolean mNonNull;
39
40    public FieldBundle(String fieldPath, String columnName, String affinity, boolean nonNull) {
41        mFieldPath = fieldPath;
42        mColumnName = columnName;
43        mAffinity = affinity;
44        mNonNull = nonNull;
45    }
46
47    public String getFieldPath() {
48        return mFieldPath;
49    }
50
51    public String getColumnName() {
52        return mColumnName;
53    }
54
55    public String getAffinity() {
56        return mAffinity;
57    }
58
59    public boolean isNonNull() {
60        return mNonNull;
61    }
62
63    @Override
64    public boolean isSchemaEqual(FieldBundle other) {
65        if (mNonNull != other.mNonNull) return false;
66        if (mColumnName != null ? !mColumnName.equals(other.mColumnName)
67                : other.mColumnName != null) {
68            return false;
69        }
70        return mAffinity != null ? mAffinity.equals(other.mAffinity) : other.mAffinity == null;
71    }
72}
73