package com.github.vangj.jbayes.inf.exact.graph;

import java.util.Set;

/**
 * Represents a discrete variable.
 */
public class Variable {
  protected String id;
  protected String name;
  protected Set<String> values;

  public Variable() {

  }

  private Variable(Builder builder) {
    id = builder.id;
    name = builder.name;
    values = builder.values;
  }

  public static Builder newBuilder() {
    return new Builder();
  }

  public String getId() {
    return id;
  }

  public String getName() {
    return name;
  }

  public Set<String> getValues() {
    return values;
  }

  @Override
  public String toString() {
    return (new StringBuilder())
        .append(id)
        .append(" {")
        .append(String.join(",", values))
        .append('}')
        .toString();
  }

  @Override
  public boolean equals(Object object) {
    if(null == object || !(object instanceof Node)) {
      return false;
    }
    Node that = (Node)object;
    return this.id.equals(that.id);
  }

  @Override
  public int hashCode() {
    return id.hashCode();
  }

  public static final class Builder {
    private String id;
    private String name;
    private Set<String> values;

    private Builder() {
    }

    public Builder id(String val) {
      id = val;
      return this;
    }

    public Builder name(String val) {
      name = val;
      return this;
    }

    public Builder values(Set<String> val) {
      values = val;
      return this;
    }

    public Variable build() {
      return new Variable(this);
    }
  }
}

@@ -43,16 +43,48 @@
 graph;%0A%0A
+import java.util.LinkedHashSet;%0A
 import j
@@ -1234,24 +1234,62 @@
 Builder() %7B%0A
+      values = new LinkedHashSet%3C%3E();%0A
     %7D%0A%0A    p
@@ -1435,32 +1435,120 @@
 rn this;%0A    %7D%0A%0A
+    public Builder value(String val) %7B%0A      values.add(val);%0A      return this;%0A    %7D%0A%0A
     public Build

use linked hashset