Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

package org.scijava.parsington.eval;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -89,9 +88,10 @@ public Object get(final String name) {
return new Unresolved(name);
}


@Override
public Map<String, Object> getAll() {
return Collections.unmodifiableMap(vars);
public Map<String, Object> vars() {
return vars;
}

@Override
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/scijava/parsington/eval/Evaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ default Object get(final Variable v) {
}

/**
* Gets a map of all variable names and values.
* Gets the Evaluator variables. Not thread-safe.
* A map of all variable names and values.
*
* @return A map from variable names to variable values.
* @return The map from variable names to variable values.
*/
Map<String, Object> getAll();
Map<String, Object> vars();

/**
* Sets the value of a variable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,24 @@ public void testClear() {
e.set("a", 1);
e.set("b", 2);
e.clear();
assertEquals(new HashMap<>(), e.getAll());
assertEquals(new HashMap<>(), e.vars());
assertThrows(IllegalArgumentException.class, () -> e.get("a"));
assertThrows(IllegalArgumentException.class, () -> e.get("b"));
}

/** Tests {@link Evaluator#getAll()} and {@link Evaluator#setAll(Map)}. */
/** Tests {@link Evaluator#vars()} and {@link Evaluator#setAll(Map)}. */
@Test
public void testGetAllSetAll() {
public void testVarsSetAll() {
final Evaluator e = createEvaluator();
assertEquals(new HashMap<>(), e.getAll());
assertEquals(new HashMap<>(), e.vars());

final Map<String, Object> vars = new HashMap<>();
vars.put("a", 1);
vars.put("b", "two");
vars.put("c", 3.0);
e.setAll(vars);

assertEquals(vars, e.getAll());
assertEquals(vars, e.vars());

// Verify individual get still works after setAll.
assertEquals(1, e.get("a"));
Expand All @@ -110,9 +110,9 @@ public void testGetAllSetAll() {

// Verify variables created at evaluation are accessible and correct.
e.evaluate("d=a+c");
assertTrue(e.getAll().containsKey("d"));
assertTrue(e.vars().containsKey("d"));
final Object dVal = e.get("d");
assertEquals(4.0, dVal);
assertEquals(dVal, e.getAll().get("d"));
assertEquals(dVal, e.vars().get("d"));
}
}
Loading