]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/Range.java
Fixed multiple issues causing dangling references to discarded queries
[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 parse(String identifier) {
44         return Spreadsheets.decodeCellAbsolute(identifier);
45     }
46
47     public static Range combine(Range from, Range to) {
48         return new Range(from.startRow, to.endRow, from.startColumn, to.endColumn);
49     }
50
51     public boolean isFull() {
52         return endRow == MAXROWSPEC && endColumn == MAXCOLUMNSPEC;
53     }
54
55     public boolean isFullRows() {
56         return endRow == MAXROWSPEC;
57     }
58
59     public boolean isFullColumns() {
60         return endColumn == MAXCOLUMNSPEC;
61     }
62
63     public int size() {
64         return (endRow-startRow + 1) * (endColumn - startColumn + 1);
65     }
66
67     public int width() {
68         return (endColumn - startColumn + 1);
69     }
70
71     public int height() {
72         return (endRow-startRow + 1);
73     }
74
75     public boolean contains(Range r) {
76         if(endRow >= 0) {
77             if(r.endRow > endRow) return false;
78             if(r.startRow < startRow) return false;
79         }
80         if(endColumn >= 0) {
81             if(r.startColumn < startColumn) return false;
82             if(r.endColumn > endColumn) return false;
83         }
84         return true;
85     }
86
87     @Override
88     public String toString() {
89         return "Range[(" + startRow + "," + startColumn + ")-(" + endRow + "," + endColumn + ")]";
90     }
91
92 }