View | Details | Raw Unified | Return to bug 58403
Collapse All | Expand All

(-)src/java/org/apache/poi/ss/util/CellRangeAddressBase.java (-6 / +40 lines)
Lines 17-22 Link Here
17
17
18
package org.apache.poi.ss.util;
18
package org.apache.poi.ss.util;
19
19
20
import java.util.Arrays;
21
20
import org.apache.poi.ss.SpreadsheetVersion;
22
import org.apache.poi.ss.SpreadsheetVersion;
21
23
22
24
Lines 72-85 Link Here
72
	}
74
	}
73
75
74
76
75
	//TODO use the correct SpreadsheetVersion
77
	/**
78
	 * @deprecated since September 2015. Use {@link #isFullColumnRange(SpreadsheetVersion)}
79
	 * @return
80
	 */
81
	@Deprecated
76
	public final boolean isFullColumnRange() {
82
	public final boolean isFullColumnRange() {
77
		return (_firstRow == 0 && _lastRow == SpreadsheetVersion.EXCEL97.getLastRowIndex())
83
		return isFullColumnRange(SpreadsheetVersion.EXCEL97);
84
	}
85
	/**
86
	 * Returns true if CellRangeAddress spans one or more entire columns
87
	 *
88
	 * @param version
89
	 * @return
90
	 */
91
	public final boolean isFullColumnRange(SpreadsheetVersion version) {
92
		return (_firstRow == 0 && _lastRow == version.getLastRowIndex())
78
		  || (_firstRow == -1 && _lastRow == -1);
93
		  || (_firstRow == -1 && _lastRow == -1);
79
	}
94
	}
80
	//TODO use the correct SpreadsheetVersion
95
	/**
96
	 * @deprecated since September 2015. Use {@link #isFullRowRange(SpreadsheetVersion)}
97
	 * @return
98
	 */
99
	@Deprecated
81
	public final boolean isFullRowRange() {
100
	public final boolean isFullRowRange() {
82
		return (_firstCol == 0 && _lastCol == SpreadsheetVersion.EXCEL97.getLastColumnIndex())
101
		return isFullRowRange(SpreadsheetVersion.EXCEL97);
102
	}
103
	/**
104
	 * Returns true if CellRangeAddress spans one or more entire rows
105
	 *
106
	 * @param version
107
	 * @return
108
	 */
109
	public final boolean isFullRowRange(SpreadsheetVersion version) {
110
		return (_firstCol == 0 && _lastCol == version.getLastColumnIndex())
83
		  || (_firstCol == -1 && _lastCol == -1);
111
		  || (_firstCol == -1 && _lastCol == -1);
84
	}
112
	}
85
113
Lines 193-199 Link Here
193
	
221
	
194
	@Override
222
	@Override
195
	public int hashCode() {
223
	public int hashCode() {
196
		final int[] values = new int[]{getMinRow(), getMaxRow(), getMinColumn(), getMaxColumn()};
224
		int hash = getMinRow();
197
		return values.hashCode();
225
		hash *= 17;
226
		hash += getMaxRow();
227
		hash *= 17;
228
		hash += getMinColumn();
229
		hash *= 17;
230
		hash += getMaxColumn();
231
		return hash;
198
	}
232
	}
