]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet/src/org/simantics/spreadsheet/solver/formula/parser/ast/AstRange.java
Adopt spreadsheet changes made in Balas development
[simantics/platform.git] / bundles / org.simantics.spreadsheet / src / org / simantics / spreadsheet / solver / formula / parser / ast / AstRange.java
1 /*******************************************************************************
2  *  Copyright (c) 2010 Association for Decentralized Information Management in
3  *  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.solver.formula.parser.ast;
13
14 import org.simantics.spreadsheet.solver.formula.PrintVisitor;
15
16 public class AstRange implements AstValue {
17         
18         private static final long serialVersionUID = -2612788686679843356L;
19
20         public static final AstRange REF = new AstRange("#REF!");
21
22         public String sheetName;
23         public String first;
24         public String second;
25
26         public AstRange(String sheetName, String first, String second) {
27                 this.sheetName = sheetName;
28                 this.first = first;
29                 this.second = second;
30         }
31
32         public AstRange(String token) {
33                 String[] parts = token.split(":");
34                 if(parts.length == 2) {
35                         this.first = parts[0];
36                         this.second = parts[1];
37                 } else {
38                         this.first = token;
39                 }
40         }
41         
42         @Override
43         public <T> T accept(AstValueVisitor<T> v) {
44                 return v.visit(this);
45         }
46
47         public boolean isCell() {
48                 return second == null;
49         }
50         
51         public boolean isRef() {
52                 return second==null && "#REF!".equals(first);
53         }
54         
55         public AstRange inSheet(String sheetName) {
56                 AstRange range = new AstRange(sheetName, first, second);
57                 return range;
58         }
59         
60         @Override
61         public String toString() {
62                 return accept(new PrintVisitor());
63         }
64         
65 }