Author: ruschein
Date: 2011-09-14 16:15:09 -0700 (Wed, 14 Sep 2011)
New Revision: 26803

Modified:
   
cytoscape/trunk/application/src/main/java/cytoscape/data/CyAttributesImpl.java
   
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/EqnCompiler.java
   
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/EqnParser.java
   
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/EqnParserImpl.java
   
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/Equation.java
Log:
Made default cell references work.

Modified: 
cytoscape/trunk/application/src/main/java/cytoscape/data/CyAttributesImpl.java
===================================================================
--- 
cytoscape/trunk/application/src/main/java/cytoscape/data/CyAttributesImpl.java  
    2011-09-14 22:37:59 UTC (rev 26802)
+++ 
cytoscape/trunk/application/src/main/java/cytoscape/data/CyAttributesImpl.java  
    2011-09-14 23:15:09 UTC (rev 26803)
@@ -1138,6 +1138,7 @@
                        currentlyActiveAttributes.add(attribName);
 
                final Collection<String> attribReferences = 
equation.getAttribReferences();
+               final Map<String, Object> defaultValues = 
equation.getDefaultValues();
 
                final Map<String, IdentDescriptor> nameToDescriptorMap = new 
TreeMap<String, IdentDescriptor>();
                for (final String attribRef : attribReferences) {
@@ -1146,14 +1147,19 @@
                                continue;
                        }
 
