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 java.util.List; 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 TableCell extends CompositeComponent { private static final long serialVersionUID = 10L; private int colspan = 1; private boolean summary = false; public TableCell(List<Component> children, boolean summary, int colspan) { super(children); Validate.isTrue(colspan >= 1); this.summary = summary; this.colspan = colspan; } public TableCell(List<Component> children, boolean summary) { this(children, summary, 1); } public TableCell(List<Component> children) { this(children, false, 1); } public int getColspan() { return colspan; } public boolean isSummary() { return summary; } // Business methods *************************************************** public TableRow getRow() { return (TableRow) getParent(); } public Table getTable() { if (getRow() == null) { throw new IllegalStateException("The cell have no row associated."); } return getRow().getTable(); } public int getIndex() { if (getRow() == null) { throw new IllegalStateException("The cell have no row associated."); } return getRow().getColumnIndex(this); } public boolean isLast() { if (getRow() == null) { throw new IllegalStateException("The cell have no row associated."); } return getRow().isLastCell(this); } // Common methods ***************************************************** @Override public boolean equals(Object obj) { EqualsBuilder builder = new EqualsBuilder(); builder.appendSuper(super.equals(obj)); if (builder.isEquals() && obj instanceof TableCell) { TableCell other = (TableCell) obj; builder.append(summary, other.summary); builder.append(colspan, other.colspan); } return builder.isEquals(); } @Override public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder(); builder.appendSuper(super.hashCode()); builder.append(summary); builder.append(colspan); return builder.toHashCode(); } @Override public String toString() { ToStringBuilder builder = new ToStringBuilder(this); builder.appendSuper(super.toString()); builder.append(summary); builder.append(colspan); return builder.toString(); } }