ConverterSet add ( Converter converter , Converter [ ] removed ) { Converter [ ] converters = iConverters ; int length = converters . length ; for ( int i = 0 ; i < length ; i ++ ) { Converter existing = converters [ i ] ; if ( converter . equals ( existing ) ) { // Already in the set. if ( removed != null ) { removed [ 0 ] = null ; } return this ; } if ( converter . getSupportedType ( ) == existing . getSupportedType ( ) ) { // Replace the converter. Converter [ ] copy = new Converter [ length ] ; for ( int j = 0 ; j < length ; j ++ ) { if ( j != i ) { copy [ j ] = converters [ j ] ; } else { copy [ j ] = converter ; } } if ( removed != null ) { removed [ 0 ] = existing ; } return new ConverterSet ( copy ) ; } } // Not found, so add it. Converter [ ] copy = new Converter [ length + 1 ] ; System . arraycopy ( converters , 0 , copy , 0 , length ) ; copy [ length ] = converter ; if ( removed != null ) { removed [ 0 ] = null ; } return new ConverterSet ( copy ) ; }
Returns a copy of this set with the given converter added . If a matching converter is already in the set the given converter replaces it . If the converter is exactly the same as one already in the set the original set is returned .