Java tutorial
/* * Copyright 2012 the original author or authors. * * 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.intan.hotelMaestro.springdata.model; import java.math.BigDecimal; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.springframework.data.annotation.PersistenceConstructor; import org.springframework.data.mongodb.core.mapping.DBRef; import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.util.Assert; /** * @author Oliver Gierke */ @Document public class RoomType extends AbstractDocument { /*@DBRef private Customer customer; */ private String name, description; private BigDecimal price; private Map<String, String> attributes = new HashMap<String, String>(); /** * Creates a new {@link RoomType} for the given {@link Customer}. * * @param customer must not be {@literal null}. * @param shippingAddress must not be {@literal null}. */ public RoomType() { } public RoomType(String name, BigDecimal price) { this(name, price, null); } @PersistenceConstructor public RoomType(String name, BigDecimal price, String description) { Assert.hasText(name, "Name must not be null or empty!"); Assert.isTrue(BigDecimal.ZERO.compareTo(price) < 0, "Price must be greater than zero!"); this.name = name; this.price = price; this.description = description; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public BigDecimal getPrice() { return price; } public void setPrice(BigDecimal price) { this.price = price; } public void setAttribute(String name, String value) { Assert.hasText(name); if (value == null) { this.attributes.remove(value); } else { this.attributes.put(name, value); } } }