/*
 * Bach - Java Shell Builder
 * Copyright (C) 2020 Christian Stein
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.sormuras.bach.project.structure;

import java.util.List;
import java.util.StringJoiner;

/** A named collection of modular units sharing compilation-related properties. */
public /*static*/ class Realm {

  private final String name;
  private final int release;
  private final boolean preview;
  private final List<Unit> units;

  public Realm(String name, int release, boolean preview, List<Unit> units) {
    this.name = name;
    this.release = release;
    this.preview = preview;
    this.units = units;
  }

  public String name() {
    return name;
  }

  public int release() {
    return release;
  }

  public boolean preview() {
    return preview;
  }

  public List<Unit> units() {
    return units;
  }

  @Override
  public String toString() {
    return new StringJoiner(", ", Realm.class.getSimpleName() + "[", "]")
        .add("name='" + name + "'")
        .add("release=" + release)
        .add("preview=" + preview)
        .add("units=" + units)
        .toString();
  }
}

@@ -695,16 +695,43 @@
 l.List;%0A
+import java.util.Optional;%0A
 import j
@@ -994,16 +994,49 @@
 %3E units;
+%0A  private final String mainUnit;
 %0A%0A  publ
@@ -1103,16 +1103,33 @@
 t%3E units
+, String mainUnit
 ) %7B%0A    
@@ -1222,24 +1222,54 @@
 ts = units;%0A
+    this.mainUnit = mainUnit;%0A
   %7D%0A%0A  publi
@@ -1465,16 +1465,71 @@
 s;%0A  %7D%0A%0A
+  public String mainUnit() %7B%0A    return mainUnit;%0A  %7D%0A%0A
   @Overr
@@ -1781,24 +1781,187 @@
        .
-toString
+add(%22mainUnit=%22 + mainUnit)%0A        .toString();%0A  %7D%0A%0A  public Optional%3CUnit%3E toMainUnit() %7B%0A    return units.stream().filter(unit -%3E unit.name().equals(mainUnit)).findAny
 ();%0A  %7D%0A

Extend realm with main-unit component