]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/Range.java
b4a31c316f65a794614ec197e93a7172401472d3
[simantics/platform.git] / bundles / org.simantics.spreadsheet / src / org / simantics / spreadsheet / Range.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.spreadsheet;
13
14
15 public class Range {
16     public static final int MAXROWSPEC = Integer.MAX_VALUE;//1048576;//
17     public static final int MAXCOLUMNSPEC = Integer.MAX_VALUE;//16384;//
18
19     public int startRow;
20     public int endRow;
21     public int startColumn;
22     public int endColumn;
23
24     public Range(int startRow, int endRow, int startColumn, int endColumn) {
25         this.startRow = startRow;
26         this.endRow = endRow;
27         this.startColumn = startColumn;
28         this.endColumn = endColumn;
29
30         if(startRow == -1) this.startRow = MAXROWSPEC;
31         if(endRow == -1) this.endRow = MAXROWSPEC;
32         if(startColumn == -1) this.startColumn = MAXCOLUMNSPEC;
33         if(endColumn == -1) this.endColumn = MAXCOLUMNSPEC;
34     }
35
36     public Range(Range copy) {
37         this.startRow = copy.startRow;
38         this.endRow = copy.endRow;
39         this.startColumn = copy.startColumn;
40         this.endColumn = copy.endColumn;
41     }
42
43     public static Range combine(Range from, Range to) {
44         return new Range(from.startRow, to.endRow, from.startColumn, to.endColumn);
45     }
46
47     public boolean isFull() {
48         return endRow == MAXROWSPEC && endColumn == MAXCOLUMNSPEC;
49     }
50
51     public boolean isFullRows() {
52         return endRow == MAXROWSPEC;
53     }
54
55     public boolean isFullColumns() {
56         return endColumn == MAXCOLUMNSPEC;
57     }
58
59     public int size() {
60         return (endRow-startRow + 1) * (endColumn - startColumn + 1);
61     }
62
63     public int width() {
64         return (endColumn - startColumn + 1);
65     }
66
67     public int height() {
68         return (endRow-startRow + 1);
69     }
70
71     public boolean contains(Range r) {
72         if(endRow >= 0) {
73             if(r.endRow > endRow) return false;
74             if(r.startRow < startRow) return false;
75         }
76         if(endColumn >= 0) {
77             if(r.startColumn < startColumn) return false;
78             if(r.endColumn > endColumn) return false;
79         }
80         return true;
81     }
82
83     @Override
84     public String toString() {
85         return "Range[(" + startRow + "," + startColumn + ")-(" + endRow + "," + endColumn + ")]";
86     }
87
88 }