/* * JBoss, Home of Professional Open Source * Copyright 2011, Red Hat, Inc., and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * 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.jboss.seam.faces.examples.shortly; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.validation.constraints.Pattern; /** * Represents a mapping between a Tiny URL and its destination URL. * * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> */ @Entity public class TinyLink { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column(unique = true, updatable = false) private String uid; @Column(unique = true, updatable = false) private String name; @Pattern(regexp = "((http|ftp)://)?((www.)?(([\\w-]+\\.)+(\\w+)|localhost)(\\:\\d+)?(/.*)?)", message = "Must be a valid web address") private String target; public Long getId() { return id; } public void setId(final Long id) { this.id = id; } public String getUid() { return uid; } public void setUid(final String key) { this.uid = key; } public String getTarget() { return target; } public void setTarget(final String target) { this.target = target; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((uid == null) ? 0 : uid.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } TinyLink other = (TinyLink) obj; if (id == null) { if (other.id != null) { return false; } } else if (!id.equals(other.id)) { return false; } if (uid == null) { if (other.uid != null) { return false; } } else if (!uid.equals(other.uid)) { return false; } if (name == null) { if (other.name != null) { return false; } } else if (!name.equals(other.name)) { return false; } return true; } public String getName() { return name; } public void setName(final String name) { this.name = name; } }