01: /* HeaderPredicate.java
02: *
03: * DDSteps - Data Driven JUnit Test Steps
04: * Copyright (C) 2005 Jayway AB
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License version 2.1 as published by the Free Software Foundation.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, visit
17: * http://www.opensource.org/licenses/lgpl-license.php
18: */
19: package org.ddsteps.dataset.excel;
20:
21: import jxl.Cell;
22: import jxl.CellReferenceHelper;
23: import jxl.CellType;
24: import net.sf.cglib.core.Predicate;
25:
26: /**
27: * @author Adam
28: * @version $Id: HeaderPredicate.java,v 1.1 2005/12/03 12:51:40 adamskogman Exp $
29: */
30: class HeaderPredicate implements Predicate,
31: org.apache.commons.collections.Predicate {
32:
33: /**
34: * Useful instance, use this instead of creating one.
35: */
36: public static final HeaderPredicate INSTANCE = new HeaderPredicate();
37:
38: /**
39: * Hidden, singleton
40: */
41: private HeaderPredicate() {
42: super ();
43: }
44:
45: /**
46: * Say true if this cell is a non-empty label cell.
47: *
48: * @see org.apache.commons.collections.Predicate#evaluate(java.lang.Object)
49: */
50: public boolean evaluate(Object object) {
51:
52: // Must be a cell
53: Cell cell = (Cell) object;
54:
55: if (cell == null)
56: return false;
57:
58: CellType type = cell.getType();
59:
60: if (type == CellType.LABEL || type == CellType.STRING_FORMULA) {
61: return true;
62: } else if (type == CellType.EMPTY) {
63: return false;
64: } else {
65: // Cannot use this
66: throw new ExcelDataException("Bad cell type for a header: "
67: + CellReferenceHelper.getCellReference(cell
68: .getColumn(), cell.getRow()));
69: }
70:
71: }
72:
73: }
|