1 /* 2 * Copyright 2009 :torweg free software group 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * 17 */ 18 package org.torweg.pulse.component.statistics.model; 19 20 import javax.persistence.MappedSuperclass; 21 import javax.xml.bind.annotation.XmlAccessOrder; 22 import javax.xml.bind.annotation.XmlAccessType; 23 import javax.xml.bind.annotation.XmlAccessorOrder; 24 import javax.xml.bind.annotation.XmlAccessorType; 25 import javax.xml.bind.annotation.XmlRootElement; 26 27 import org.torweg.pulse.util.entity.AbstractNamedEntity; 28 29 /** 30 * An abstract base class to derive a statistical entity from, which represents 31 * a version. 32 * <p> 33 * To be removed if no further sub-classes are to be derived from 34 * {@code AbstractVersion}. 35 * </p> 36 * 37 * @param <T> 38 * the type of the match; see: AbstractVersion<T>.isMatch(T) 39 * 40 * @author Daniel Dietz 41 * @version $Revision: 1548 $ 42 * 43 */ 44 @XmlRootElement(name = "version") 45 @XmlAccessorOrder(XmlAccessOrder.UNDEFINED) 46 @XmlAccessorType(XmlAccessType.FIELD) 47 @MappedSuperclass 48 public abstract class AbstractVersion<T extends Object> extends 49 AbstractNamedEntity { 50 51 /** 52 * The serialVersionUID. 53 */ 54 private static final long serialVersionUID = 5837930131673084556L; 55 56 /** 57 * Sets the display name. 58 * 59 * @param n 60 * the name 61 * 62 * @throws IllegalArgumentException 63 * if the given name is {@code null} or empty string 64 */ 65 @Override 66 public final void setName(final String n) { 67 if (n == null || n.trim().equals("")) { 68 throw new IllegalArgumentException( 69 "The given name must not be null or empty string."); 70 } 71 super.setName(n); 72 } 73 74 /** 75 * 76 * @param match 77 * the <T> to match 78 * 79 * @return {@code true} if and only if the given >T< matches, 80 * {@code false} otherwise 81 */ 82 public abstract boolean isMatch(final T match); 83 84 /** 85 * Returns a string representation of the {@code Version}. 86 * 87 * @return a string representation of the {@code Version} 88 */ 89 @Override 90 public String toString() { 91 return "{" + super.toString() + "@[" + getId() + "], name: " 92 + getName() + "}"; 93 } 94 95 } 96