001/* 002 * Shredzone Commons 003 * 004 * Copyright (C) 2012 Richard "Shred" Körber 005 * http://commons.shredzone.org 006 * 007 * This program is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU Library General Public License as 009 * published by the Free Software Foundation, either version 3 of the 010 * License, or (at your option) any later version. 011 * 012 * This program is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU Library General Public License 018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 019 */ 020package org.shredzone.commons.taglib.processor; 021 022import javax.annotation.Nonnull; 023import javax.annotation.ParametersAreNonnullByDefault; 024import javax.annotation.concurrent.Immutable; 025 026/** 027 * A bean that stores the parameters of a tag attribute. This bean is immutable once it is 028 * created. 029 * 030 * @author Richard "Shred" Körber 031 */ 032@ParametersAreNonnullByDefault 033@Immutable 034public class AttributeBean implements Comparable<AttributeBean> { 035 036 private final String name; 037 private final String type; 038 private final boolean required; 039 private final boolean rtexprvalue; 040 041 /** 042 * Creates and initializes a new {@link AttributeBean}. 043 * 044 * @param name 045 * Attribute name 046 * @param type 047 * Attribute type 048 * @param required 049 * {@code true}: The attribute is required 050 * @param rtexprvalue 051 * {@code true} The attribute is a rtexpression value 052 */ 053 public AttributeBean(String name, String type, boolean required, boolean rtexprvalue) { 054 this.name = name; 055 this.type = type; 056 this.required = required; 057 this.rtexprvalue = rtexprvalue; 058 } 059 060 public @Nonnull String getName() { return name; } 061 062 public @Nonnull String getType() { return type; } 063 064 public boolean isRequired() { return required; } 065 066 public boolean isRtexprvalue() { return rtexprvalue; } 067 068 /** 069 * {@inheritDoc} 070 * <p> 071 * Two {@link AttributeBean} are considered equal if they have an equal name. 072 */ 073 @Override 074 public boolean equals(Object obj) { 075 if (obj == null || !(obj instanceof AttributeBean)) { 076 return false; 077 } 078 return ((AttributeBean) obj).getName().equals(name); 079 } 080 081 @Override 082 public int hashCode() { 083 return name.hashCode(); 084 } 085 086 @Override 087 public int compareTo(AttributeBean o) { 088 return name.compareTo(o.name); 089 } 090 091}