/** * Builds a {@link Type} and returns the parent builder, if given, or the * {@code Type} that was built. If returning a parent object that is a * GroupBuilder, the constructed type will be added to it as a field. * <p> * <em>Note:</em> Any configuration for this type builder should be done * before calling this method. * * @param name a name for the constructed type * @return the parent {@code GroupBuilder} or the constructed {@code Type} */ public P named(String name) { Preconditions.checkNotNull(name, "Name is required"); Preconditions.checkNotNull(repetition, "Repetition is required"); Type type = build(name); if (parent != null) { // if the parent is a GroupBuilder, add type to it if (GroupBuilder.class.isAssignableFrom(parent.getClass())) { GroupBuilder.class.cast(parent).addField(type); } return parent; } else { // no parent indicates that the Type object should be returned // the constructor check guarantees that returnClass is a Type return returnClass.cast(type); } }