/* * Copyright (c) 2008-2016 MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.mongodb.morphia.entities; import org.bson.types.ObjectId; import org.mongodb.morphia.annotations.Entity; import org.mongodb.morphia.annotations.Id; import org.mongodb.morphia.annotations.Validation; import java.util.Date; @Entity("validation") @Validation("{ number : { $gt : 10 } }") public class DocumentValidation { @Id private ObjectId id; private String string; private int number; private Date date; public DocumentValidation() { } public DocumentValidation(final String string, final int number, final Date date) { this.string = string; this.number = number; this.date = date; } public ObjectId getId() { return id; } public void setId(final ObjectId id) { this.id = id; } public String getString() { return string; } public void setString(final String string) { this.string = string; } public int getNumber() { return number; } public void setNumber(final int number) { this.number = number; } public Date getDate() { return date; } public void setDate(final Date date) { this.date = date; } @Override public boolean equals(final Object o) { if (this == o) { return true; } if (!(o instanceof DocumentValidation)) { return false; } final DocumentValidation that = (DocumentValidation) o; if (number != that.number) { return false; } if (id != null ? !id.equals(that.id) : that.id != null) { return false; } if (string != null ? !string.equals(that.string) : that.string != null) { return false; } return date != null ? date.equals(that.date) : that.date == null; } @Override public int hashCode() { int result = id != null ? id.hashCode() : 0; result = 31 * result + (string != null ? string.hashCode() : 0); result = 31 * result + number; result = 31 * result + (date != null ? date.hashCode() : 0); return result; } }