|
| 1 | +/* |
| 2 | + * Copyright 2017 MongoDB, Inc. |
| 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 org.bson.codecs.pojo.entities.conventions; |
| 18 | + |
| 19 | +import org.bson.codecs.pojo.annotations.BsonCreator; |
| 20 | +import org.bson.codecs.pojo.annotations.BsonProperty; |
| 21 | + |
| 22 | +import java.util.List; |
| 23 | + |
| 24 | +public final class CreatorConstructorLegacyBsonPropertyModel { |
| 25 | + private final List<Integer> integersField; |
| 26 | + private String stringField; |
| 27 | + @BsonProperty("longField") |
| 28 | + private long myLongField; |
| 29 | + |
| 30 | + // Here we use the @BsonProperty using the actual field name, that has been set to read and write to "longField" |
| 31 | + @BsonCreator |
| 32 | + public CreatorConstructorLegacyBsonPropertyModel(@BsonProperty("integersField") final List<Integer> integerField, |
| 33 | + @BsonProperty("myLongField") final long longField) { |
| 34 | + this.integersField = integerField; |
| 35 | + this.myLongField = longField; |
| 36 | + } |
| 37 | + |
| 38 | + public CreatorConstructorLegacyBsonPropertyModel(final List<Integer> integersField, final String stringField, final long longField) { |
| 39 | + this.integersField = integersField; |
| 40 | + this.stringField = stringField; |
| 41 | + this.myLongField = longField; |
| 42 | + } |
| 43 | + |
| 44 | + public List<Integer> getIntegersField() { |
| 45 | + return integersField; |
| 46 | + } |
| 47 | + |
| 48 | + public String getStringField() { |
| 49 | + return stringField; |
| 50 | + } |
| 51 | + |
| 52 | + public void setStringField(final String stringField) { |
| 53 | + this.stringField = stringField; |
| 54 | + } |
| 55 | + |
| 56 | + public long getMyLongField() { |
| 57 | + return myLongField; |
| 58 | + } |
| 59 | + |
| 60 | + public void setMyLongField(final long myLongField) { |
| 61 | + this.myLongField = myLongField; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public boolean equals(final Object o) { |
| 66 | + if (this == o) { |
| 67 | + return true; |
| 68 | + } |
| 69 | + if (o == null || getClass() != o.getClass()) { |
| 70 | + return false; |
| 71 | + } |
| 72 | + |
| 73 | + CreatorConstructorLegacyBsonPropertyModel that = (CreatorConstructorLegacyBsonPropertyModel) o; |
| 74 | + |
| 75 | + if (getMyLongField() != that.getMyLongField()) { |
| 76 | + return false; |
| 77 | + } |
| 78 | + if (getIntegersField() != null ? !getIntegersField().equals(that.getIntegersField()) : that.getIntegersField() != null) { |
| 79 | + return false; |
| 80 | + } |
| 81 | + if (getStringField() != null ? !getStringField().equals(that.getStringField()) : that.getStringField() != null) { |
| 82 | + return false; |
| 83 | + } |
| 84 | + |
| 85 | + return true; |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public int hashCode() { |
| 90 | + int result = getIntegersField() != null ? getIntegersField().hashCode() : 0; |
| 91 | + result = 31 * result + (getStringField() != null ? getStringField().hashCode() : 0); |
| 92 | + result = 31 * result + (int) (getMyLongField() ^ (getMyLongField() >>> 32)); |
| 93 | + return result; |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public String toString() { |
| 98 | + return "CreatorConstructorModel{" |
| 99 | + + "integersField=" + integersField |
| 100 | + + ", stringField='" + stringField + "'" |
| 101 | + + ", myLongField=" + myLongField |
| 102 | + + "}"; |
| 103 | + } |
| 104 | +} |
0 commit comments