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 com.github.carlomicieli.rest.representations; import javax.ws.rs.core.EntityTag; import javax.ws.rs.core.MultivaluedMap; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; import org.apache.commons.lang3.builder.HashCodeBuilder; import com.github.carlomicieli.entities.Brand; import com.github.carlomicieli.entities.Era; import com.github.carlomicieli.entities.PowerMethod; import com.github.carlomicieli.entities.Railway; import com.github.carlomicieli.entities.RollingStock; import com.github.carlomicieli.entities.Scale; /** * * @author Carlo Micieli * */ @XmlRootElement(name = "rollingStock", namespace = "http://schemas.trenako.com/2012/05") @XmlAccessorType(XmlAccessType.PROPERTY) public class RollingStockRepresentation { private final RollingStock rollingStock; private String brandName; private String scaleName; private String railwayName; public RollingStockRepresentation() { this.rollingStock = new RollingStock(); } public RollingStockRepresentation(RollingStock rollingStock) { this.rollingStock = rollingStock; } public RollingStockRepresentation(MultivaluedMap<String, String> formValues) { this(); } /** * Returns the rolling stock entity wrapped object. * @return the entity object. */ public RollingStock getInner() { return this.rollingStock; } /** * Return the unique id. * @return the unique id. */ public long getId() { return getInner().getId(); } /** * Set the unique id. * @param id the unique id. */ public void setId(long id) { getInner().setId(id); } /** * Return the brand name. * @return the brand name. */ @XmlTransient Brand getBrand() { return getInner().getBrand(); } /** * Set the brand name. * @param brand the brand name. */ void setBrand(Brand brand) { getInner().setBrand(brand); } /** * Returns the brand name. * @return the brand name. */ @XmlElement(name = "brand") public String getBrandName() { if (this.brandName != null) return this.brandName; if (getBrand() == null) return null; return getBrand().getName(); } /** * Sets the brand name. * @param brandName */ public void setBrandName(String brandName) { this.brandName = brandName; } /** * Return the item number. * @return the item number. */ public String getItemNumber() { return getInner().getItemNumber(); } /** * Set the item number. * @param itemNumber the item number. */ public void setItemNumber(String itemNumber) { getInner().setItemNumber(itemNumber); } /** * Return the rolling stock description. * @return the rolling stock description. */ public String getDescription() { return getInner().getDescription(); } /** * Set the rolling stock description. * @param description the rolling stock description. */ public void setDescription(String description) { getInner().setDescription(description); } /** * Return the railway name. * @return the railway name. */ @XmlTransient public Railway getRailway() { return getInner().getRailway(); } /** * Set the railway name. * @param railway the railway name. */ public void setRailway(Railway railway) { getInner().setRailway(railway); } /** * Return the railway name. * @return the railway name. */ @XmlElement(name = "railway") public String getRailwayName() { if (this.railwayName != null) return this.railwayName; if (getRailway() == null) return null; return getRailway().getName(); } /** * Set the railway name. * @param railwayName the railway name. */ public void setRailwayName(String railwayName) { this.railwayName = railwayName; } /** * Return the scale. * @return the scale. */ @XmlTransient public Scale getScale() { return getInner().getScale(); } /** * Set the scale. * @param scale the scale. */ public void setScale(Scale scale) { getInner().setScale(scale); } /** * Return the scale. * @return the scale. */ @XmlElement(name = "scale") public String getScaleName() { if (this.scaleName != null) return this.scaleName; if (getScale() == null) return null; return getScale().getName(); } /** * Set the scale. * @param scaleName the scale. */ public void setScaleName(String scaleName) { this.scaleName = scaleName; } /** * Returns the model era. * @return the model era. */ public String getEra() { return getInner().getEra().toString(); } /** * Sets the model era. * @param era the model era. */ public void setEra(String era) { getInner().setEra(Enum.valueOf(Era.class, era)); } /** * Returns the model power method. * @return the model power method. */ public String getPowerMethod() { return getInner().getPowerMethod().toString(); } /** * Sets the model power method. * @param powerMethod the model power method. */ public void setPowerMethod(String powerMethod) { getInner().setPowerMethod(Enum.valueOf(PowerMethod.class, powerMethod)); } /** * Compute the ETag for the current player representation. * @return the ETag value. */ public EntityTag tag() { return new EntityTag(Long.toHexString(this.hashCode())); } /** * Returns a string representation of this <em>BrandRepresentation</em>. * @return a string representation of the object. */ @Override public int hashCode() { return new HashCodeBuilder(15, 37).append(getBrandName()).append(getItemNumber()).append(getDescription()) .append(getScale()).append(getRailway()).append(getEra()).append(getPowerMethod()).toHashCode(); } }