コード例 #1
0
ファイル: EnvironmentTest.java プロジェクト: ksen938/thundr
  @Test
  public void shouldAllowTheSettingOfTheEnvironment() {
    assertThat(Environment.get(), is(nullValue()));
    assertThat(Environment.is(null), is(true));
    assertThat(Environment.is("anything else"), is(false));

    Environment.set("test");

    assertThat(Environment.get(), is("test"));
    assertThat(Environment.is("test"), is(true));
    assertThat(Environment.is(null), is(false));
    assertThat(Environment.is("Test"), is(false));

    Environment.set("test2");

    assertThat(Environment.get(), is("test2"));
    assertThat(Environment.is("test2"), is(true));
    assertThat(Environment.is("test"), is(false));
  }
コード例 #2
0
ファイル: EnvironmentStack.java プロジェクト: 01mf02/lea
  public VariableInfo getVariable(String id) {
    VariableInfo vi = null;
    for (Enumeration<Environment> e = this.elements(); e.hasMoreElements(); ) {
      Environment env = e.nextElement();

      vi = env.get(id);
      if (vi != null) return vi;
    }

    return null;
  }
コード例 #3
0
ファイル: Call.java プロジェクト: gxzhouyong/MOEAFramework
  @Override
  public Object evaluate(Environment environment) {
    Environment closure = new Environment(environment);

    for (int i = 0; i < getNumberOfArguments(); i++) {
      closure.set(variableNames[i], getArgument(i).evaluate(environment));
    }

    Node functionBody = environment.get(Node.class, functionName);
    return functionBody.evaluate(closure);
  }
コード例 #4
0
 public Object eval(Environment env) {
   Object value = env.get(name());
   if (value == null) throw new StoneException("undefined name: " + name(), this);
   else return value;
 }
コード例 #5
0
 /** Evalaution method for id Fact Nodes. Evaluates the id portion. */
 public double eval(Environment env) throws EvalException {
   return env.get(pos, id);
 }
コード例 #6
0
ファイル: TestEnvironment.java プロジェクト: Toxaris/gll
  @Test
  public final void test() {
    final Environment<String, String> env = new Environment<String, String>();

    env.put("x", "1");
    env.put("y", "2");

    assertEquals("1", env.get("x"));
    assertEquals("2", env.get("y"));

    env.put("x", "3");

    assertEquals("3", env.get("x"));
    assertEquals("2", env.get("y"));

    env.beginScope();

    assertEquals("3", env.get("x"));
    assertEquals("2", env.get("y"));

    env.put("x", "4");

    assertEquals("4", env.get("x"));
    assertEquals("2", env.get("y"));

    env.beginScope();

    assertEquals("4", env.get("x"));
    assertEquals("2", env.get("y"));

    env.put("y", "5");
    env.put("z", "6");

    assertEquals("4", env.get("x"));
    assertEquals("5", env.get("y"));
    assertEquals("6", env.get("z"));

    env.endScope();

    assertEquals("4", env.get("x"));
    assertEquals("2", env.get("y"));
    assertEquals(null, env.get("z"));

    env.put("y", "7");

    assertEquals("4", env.get("x"));
    assertEquals("7", env.get("y"));

    env.endScope();

    assertEquals("3", env.get("x"));
    assertEquals("2", env.get("y"));
  }