-                       final Object attribValue = getAttribute(id, attribRef);
+                       Object attribValue = getAttribute(id, attribRef);
                        if (attribValue == null) {
-                               currentlyActiveAttributes.clear();
-                               errorMessage.append("Missing value for 
referenced attribute \"" + attribRef + "\"!");
-                               logger.warn("Missing value for \"" + attribRef
-                                           + "\" while evaluating an equation 
(ID:" + id
-                                           + ", attribute name:" + attribName 
+ ")");
-                               return null;
+                               final Object defaultValue = 
defaultValues.get(attribRef);
+                               if (defaultValue != null)
+                                       attribValue = defaultValue;
+                               else {
+                                       currentlyActiveAttributes.clear();
+                                       errorMessage.append("Missing value for 
referenced attribute \"" + attribRef + "\"!");
+                                       logger.warn("Missing value for \"" + 
attribRef
+                                                   + "\" while evaluating an 
equation (ID:" + id
+                                                   + ", attribute name:" + 
attribName + ")");
+                                       return null;
+                               }
                        }
 
                        try {

Modified: 
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/EqnCompiler.java
===================================================================
--- 
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/EqnCompiler.java
   2011-09-14 22:37:59 UTC (rev 26802)
+++ 
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/EqnCompiler.java
   2011-09-14 23:15:09 UTC (rev 26803)
@@ -71,7 +71,9 @@
                        code[i]            = codeAndSourceLocation.getCode();
                        sourceLocations[i] = 
codeAndSourceLocation.getSourceLocation();
                }
-               this.equation = new Equation(equation, 
parser.getVariableReferences(), code, sourceLocations, parser.getType());
+               this.equation = new Equation(equation, 
parser.getVariableReferences(),
+                                            parser.getDefaultValues(), code, 
sourceLocations,
+                                            parser.getType());
 
                errorMsg = null;
                return true;

Modified: 
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/EqnParser.java
===================================================================
--- 
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/EqnParser.java
     2011-09-14 22:37:59 UTC (rev 26802)
+++ 
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/EqnParser.java
     2011-09-14 23:15:09 UTC (rev 26803)
@@ -77,6 +77,11 @@
        public Set<String> getVariableReferences();
 
        /**
+        *  @return a map from variable names to their default values, if any
+        */
+       public Map<String, Object> getDefaultValues();
+
+       /**
         *  @return the parse tree.  Must only be called if parse() returns 
true!
         */
        public Node getParseTree();

Modified: 
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/EqnParserImpl.java
===================================================================
--- 
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/EqnParserImpl.java
 2011-09-14 22:37:59 UTC (rev 26802)
+++ 
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/EqnParserImpl.java
 2011-09-14 23:15:09 UTC (rev 26803)
@@ -1,7 +1,7 @@
 /*
   File: EqnParserImpl.java
 
-  Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+  Copyright (c) 2010-2011, The Cytoscape Consortium (www.cytoscape.org)
 
   This library is free software; you can redistribute it and/or modify it
   under the terms of the GNU Lesser General Public License as published
@@ -35,6 +35,7 @@
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
 import java.util.TreeSet;
 import org.cytoscape.equations.parse_tree.*;
 
@@ -47,6 +48,7 @@
        private Node parseTree;
        private Map<String, Class> variableNameToTypeMap;
        private Set<String> variableReferences;
+       private Map<String, Object> defaultValues;
        private Set<Function> registeredFunctions;
 
        public EqnParserImpl() {
@@ -92,6 +94,7 @@
                this.formula = formula;
                this.variableNameToTypeMap = variableNameToTypeMap;
                this.variableReferences = new TreeSet<String>();
+               this.defaultValues = new TreeMap<String, Object>();
                this.tokeniser = new Tokeniser(formula.substring(1));
                this.lastErrorMessage = null;
 
@@ -131,6 +134,8 @@
 
        public Set<String> getVariableReferences() { return variableReferences; 
}
 
+       public Map<String, Object> getDefaultValues() { return defaultValues; }
+
        /**
         *  @return the parse tree.  Must only be called if parse() returns 
true!
         */
@@ -232,11 +237,12 @@
                        if (token != Token.IDENTIFIER)
                                throw new IllegalStateException(sourceLocation 
+ ": identifier expected!");
 
-                       final Class varRefType = 
variableNameToTypeMap.get(tokeniser.getIdent());
+                       final String ident = tokeniser.getIdent();
+                       final Class varRefType = 
variableNameToTypeMap.get(ident);
                        if (varRefType == null)
                                throw new IllegalStateException(sourceLocation 
+ ": unknown variable reference name: \""
-                                                               + 
tokeniser.getIdent() + "\"!");
-                       variableReferences.add(tokeniser.getIdent());
+                                                               + ident + 
"\"!");
+                       variableReferences.add(ident);
 
                        Object defaultValue = null;
                        if (usingOptionalBraces) {
@@ -265,6 +271,8 @@
 
                                if (token != Token.CLOSE_BRACE)
                                        throw new 
IllegalStateException(sourceLocation + ": closing brace expected!");
+
+                               defaultValues.put(ident, defaultValue);
                        }
 
                        return new IdentNode(varRefStartPos, 
tokeniser.getIdent(), defaultValue, varRefType);

Modified: 
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/Equation.java
===================================================================
--- 
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/Equation.java
      2011-09-14 22:37:59 UTC (rev 26802)
+++ 
cytoscape/trunk/corelibs/equations/src/main/java/org/cytoscape/equations/Equation.java
      2011-09-14 23:15:09 UTC (rev 26803)
@@ -38,6 +38,7 @@
 public class Equation {
        private final String equation;
        private final Set<String> attribReferences;
+       private final Map<String, Object> defaultValues;
        private final Object[] code;
        private final int[] sourceLocations;
        private final Class type;
@@ -45,14 +46,17 @@
        /**
         *  @param equation          the string representing this equation
         *  @param attribReferences  other attributes that are referenced by 
this equation
+        *  @param defaultValues     default values for attribute references, 
if any
         *  @param code              the instruction sequence representing the 
compiled equation
         *  @param type              the type of the equation, String.class, 
Boolean.class or Double.class
         */
-       Equation(final String equation, final Set<String> attribReferences, 
final Object[] code,
+       Equation(final String equation, final Set<String> attribReferences,
+                final Map<String, Object> defaultValues, final Object[] code,
                 final int[] sourceLocations, final Class type)
        {
                this.equation         = equation;
                this.attribReferences = attribReferences;
+               this.defaultValues    = defaultValues;
                this.code             = code;
                this.sourceLocations  = sourceLocations;
                this.type             = type;
@@ -69,6 +73,7 @@
        }
 
        public Set<String> getAttribReferences() { return attribReferences; }
+       public Map<String, Object> getDefaultValues() { return defaultValues; }
        public Object[] getCode() { return code; }
        public int[] getSourceLocations() { return sourceLocations; }
        public Class getType() { return type; }
@@ -88,7 +93,8 @@
 
                final Equation errorEquation = compiler.getEquation();
 
-               return new Equation(equation, errorEquation.attribReferences, 
errorEquation.code,
+               return new Equation(equation, errorEquation.attribReferences,
+                                   errorEquation.defaultValues, 
errorEquation.code,
                                    errorEquation.sourceLocations, type);
        }
 

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to