/*
 * Copyright (c) 2016-2017 by OpenText Corporation. All Rights Reserved.
 */
package com.opentext.ia.configuration;


/**
 * Builder for named configuration objects.
 * @author Ray Sinnema
 * @since 9.4.0
 *
 * @param <P> The type of the parent builder
 * @param <S> The type of this builder
 * @param <C> The type of configuration to build
 */
public class NamedObjectBuilder<P extends BaseBuilder<?, C>, S extends NamedObjectBuilder<?, ?, C>,
    C extends Configuration<?>> extends BaseBuilder<P, C> {

  protected NamedObjectBuilder(P parent, String type) {
    super(parent, type);
    named(typePrefix(type) + someName());
  }

  private String typePrefix(String type) {
    return type.substring(0, Math.min(type.length(), 3)) + '_';
  }

  /**
   * Set the name of the object.
   * @param name The name of the object
   * @return This builder
   */
  @SuppressWarnings("unchecked")
  public final S named(String name) {
    setProperty("name", name);
    return (S)this;
  }

  /**
   * Set the configure property.
   * @param configure The new value of the configure property
   * @return This builder
   * @since 9.8.0
   */
  @SuppressWarnings("unchecked")
  public S configure(String configure) {
    setProperty("configure", configure);
    return (S)this;
  }

}

@@ -113,16 +113,70 @@
 ation;%0A%0A
+import java.util.Arrays;%0Aimport java.util.Collection;%0A
 %0A/**%0A * 
@@ -556,16 +556,147 @@
 , C%3E %7B%0A%0A
+  private static final Collection%3CString%3E COMMON_TYPE_PREFIXES = Arrays.asList(%0A      %22xdb%22, %22space%22, %22search%22, %22root%22, %22query%22);%0A%0A
   protec
@@ -789,21 +789,47 @@
 ePrefix(
+removeCommonTypePrefixes(
 type)
+)
  + someN
@@ -841,16 +841,529 @@
 );%0A  %7D%0A%0A
+  private String removeCommonTypePrefixes(String type) %7B%0A    StringBuilder result = new StringBuilder(type);%0A    boolean found;%0A    do %7B%0A      found = false;%0A      for (String prefix : COMMON_TYPE_PREFIXES) %7B%0A        if (result.length() %3E prefix.length() && result.toString().startsWith(prefix)) %7B%0A          found = true;%0A          result.delete(0, prefix.length());%0A          result.setCharAt(0, Character.toLowerCase(result.charAt(0)));%0A        %7D%0A      %7D%0A    %7D while (found);%0A    return result.toString();%0A  %7D%0A%0A
   privat

Improve default names for objects built by ConfigurationBuilder