public AttributeDescription withOption(final String option){
  Reject.ifNull(option);
  final String normalizedOption=toLowerCase(option);
  if (optionsPimpl.hasOption(normalizedOption)) {
    return this;
  }
  final String newAttributeDescription=appendOption(attributeDescription,option);
  final Impl impl=optionsPimpl;
  if (impl instanceof ZeroOptionImpl) {
    return new AttributeDescription(newAttributeDescription,nameOrOid,attributeType,new SingleOptionImpl(option,normalizedOption));
  }
 else   if (impl instanceof SingleOptionImpl) {
    final SingleOptionImpl simpl=(SingleOptionImpl)impl;
    final String[] newOptions=new String[2];
    newOptions[0]=simpl.option;
    newOptions[1]=option;
    final String[] newNormalizedOptions=new String[2];
    if (normalizedOption.compareTo(simpl.normalizedOption) < 0) {
      newNormalizedOptions[0]=normalizedOption;
      newNormalizedOptions[1]=simpl.normalizedOption;
    }
 else {
      newNormalizedOptions[0]=simpl.normalizedOption;
      newNormalizedOptions[1]=normalizedOption;
    }
    return new AttributeDescription(newAttributeDescription,nameOrOid,attributeType,new MultiOptionImpl(newOptions,newNormalizedOptions));
  }
 else {
    final MultiOptionImpl mimpl=(MultiOptionImpl)impl;
    final int sz1=mimpl.options.length;
    final String[] newOptions=Arrays.copyOf(mimpl.options,sz1 + 1);
    newOptions[sz1]=option;
    final int sz2=mimpl.normalizedOptions.length;
    final String[] newNormalizedOptions=new String[sz2 + 1];
    boolean inserted=false;
    for (int i=0; i < sz2; i++) {
      if (!inserted) {
        final String s=mimpl.normalizedOptions[i];
        if (normalizedOption.compareTo(s) < 0) {
          newNormalizedOptions[i]=normalizedOption;
          newNormalizedOptions[i + 1]=s;
          inserted=true;
        }
 else {
          newNormalizedOptions[i]=s;
        }
      }
 else {
        newNormalizedOptions[i + 1]=mimpl.normalizedOptions[i];
      }
    }
    if (!inserted) {
      newNormalizedOptions[sz2]=normalizedOption;
    }
    return new AttributeDescription(newAttributeDescription,nameOrOid,attributeType,new MultiOptionImpl(newOptions,newNormalizedOptions));
  }
}

public AttributeDescription withOption ( final String option ) { Reject . ifNull ( option ) ; final String normalizedOption = toLowerCase ( option ) ; if ( optionsPimpl . hasOption ( normalizedOption ) ) { return this ; } final String newAttributeDescription = appendOption ( attributeDescription , option ) ; final Impl impl = optionsPimpl ; if ( impl instanceof ZeroOptionImpl ) { return new AttributeDescription ( newAttributeDescription , nameOrOid , attributeType , new SingleOptionImpl ( option , normalizedOption ) ) ; } else if ( impl instanceof SingleOptionImpl ) { final SingleOptionImpl simpl = ( SingleOptionImpl ) impl ; final String [ ] newOptions = new String [ 2 ] ; newOptions [ 0 ] = simpl . option ; newOptions [ 1 ] = option ; final String [ ] newNormalizedOptions = new String [ 2 ] ; if ( normalizedOption . compareTo ( simpl . normalizedOption ) < 0 ) { newNormalizedOptions [ 0 ] = normalizedOption ; newNormalizedOptions [ 1 ] = simpl . normalizedOption ; } else { newNormalizedOptions [ 0 ] = simpl . normalizedOption ; newNormalizedOptions [ 1 ] = normalizedOption ; } return new AttributeDescription ( newAttributeDescription , nameOrOid , attributeType , new MultiOptionImpl ( newOptions , newNormalizedOptions ) ) ; } else { final MultiOptionImpl mimpl = ( MultiOptionImpl ) impl ; final int sz1 = mimpl . options . length ; final String [ ] newOptions = Arrays . copyOf ( mimpl . options , sz1 + 1 ) ; newOptions [ sz1 ] = option ; final int sz2 = mimpl . normalizedOptions . length ; final String [ ] newNormalizedOptions = new String [ sz2 + 1 ] ; boolean inserted = false ; for ( int i = 0 ; i < sz2 ; i ++ ) { if ( ! inserted ) { final String s = mimpl . normalizedOptions [ i ] ; if ( normalizedOption . compareTo ( s ) < 0 ) { newNormalizedOptions [ i ] = normalizedOption ; newNormalizedOptions [ i + 1 ] = s ; inserted = true ; } else { newNormalizedOptions [ i ] = s ; } } else { newNormalizedOptions [ i + 1 ] = mimpl . normalizedOptions [ i ] ; } } if ( ! inserted ) { newNormalizedOptions [ sz2 ] = normalizedOption ; } return new AttributeDescription ( newAttributeDescription , nameOrOid , attributeType , new MultiOptionImpl ( newOptions , newNormalizedOptions ) ) ; } }
returns an attribute description having the same attribute type and options as this attribute description as well as the provided option .
