private void ensureMutable(final String name) { assert name != null; if (!isMutable(name)) { throw new ImmutableVariableException(name); } }
public Object get(final String name) { assert name != null; Object value = map.get(name); if (value == null && parent != null) { value = parent.get(name); } return value; }
public Object put(final String key, final Object value) { assert key != null; Object prev = get(key); vars.set(key, value); return prev; }
public void unset(final String name) { assert name != null; ensureMutable(name); map.remove(name); if (eventManager != null) { eventManager.publish(new VariableUnsetEvent(name)); } }
public void set(final String name, final Object value, boolean mutable) { assert name != null; ensureMutable(name); Object previous = map.put(name, value); if (!mutable) { immutables.add(name); } if (eventManager != null) { eventManager.publish(new VariableSetEvent(name, previous)); } }
public void onEvent(final EventObject event) throws Exception { if (event instanceof VariableSetEvent) { VariableSetEvent target = (VariableSetEvent) event; delegate.getStrings().add(target.getName()); } else if (event instanceof VariableUnsetEvent) { VariableUnsetEvent target = (VariableUnsetEvent) event; delegate.getStrings().remove(target.getName()); } } });
public <T> T get(final String name, final Class<T> type, final T defaultValue) { T value = get(name, type); if (value == null) { return defaultValue; } return value; }
public void set(final String name, final Object value) { set(name, value, true); }
public boolean contains(final Class<?> type) { assert type != null; return contains(type.getName()); }
public boolean isMutable(final String name) { assert name != null; boolean mutable = true; // First ask out parent if there is one, if they are immutable, then so are we if (parent != null) { mutable = parent.isMutable(name); } if (mutable) { mutable = !immutables.contains(name); } return mutable; }
private void unsetVariable(final Variables vars, final String name) { log.info("Un-setting variable: {}", name); vars.unset(name); } }
public boolean isCloaked(final Class<?> type) { assert type != null; return isCloaked(type.getName()); }
public boolean isMutable(final Class<?> type) { assert type != null; return isMutable(type.getName()); }
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) { if (!initialized) { init(); } return delegate.complete(buffer, cursor, candidates); } }
public Object get(final String name, final Object defaultValue) { Object value = get(name); if (value == null) { return defaultValue; } return value; }
public void set(final Class<?> type, final Object value) { assert type != null; set(type.getName(), value); }
public <T> T get(final Class<T> type, final T defaultValue) { assert type != null; return get(type.getName(), type, defaultValue); }
public <T> T get(final Class<T> type) { assert type != null; return get(type.getName(), type); }