title: How to create an immutable builder of an immutable class that contains a set?
body: <p>I am trying to create an immutable builder of an immutable class that contains a Set.  It should be an immutable set really but for now I have to use the regular JCF classes.  Using the standard pizza example, I have the pizza base as a mandatory parameter and toppings as optional, 0 or more allowed.  I imagine that each call to <code>addToppings()</code> will create a new immutable builder with a set of toppings and then finally when build is called the Pizza object will be delivered.  I just don't know how to build up the immutable set of <code>toppings</code>.  Here is my code:</p>
  
  <pre><code>public class Pizza {
  
  private Pizza(Base base, Set&lt;Topping&gt; toppings) {
      this.base = base;
      this.toppings = toppings;
  }
  
  public static PizzaBuilder createBuilder(Base pizzaBase) {
      return new PizzaBuilder(new Pizza(pizzaBase, null));
  }
  
  public static class PizzaBuilder {
      private PizzaBuilder(Pizza pizza) {
          this.pizza = pizza;
      }
  
      public PizzaBuilder addTopping(Topping topping) {
          return new PizzaBuilder(new Pizza(pizza.base, ???));
      }
  
      public Pizza build() {
          return pizza;
      }
  
      final private Pizza pizza;
  }
  
  public Collection&lt;Topping&gt; getToppings() {
      return Collections.unmodifiableSet(toppings);
  }
  
  enum Base {DEEP_PAN, THIN}
  enum Topping {MOZZARELLA, TOMATO, ANCHOVIES, PEPPERONI}
  
  final private Base base;
  final private Set&lt;Topping&gt; toppings;
  </code></pre>
  
  <p>}</p>
  
  <p>I know this is a deviation from the 'standard' new builder pattern but I find the storing and copying of values there inelegant because the target class already defines what fields are needed.</p>