code: public void addVar(Var var) {
          int id = var.getId();
          boolean alreadyAdded = (0 <= id && id < vars.size());
          if (alreadyAdded) {
              if (vars.get(id) != var) {
                  throw new IllegalStateException("Var id already set, but factor not yet added.");
              }
          } else {  
              // Var was not yet in the factor graph.
              //
              // Check and set the id.
              if (id != -1 && id != vars.size()) {
                  throw new IllegalStateException("Var id already set, but incorrect: " + id);
              }
              var.setId(vars.size());
              // Add the Var.
              vars.add(var);
  
              if (bg != null) { log.warn("Discarding BipartiteGraph. This may indicate inefficiency."); }
              bg = null;
          }
      }
docs: Adds a variable to this factor graph, if not already present.
  
  @param var The variable to add.
  @return The node for this variable.