Java tutorial
/* * $Id$ * * This file is released under the GNU General Public License. * Refer to the COPYING file distributed with this package. * * Copyright (c) 2008 WURFL-Pro S.r.l. */ package it.filosganga.mobile.widgets.component; import org.apache.commons.lang.Validate; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; /** * @author Filippo De Luca * @version $Id$ */ public class TableColumn extends Component { private static final long serialVersionUID = 10L; private String label; private String shortLabel; private int colspan = 1; public TableColumn(String label) { this(label, null, 1); } public TableColumn(String label, String shortLabel) { this(label, shortLabel, 1); } public TableColumn(String label, String shortLabel, int colspan) { Validate.notEmpty(label); Validate.isTrue(colspan >= 1); this.label = label; this.shortLabel = shortLabel; this.colspan = colspan; } // Access methods ***************************************************** public String getLabel() { return label; } public String getShortLabel() { return shortLabel; } public int getColspan() { return colspan; } // Business methods *************************************************** public TableHeader getHeader() { return (TableHeader) getParent(); } public Table getTable() { if (getHeader() == null) { throw new IllegalStateException("The column have no associated header"); } return getHeader().getTable(); } public int getIndex() { if (getHeader() == null) { throw new IllegalStateException("The column have no associated header"); } return getHeader().getColumnIndex(this); } // Commons methods **************************************************** @Override public boolean equals(Object obj) { EqualsBuilder builder = new EqualsBuilder(); builder.appendSuper(super.equals(obj)); if (builder.isEquals() && obj instanceof TableColumn) { TableColumn other = (TableColumn) obj; builder.append(label, other.label); builder.append(shortLabel, other.shortLabel); builder.append(colspan, other.colspan); } return builder.isEquals(); } @Override public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder(); builder.appendSuper(super.hashCode()); builder.append(label).append(shortLabel).append(colspan); return builder.toHashCode(); } @Override public String toString() { ToStringBuilder builder = new ToStringBuilder(this); builder.appendSuper(super.toString()); builder.append(label).append(shortLabel).append(colspan); return builder.toString(); } }