Commits

Kevin A. Archie  committed 039aa16

be less brittle with trivial scripts

  • Participants
  • Parent commits 96e2463

Comments (0)

Files changed (1)

File src/main/java/org/nrg/dcm/edit/ScriptApplicator.java

 /**
- * Copyright 2009-2011 Washington University
+ * Copyright 2009-2012 Washington University
  */
 package org.nrg.dcm.edit;
 
             final Map<String,ValueGenerator> generators)
     throws IOException,ScriptEvaluationException {
         if (null == script) {
-            statements = Lists.newArrayList();
+            statements = Collections.emptyList();
             astParser = null;
         } else {
             try {
     }
 
     public ScriptApplicator() {
-        statements = Lists.newArrayList();
+        statements = Collections.emptyList();
         astParser = null;
     }
 
     public int getTopTag() {
         final SortedSet<Integer> tags = Sets.newTreeSet();
+        tags.add(0);
         for (final Statement s : statements) {
             tags.add(s.getTopTag());
         }
     }
     
     public Variable getVariable(final String label) {
-        return astParser.getVariable(label);
+        return null == astParser ? null : astParser.getVariable(label);
     }
 
     public Map<String,Variable> getVariables() {
-        return astParser.getVariables();
+        return null == astParser ? Collections.<String,Variable>emptyMap() : astParser.getVariables();
     }
 
     public List<Variable> getSortedVariables(final Collection<String> excluding) {
         final Map<Variable,Collection<Variable>> graph = Maps.newLinkedHashMap();
-        for (final Variable v : astParser.getVariables().values()) {
+        for (final Variable v : getVariables().values()) {
             if (!excluding.contains(v.getName())) {
                 final Value iv = v.getInitialValue();
                 final Collection<Variable> dependencies = Lists.newArrayList();
     }
 
     public void setGenerator(final String label, final ValueGenerator generator) {
-        astParser.setGenerator(label, generator);
+        if (null != astParser) {
+            astParser.setGenerator(label, generator);
+        }
     }
 
     public void setFunction(final String label, final ScriptFunction function) {
-        astParser.setFunction(label, function);
+        if (null != astParser) {
+            astParser.setFunction(label, function);
+        }
     }
 
 
      */
     public static void main(final String args[]) throws Exception {
         final InputStream in;
-        if (0 == args.length || "".equals(args[0])) {
+        if (0 == args.length || "-".equals(args[0])) {
             in = System.in;
         } else {
             in = new FileInputStream(args[0]);