199
}
233
}
(-)src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java (-2 / +3 lines)
Lines 22-27 Link Here
22
import junit.framework.AssertionFailedError;
22
import junit.framework.AssertionFailedError;
23
import junit.framework.TestCase;
23
import junit.framework.TestCase;
24
24
25
import org.apache.poi.ss.SpreadsheetVersion;
25
import org.apache.poi.ss.util.CellRangeAddress;
26
import org.apache.poi.ss.util.CellRangeAddress;
26
27
27
/**
28
/**
Lines 181-188 Link Here
181
	}
182
	}
182
183
183
	private static void confirmRange(CellRangeAddress cr, boolean isFullRow, boolean isFullColumn) {
184
	private static void confirmRange(CellRangeAddress cr, boolean isFullRow, boolean isFullColumn) {
184
		assertEquals("isFullRowRange", isFullRow, cr.isFullRowRange());
185
		assertEquals("isFullRowRange", isFullRow, cr.isFullRowRange(SpreadsheetVersion.EXCEL97));
185
		assertEquals("isFullColumnRange", isFullColumn, cr.isFullColumnRange());
186
		assertEquals("isFullColumnRange", isFullColumn, cr.isFullColumnRange(SpreadsheetVersion.EXCEL97));
186
	}
187
	}
187
	
188
	
188
	public void testNumberOfCells() {
189
	public void testNumberOfCells() {
(-)src/testcases/org/apache/poi/ss/util/TestCellRangeAddress.java (+75 lines)
Lines 25-30 Link Here
25
import static org.junit.Assert.assertNotEquals; //junit4
25
import static org.junit.Assert.assertNotEquals; //junit4
26
26
27
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
27
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
28
import org.apache.poi.ss.SpreadsheetVersion;
28
import org.apache.poi.util.LittleEndianOutputStream;
29
import org.apache.poi.util.LittleEndianOutputStream;
29
30
30
public final class TestCellRangeAddress extends TestCase {
31
public final class TestCellRangeAddress extends TestCase {
Lines 233-236 Link Here
233
        assertEquals(4, ref.getMinColumn());
234
        assertEquals(4, ref.getMinColumn());
234
        assertEquals(10, ref.getMaxColumn());
235
        assertEquals(10, ref.getMaxColumn());
235
    }
236
    }
237
    
238
    public static void testIsFullRowRange() {
239
        CellRangeAddress ref = new CellRangeAddress(0, 0, 0, 0);
240
        assertFalse("single cell range",
241
                ref.isFullRowRange(SpreadsheetVersion.EXCEL97));
242
        
243
        // 1 before last column (for Excel 97
244
        ref = new CellRangeAddress(0, 0, 0, 254);
245
        assertFalse("1 before last column for EXCEL97",
246
                ref.isFullRowRange(SpreadsheetVersion.EXCEL97));
247
        
248
        // last column (for Excel97)
249
        ref = new CellRangeAddress(0, 0, 0, 255);
250
        assertTrue("last column for Excel 97",
251
                ref.isFullRowRange(SpreadsheetVersion.EXCEL97));
252
        assertFalse("many before last column for Excel 2007",
253
                ref.isFullRowRange(SpreadsheetVersion.EXCEL2007));
254
        
255
        // 1 before last column
256
        ref = new CellRangeAddress(0, 0, 0, 16382);
257
        assertFalse("many after last column for Excel 97",
258
                ref.isFullRowRange(SpreadsheetVersion.EXCEL97));
259
        assertFalse("1 before last column for Excel 2007",
260
                ref.isFullRowRange(SpreadsheetVersion.EXCEL2007));
261
        
262
        //last column
263
        ref = new CellRangeAddress(0, 0, 0, 16383);
264
        assertTrue("last column for Excel 2007",
265
                ref.isFullRowRange(SpreadsheetVersion.EXCEL2007));
266
        
267
        //1 after last column
268
        ref = new CellRangeAddress(0, 0, 0, 16384);
269
        assertFalse("1 after last column for Excel 2007",
270
                ref.isFullRowRange(SpreadsheetVersion.EXCEL2007));
271
        
272
        // Does -1, -1 mean this is an invalid/deleted reference? Is this a useful test?
273
        ref = new CellRangeAddress(0, 0, -1, -1);
274
        assertTrue(ref.isFullRowRange(SpreadsheetVersion.EXCEL97));
275
        assertTrue(ref.isFullRowRange(SpreadsheetVersion.EXCEL2007));
276
    }
277
    
278
    public static void testIsFullColumnRange() {
279
        CellRangeAddress ref = new CellRangeAddress(0, 0, 0, 0);
280
        assertFalse(ref.isFullColumnRange(SpreadsheetVersion.EXCEL97));
281
        
282
        ref = new CellRangeAddress(0, 65534, 0, 0);
283
        assertFalse(ref.isFullColumnRange(SpreadsheetVersion.EXCEL97));
284
        
285
        ref = new CellRangeAddress(0, 65535, 0, 0);
286
        assertTrue(ref.isFullColumnRange(SpreadsheetVersion.EXCEL97));
287
        assertFalse(ref.isFullColumnRange(SpreadsheetVersion.EXCEL2007));
288
        
289
        ref = new CellRangeAddress(0, 1048574, 0, 0);
290
        assertFalse(ref.isFullColumnRange(SpreadsheetVersion.EXCEL97));
291
        assertFalse(ref.isFullColumnRange(SpreadsheetVersion.EXCEL2007));
292
        
293
        ref = new CellRangeAddress(0, 1048575, 0, 0);
294
        assertTrue(ref.isFullColumnRange(SpreadsheetVersion.EXCEL2007));
295
        
296
        ref = new CellRangeAddress(0, 1048576, 0, 0);
297
        assertFalse(ref.isFullColumnRange(SpreadsheetVersion.EXCEL2007));
298
        
299
        // Does -1, -1 mean this is an invalid/deleted reference? Is this a relevant test?
300
        ref = new CellRangeAddress(-1, -1, 0, 0);
301
        assertTrue(ref.isFullColumnRange(SpreadsheetVersion.EXCEL97));
302
        assertTrue(ref.isFullColumnRange(SpreadsheetVersion.EXCEL2007));
303
    }
304
    
305
    public static void testHashCode() {
306
        final CellRangeAddress a = new CellRangeAddress(0, 0, 0, 0);
307
        final CellRangeAddress b = new CellRangeAddress(0, 0, 0, 0);
308
        assertNotSame(a, b);
309
        assertEquals(a.hashCode(), b.hashCode());
310
    }
236
}
311
}

Return to bug 58403