/* (non-Javadoc)
@see com.tvd12.ezyfox.sfs2x.serializer.AgentUnwrapper#newVariable(java.lang.String, java.lang.Object, boolean)
762678
@SuppressWarnings("unchecked")
    @Override
    protected BuddyVariable newVariable(String name, Object value, boolean isHidden) {
        return new SFSBuddyVariable(name, value);
    }
1103093
public boolean refactorVariable(SymbolDefinition n, final String newName) {
        Map<String, SymbolDefinition> scope = n.getVariableDefinitions();

        if (!scope.containsKey(newName)) {

            if (n.getUsages() != null) {
                List<SymbolReference> usages = new LinkedList<SymbolReference>(n.getUsages());

                VoidVisitorAdapter<?> visitor = new VoidVisitorAdapter<Object>() {
                    @Override
                    public void visit(NameExpr nexpr, Object ctx) {
                        Map<String, SymbolDefinition> innerScope = nexpr.getVariableDefinitions();
                        if (innerScope.containsKey(newName)) {
                            nexpr.getParentNode().replaceChildNode(nexpr, new FieldAccessExpr(new ThisExpr(), newName));
                        } else {
                            nexpr.getParentNode().replaceChildNode(nexpr, new NameExpr(newName));
                        }
                    }

                    @Override
                    public void visit(FieldAccessExpr nexpr, Object ctx) {
                        nexpr.getParentNode().replaceChildNode(nexpr,
                                new FieldAccessExpr(nexpr.getScope(), nexpr.getTypeArgs(), newName));
                    }
                };

                for (SymbolReference usage : usages) {
                    Node aux = (Node) usage;

                    aux.accept(visitor, null);

                }
            }

            return true;
        }
        return false;
    }
598802
private boolean vForVariable(String loopVariablesDefinition, TemplateParserContext context) {
    Matcher matcher = VFOR_VARIABLE.matcher(loopVariablesDefinition);
    if (matcher.matches()) {
      initLoopVariable(matcher.group(1), matcher.group(2), context);
      indexVariableInfo = null;
      return true;
    }

    return false;
  }
548885
@Override
    public ConditionBuilder as(String variable)
    {
        Assert.notNull(variable, "Variable name must not be null.");
        this.setOutputVariablesName(variable);
        return this;
    }
1131778
public SDVariable var(@NonNull String name, @NonNull VariableType variableType, WeightInitScheme weightInitScheme,
                             org.nd4j.linalg.api.buffer.DataType dataType, long... shape) {
        if (variables.containsKey(name) && variables.get(name).getVariable().getArr() != null)
            throw new IllegalArgumentException("Another variable with the name " + name + " already exists.");

        if (name == null || name.length() < 1)
            name = getNewVarName();


        SDVariable ret = new SDVariable(name, variableType, this, shape, dataType, weightInitScheme);
        addVariable(ret);

        if(variableType == VariableType.PLACEHOLDER){
            setOriginalPlaceHolderShape(name, shape);
            putShapeForVarName(name, shape);
        }
        return ret;
    }
532191
func NewVariable(v interface{}) (result Variable, err error) {
	switch v := reflect.ValueOf(v); v.Kind() {
	case reflect.String:
		result.Type = TypeString
	default:
		err = fmt.Errorf("Unknown type: %s", v.Kind())
	}

	result.Value = v
	return
}
1048466
@SuppressWarnings("unchecked")
    @Override
	public <T> T execute() {
		User sfsUser = CommandUtil.getSfsUser(agent, api);
		if(sfsUser == null) return null;
		try {
		    AgentClassUnwrapper unwrapper = context.getUserAgentClass(agent.getClass())
		            .getUnwrapper();
			List<UserVariable> variables = new UserAgentSerializer().serialize(unwrapper, agent);
			List<UserVariable> answer = variables;
			if(includedVars.size() > 0) 
			    answer = getVariables(variables, includedVars);
			answer.removeAll(getVariables(answer, excludedVars));
			
			//update user variables on server and notify to client
			if(toClient) api.setUserVariables(sfsUser, answer);
			
			// only update user variables on server
			else sfsUser.setVariables(answer);
		} 
		catch (SFSVariableException e) {
		    throw new IllegalStateException(e);
		}
		return (T)agent;
	}
432043
public SDVariable addVariable(SDVariable variable) {
        Preconditions.checkState(variable.getSameDiff() == this, "Samediff instance must be the same.");

        if (variables.containsKey(variable.getVarName()) && !variables.get(variable.getVarName()).getVariable().equals(variable)) {
            throw new IllegalArgumentException("Variable already found with variable opName " + variable.getVarName());
        }

        Preconditions.checkState(variable.getSameDiff() == this, "Same diff instance for variable must be the same!");
        variables.put(variable.getVarName(), Variable.builder().name(variable.getVarName()).variable(variable).build());
        return variable;
    }
969631
@Override
    public VariableNullability appendNewVariables(ImmutableMap<Variable, Variable> nullabilityBindings) {
        ImmutableList<ImmutableSet<Variable>> groupList = ImmutableList.copyOf(nullableGroups);
        ImmutableMap<Variable, Integer> originalVariableMap = extractVariableMap(groupList);

        AtomicInteger groupCount = new AtomicInteger(groupList.size());

        ImmutableMultimap<Integer, Variable> newVariableMultimap = nullabilityBindings.entrySet().stream()
                .collect(ImmutableCollectors.toMultimap(
                        e -> e.getKey().equals(e.getValue())
                                ? groupCount.getAndIncrement()
                                : originalVariableMap.get(e.getValue()),
                        Map.Entry::getKey));

        ImmutableSet<ImmutableSet<Variable>> newNullableGroups = IntStream.range(0, groupCount.get())
                .boxed()
                .map(i -> i < groupList.size()
                        ? Sets.union(groupList.get(i), ImmutableSet.copyOf(newVariableMultimap.get(i)))
                            .immutableCopy()
                        : ImmutableSet.copyOf(newVariableMultimap.get(i)))
                .collect(ImmutableCollectors.toSet());

        return new VariableNullabilityImpl(newNullableGroups);
    }
1238451
public Variable variable(final String name) {
    Variable var = this.posLiterals.get(name);
    if (var == null) {
      var = new Variable(name, this);
      this.posLiterals.put(name, var);
    }
    return var;
  }
1165614
@Override
	public String onVariable(String variable) {
		String value = null;
		if(variables != null && variables.containsKey(variable)) {
			Object val = variables.get(variable);
			value = (val != null) ? val.toString() : null;
		}
		return value;
	}
652499
function updateVariable(key, value) {
            variableService.addOrUpdate({key: key, value: value}, function () {
                vm.variables[key] = value;
                vm.variable = {
                    key: undefined,
                    value: undefined
                };
            });
        }
578097
public boolean setVariable(Object key, Object value) {
		boolean success = false;
		Object object = null;

		for (int i = working.size() - 1; i >= 0; --i) {
			Map<Object, Object> map = working.get(i);
			object = map.get(key);
			if (object != null) {
				map.put(key, value);
				success = true;
				break;
			}
		}
		if (!success) {
			object = global.get(key);
			if (object != null) {
				global.put(key, value);
				success = true;
			}
		}
		return success;
	}
1296243
protected void initializeVariable(VariableInstanceEntity e) {
    if (Context.getCommandContext() != null && e != null && e.getType() != null) {
      e.getValue();

      // make sure JPA entities are cached for later retrieval
      if (JPAEntityVariableType.TYPE_NAME.equals(e.getType().getTypeName()) || JPAEntityListVariableType.TYPE_NAME.equals(e.getType().getTypeName())) {
        ((CacheableVariable) e.getType()).setForceCacheable(true);
      }
    }
  }
704422
@Override
    public String getValue(final String variable) throws NotAvailableException {
        try {
            return VariableProcessor.resolveVariables(VariableProcessor.resolveVariable(variable, variableProviderPool), true, variableProviderPool);
        } catch (MultiException ex) {
            throw new NotAvailableException("Variable[" + variable + "]", ex);
        }
    }
299735
function createVariable() {
    var id = nextVariableId++;
    var name = '$V';

    do {
        name += variableTokens[id % variableTokensLength];
        id = ~~(id / variableTokensLength);
    } while (id !== 0);

    return name;
}
135728
public Object getVariableValue(String namespaceURI, String prefix, String localName) throws UnresolvableException {
        if (this.request.hasAttribute(localName)) {
            return String.valueOf(this.request.getAttribute(localName));
        }
        
        return null;
    }