]> gerrit.simantics Code Review - simantics/r.git/blob - org.simantics.r.scl/src/org/simantics/r/scl/variable/RListLengthNode.java
(refs #6833) Test RExp inheritance in SCL
[simantics/r.git] / org.simantics.r.scl / src / org / simantics / r / scl / variable / RListLengthNode.java
1 /*******************************************************************************\r
2  * Copyright (c) 2014, 2016 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.r.scl.variable;\r
13 \r
14 import org.rosuda.REngine.REXP;\r
15 import org.rosuda.REngine.REXPInteger;\r
16 import org.rosuda.REngine.REXPMismatchException;\r
17 \r
18 public class RListLengthNode implements RVariableNode {\r
19 \r
20         RVariableNode parent;\r
21         \r
22         public RListLengthNode(RVariableNode parent) {\r
23                 this.parent = parent;\r
24         }\r
25 \r
26         @Override\r
27         public REXP getValue() {\r
28                 REXP parentValue = parent.getValue();\r
29                 if (parentValue == null)\r
30                         return null;\r
31                 \r
32                 try {\r
33                         return new REXPInteger(parentValue.length());\r
34                 } catch (REXPMismatchException e) {\r
35                         return null;\r
36                 }\r
37         }\r
38 \r
39         @Override\r
40         public String getName() {\r
41                 return "length";\r
42         }\r
43 \r
44         @Override\r
45         public RVariableNode getParent() {\r
46                 return parent;\r
47         }\r
48 }\r