001/**
002 * TextPrimitive.java
003 * 
004 * Copyright (c) 2004-2012, Nicole C. Tedesco. All rights reserved.
005 * 
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
007 * use this file except in compliance with the License. You may obtain a copy of
008 * the License at:
009 * 
010 * http://www.apache.org/licenses/LICENSE-2.0
011 * 
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015 * License for the specific language governing permissions and limitations under
016 * the License.
017 */
018
019package net.sf.jaccumulator.texts;
020
021import java.util.NoSuchElementException;
022
023import net.sf.jaccumulator.ConcurrencyStrategy;
024import net.sf.jaccumulator.lex.PrimitiveAction;
025import net.sf.jaccumulator.primitives.Primitive;
026
027/**
028 * A {@link String text} {@link Primitive primitive} implementation
029 * 
030 * @since JAccumulator 4.0
031 * @author Nicole Tedesco (<a
032 *         href="mailto:Nicole@NicoleTedesco.com">Nicole@NicoleTedesco.com</a>)
033 */
034public final class TextPrimitive
035    extends
036        AbstractTextPrimitive<TextPrimitive>
037{
038    private static final long serialVersionUID = 5620031426456524721L;
039
040    private final StringBuilder _theBuilder;
041
042    public TextPrimitive()
043    {
044        super();
045        this._theBuilder = new StringBuilder();
046    }
047
048    public TextPrimitive( final boolean aValue )
049    {
050        this();
051        this._theBuilder.append(aValue);
052    }
053
054    public TextPrimitive(
055        final boolean aValue,
056        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator )
057    {
058        this(aPrimitiveTranslator);
059        this._theBuilder.append(aValue);
060    }
061
062    public TextPrimitive(
063        final boolean aValue,
064        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
065        final PrimitiveAction<Primitive<?>> aRealTranslator )
066    {
067        this(aPrimitiveTranslator, aRealTranslator);
068        this._theBuilder.append(aValue);
069    }
070
071    public TextPrimitive(
072        final boolean aValue,
073        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
074        final PrimitiveAction<Primitive<?>> aRealTranslator,
075        final PrimitiveAction<Primitive<?>> aScalarTranslator )
076    {
077        this(aPrimitiveTranslator, aRealTranslator, aScalarTranslator);
078        this._theBuilder.append(aValue);
079    }
080
081    public TextPrimitive( final byte aValue )
082    {
083        this();
084        this._theBuilder.append(aValue);
085    }
086
087    public TextPrimitive(
088        final byte aValue,
089        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator )
090    {
091        this(aPrimitiveTranslator);
092        this._theBuilder.append(aValue);
093    }
094
095    public TextPrimitive(
096        final byte aValue,
097        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
098        final PrimitiveAction<Primitive<?>> aRealTranslator )
099    {
100        this(aPrimitiveTranslator, aRealTranslator);
101        this._theBuilder.append(aValue);
102    }
103
104    public TextPrimitive(
105        final byte aValue,
106        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
107        final PrimitiveAction<Primitive<?>> aRealTranslator,
108        final PrimitiveAction<Primitive<?>> aScalarTranslator )
109    {
110        this(aPrimitiveTranslator, aRealTranslator, aScalarTranslator);
111        this._theBuilder.append(aValue);
112    }
113
114    public TextPrimitive( final char aValue )
115    {
116        this();
117        this._theBuilder.append(aValue);
118    }
119
120    public TextPrimitive(
121        final char aValue,
122        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator )
123    {
124        this(aPrimitiveTranslator);
125        this._theBuilder.append(aValue);
126    }
127
128    public TextPrimitive(
129        final char aValue,
130        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
131        final PrimitiveAction<Primitive<?>> aRealTranslator )
132    {
133        this(aPrimitiveTranslator, aRealTranslator);
134        this._theBuilder.append(aValue);
135    }
136
137    public TextPrimitive(
138        final char aValue,
139        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
140        final PrimitiveAction<Primitive<?>> aRealTranslator,
141        final PrimitiveAction<Primitive<?>> aScalarTranslator )
142    {
143        this(aPrimitiveTranslator, aRealTranslator, aScalarTranslator);
144        this._theBuilder.append(aValue);
145    }
146
147    public TextPrimitive( final CharSequence aValue )
148    {
149        super();
150        this._theBuilder = new StringBuilder(aValue);
151    }
152
153    public TextPrimitive( final double aValue )
154    {
155        this();
156        this._theBuilder.append(aValue);
157    }
158
159    public TextPrimitive(
160        final double aValue,
161        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator )
162    {
163        this(aPrimitiveTranslator);
164        this._theBuilder.append(aValue);
165    }
166
167    public TextPrimitive(
168        final double aValue,
169        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
170        final PrimitiveAction<Primitive<?>> aRealTranslator )
171    {
172        this(aPrimitiveTranslator, aRealTranslator);
173        this._theBuilder.append(aValue);
174    }
175
176    public TextPrimitive(
177        final double aValue,
178        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
179        final PrimitiveAction<Primitive<?>> aRealTranslator,
180        final PrimitiveAction<Primitive<?>> aScalarTranslator )
181    {
182        this(aPrimitiveTranslator, aRealTranslator, aScalarTranslator);
183        this._theBuilder.append(aValue);
184    }
185
186    public TextPrimitive( final float aValue )
187    {
188        this();
189        this._theBuilder.append(aValue);
190    }
191
192    public TextPrimitive(
193        final float aValue,
194        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator )
195    {
196        this(aPrimitiveTranslator);
197        this._theBuilder.append(aValue);
198    }
199
200    public TextPrimitive(
201        final float aValue,
202        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
203        final PrimitiveAction<Primitive<?>> aRealTranslator )
204    {
205        this(aPrimitiveTranslator, aRealTranslator);
206        this._theBuilder.append(aValue);
207    }
208
209    public TextPrimitive(
210        final float aValue,
211        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
212        final PrimitiveAction<Primitive<?>> aRealTranslator,
213        final PrimitiveAction<Primitive<?>> aScalarTranslator )
214    {
215        this(aPrimitiveTranslator, aRealTranslator, aScalarTranslator);
216        this._theBuilder.append(aValue);
217    }
218
219    public TextPrimitive( final int aValue )
220    {
221        this();
222        this._theBuilder.append(aValue);
223    }
224
225    public TextPrimitive(
226        final int aValue,
227        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator )
228    {
229        this(aPrimitiveTranslator);
230        this._theBuilder.append(aValue);
231    }
232
233    public TextPrimitive(
234        final int aValue,
235        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
236        final PrimitiveAction<Primitive<?>> aRealTranslator )
237    {
238        this(aPrimitiveTranslator, aRealTranslator);
239        this._theBuilder.append(aValue);
240    }
241
242    public TextPrimitive(
243        final int aValue,
244        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
245        final PrimitiveAction<Primitive<?>> aRealTranslator,
246        final PrimitiveAction<Primitive<?>> aScalarTranslator )
247    {
248        this(aPrimitiveTranslator, aRealTranslator, aScalarTranslator);
249        this._theBuilder.append(aValue);
250    }
251
252    public TextPrimitive( final long aValue )
253    {
254        this();
255        this._theBuilder.append(aValue);
256    }
257
258    public TextPrimitive(
259        final long aValue,
260        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator )
261    {
262        this(aPrimitiveTranslator);
263        this._theBuilder.append(aValue);
264    }
265
266    public TextPrimitive(
267        final long aValue,
268        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
269        final PrimitiveAction<Primitive<?>> aRealTranslator )
270    {
271        this(aPrimitiveTranslator, aRealTranslator);
272        this._theBuilder.append(aValue);
273    }
274
275    public TextPrimitive(
276        final long aValue,
277        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
278        final PrimitiveAction<Primitive<?>> aRealTranslator,
279        final PrimitiveAction<Primitive<?>> aScalarTranslator )
280    {
281        this(aPrimitiveTranslator, aRealTranslator, aScalarTranslator);
282        this._theBuilder.append(aValue);
283    }
284
285    public TextPrimitive( final Object aValue )
286    {
287        this();
288        this._theBuilder.append(aValue);
289    }
290
291    public TextPrimitive(
292        final Object aValue,
293        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator )
294    {
295        this(aPrimitiveTranslator);
296        this._theBuilder.append(aValue);
297    }
298
299    public TextPrimitive(
300        final Object aValue,
301        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
302        final PrimitiveAction<Primitive<?>> aRealTranslator )
303    {
304        this(aPrimitiveTranslator, aRealTranslator);
305        this._theBuilder.append(aValue);
306    }
307
308    public TextPrimitive(
309        final Object aValue,
310        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
311        final PrimitiveAction<Primitive<?>> aRealTranslator,
312        final PrimitiveAction<Primitive<?>> aScalarTranslator )
313    {
314        this(aPrimitiveTranslator, aRealTranslator, aScalarTranslator);
315        this._theBuilder.append(aValue);
316    }
317
318    public TextPrimitive(
319        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator )
320    {
321        super(aPrimitiveTranslator);
322        this._theBuilder = new StringBuilder();
323    }
324
325    public TextPrimitive(
326        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
327        final PrimitiveAction<Primitive<?>> aRealTranslator )
328    {
329        super(aPrimitiveTranslator, aRealTranslator);
330        this._theBuilder = new StringBuilder();
331    }
332
333    public TextPrimitive(
334        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
335        final PrimitiveAction<Primitive<?>> aRealTranslator,
336        final PrimitiveAction<Primitive<?>> aScalarTranslator )
337    {
338        super(aPrimitiveTranslator, aRealTranslator, aScalarTranslator);
339        this._theBuilder = new StringBuilder();
340    }
341
342    public TextPrimitive( final short aValue )
343    {
344        this();
345        this._theBuilder.append(aValue);
346    }
347
348    public TextPrimitive(
349        final short aValue,
350        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator )
351    {
352        this(aPrimitiveTranslator);
353        this._theBuilder.append(aValue);
354    }
355
356    public TextPrimitive(
357        final short aValue,
358        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
359        final PrimitiveAction<Primitive<?>> aRealTranslator )
360    {
361        this(aPrimitiveTranslator, aRealTranslator);
362        this._theBuilder.append(aValue);
363    }
364
365    public TextPrimitive(
366        final short aValue,
367        final PrimitiveAction<Primitive<?>> aPrimitiveTranslator,
368        final PrimitiveAction<Primitive<?>> aRealTranslator,
369        final PrimitiveAction<Primitive<?>> aScalarTranslator )
370    {
371        this(aPrimitiveTranslator, aRealTranslator, aScalarTranslator);
372        this._theBuilder.append(aValue);
373    }
374
375    @Override
376    public final TextPrimitive append( final boolean aValue )
377    {
378        this._theBuilder.append(aValue);
379        return this;
380    }
381
382    @Override
383    public final TextPrimitive append( final char aValue )
384    {
385        this._theBuilder.append(aValue);
386        return this;
387    }
388
389    @Override
390    public final TextPrimitive append( final char[] content )
391    {
392        this._theBuilder.append(content);
393        return this;
394    }
395
396    @Override
397    public final TextPrimitive append(
398        final char[] content,
399        final int contentIndex )
400    {
401        this._theBuilder.append(content, contentIndex, content.length
402                - contentIndex);
403        return this;
404    }
405
406    @Override
407    public final TextPrimitive append(
408        final char[] content,
409        final int contentIndex,
410        final int contentLength )
411    {
412        this._theBuilder.append(content, contentIndex, contentLength);
413        return this;
414    }
415
416    @Override
417    public final TextPrimitive append( final CharSequence content )
418    {
419        this._theBuilder.append(content);
420        return this;
421    }
422
423    @Override
424    public final TextPrimitive append(
425        final CharSequence content,
426        final int contentStartIndex )
427    {
428        return this.append(content, contentStartIndex, content.length());
429    }
430
431    @Override
432    public final TextPrimitive append(
433        final CharSequence content,
434        final int contentStartIndex,
435        final int contentEndIndexPlusOne )
436    {
437        this._theBuilder.append(content, contentStartIndex,
438            contentEndIndexPlusOne);
439        return this;
440    }
441
442    @Override
443    public final TextPrimitive append( final double aValue )
444    {
445        this._theBuilder.append(aValue);
446        return this;
447    }
448
449    @Override
450    public final TextPrimitive append( final float aValue )
451    {
452        this._theBuilder.append(aValue);
453        return this;
454    }
455
456    @Override
457    public final TextPrimitive append( final int aValue )
458    {
459        this._theBuilder.append(aValue);
460        return this;
461    }
462
463    @Override
464    public final TextPrimitive append( final long aValue )
465    {
466        this._theBuilder.append(aValue);
467        return this;
468    }
469
470    @Override
471    public final TextPrimitive append( final Object aValue )
472    {
473        this._theBuilder.append(aValue);
474        return this;
475    }
476
477    @Override
478    public final TextPrimitive append( final StringBuffer sb )
479    {
480        this._theBuilder.append(sb);
481        return this;
482    }
483
484    @Override
485    public final TextPrimitive appendCodePoint( final int codePoint )
486    {
487        this._theBuilder.appendCodePoint(codePoint);
488        return this;
489    }
490
491    @Override
492    public final char charAt( final int index )
493    {
494        return this._theBuilder.charAt(index);
495    }
496
497    @Override
498    public final void clear()
499    {
500        this._theBuilder.setLength(0);
501    }
502
503    @Override
504    public final int codePointAt( final int index )
505    {
506        return this._theBuilder.codePointAt(index);
507    }
508
509    @Override
510    public final int codePointBefore( final int index )
511    {
512        return this._theBuilder.codePointBefore(index);
513    }
514
515    @Override
516    public final int codePointCount( final int beginIndex, final int endIndex )
517    {
518        return this._theBuilder.codePointCount(beginIndex, endIndex);
519    }
520
521    @Override
522    public final TextPrimitive copy()
523    {
524        return new TextPrimitive(this._theBuilder);
525    }
526
527    @Override
528    public final TextPrimitive copyUsingText( final CharSequence aValue )
529    {
530        return new TextPrimitive(aValue);
531    }
532
533    @Override
534    public final TextPrimitive delete( final int start, final int end )
535    {
536        this._theBuilder.delete(start, end);
537        return this;
538    }
539
540    @Override
541    public final TextPrimitive deleteCharAt( final int anIndex )
542    {
543        this._theBuilder.deleteCharAt(anIndex);
544        return this;
545    }
546
547    @Override
548    public final ConcurrencyStrategy getConcurrency()
549    {
550        return ConcurrencyStrategy.SEQUENTIAL;
551    }
552
553    @Override
554    public int indexOfText( final CharSequence str )
555    {
556        return this._theBuilder.indexOf(str.toString());
557    }
558
559    @Override
560    public final int indexOfText( final CharSequence str, final int beginIndex )
561    {
562        return this._theBuilder.indexOf(str.toString(), beginIndex);
563    }
564
565    @Override
566    @SuppressWarnings( "unchecked" )
567    public final <TEXT extends Text<?>> TEXT induceTextValue( final TEXT aTarget )
568        throws NullPointerException,
569            NoSuchElementException,
570            UnsupportedOperationException,
571            IllegalStateException
572    {
573        return (TEXT)aTarget.setText(this._theBuilder);
574    }
575
576    @Override
577    public final TextPrimitive insert( final int anIndex, final boolean aValue )
578    {
579        this._theBuilder.insert(anIndex, aValue);
580        return this;
581    }
582
583    @Override
584    public final TextPrimitive insert( final int anIndex, final char aValue )
585    {
586        this._theBuilder.insert(anIndex, aValue);
587        return this;
588    }
589
590    @Override
591    public final TextPrimitive insert( final int anIndex, final char[] content )
592    {
593        this._theBuilder.insert(anIndex, content);
594        return this;
595    }
596
597    @Override
598    public final TextPrimitive insert(
599        final int targetIndex,
600        final char[] content,
601        final int contentIndex,
602        final int contentLength )
603    {
604        this._theBuilder.insert(targetIndex, content, contentIndex,
605            contentLength);
606        return this;
607    }
608
609    @Override
610    public final TextPrimitive insert(
611        final int anIndex,
612        final CharSequence content )
613    {
614        this._theBuilder.insert(anIndex, content);
615        return this;
616    }
617
618    @Override
619    public final TextPrimitive insert(
620        final int targetIndex,
621        final CharSequence content,
622        final int contentIndex ) throws UnsupportedOperationException
623    {
624        return this.insert(targetIndex, content, contentIndex, content.length());
625    }
626
627    @Override
628    public final TextPrimitive insert(
629        final int targetIndex,
630        final CharSequence content,
631        final int contentStartIndex,
632        final int contentEndIndexPlusOne )
633    {
634        this._theBuilder.insert(targetIndex, content, contentStartIndex,
635            contentEndIndexPlusOne);
636        return this;
637    }
638
639    @Override
640    public final TextPrimitive insert( final int anIndex, final double aValue )
641    {
642        this._theBuilder.insert(anIndex, aValue);
643        return this;
644    }
645
646    @Override
647    public final TextPrimitive insert( final int anIndex, final float aValue )
648    {
649        this._theBuilder.insert(anIndex, aValue);
650        return this;
651    }
652
653    @Override
654    public final TextPrimitive insert( final int anIndex, final int aValue )
655    {
656        this._theBuilder.insert(anIndex, aValue);
657        return this;
658    }
659
660    @Override
661    public final TextPrimitive insert( final int anIndex, final long aValue )
662    {
663        this._theBuilder.insert(anIndex, aValue);
664        return this;
665    }
666
667    @Override
668    public final TextPrimitive insert( final int anIndex, final Object aValue )
669    {
670        this._theBuilder.insert(anIndex, aValue);
671        return this;
672    }
673
674    @Override
675    public final boolean isElastic()
676    {
677        return true;
678    }
679
680    @Override
681    public final boolean isEmpty()
682    {
683        return this._theBuilder.length() == 0;
684    }
685
686    @Override
687    public final boolean isExpandable()
688    {
689        return true;
690    }
691
692    @Override
693    public final int length()
694    {
695        return this._theBuilder.length();
696    }
697
698    @Override
699    public TextPrimitive lowerCase()
700    {
701        final int myLength = this.length();
702        for (int i = 0; i < myLength; i++) {
703            final char lowSurrogate = this._theBuilder.charAt(i);
704            if (Character.isHighSurrogate(lowSurrogate)) {
705                final int iNext = i + 1;
706                if (iNext < myLength) {
707                    final char highSurrogate = this._theBuilder.charAt(iNext);
708                    if (Character.isLowSurrogate(highSurrogate)) {
709                        final int cp = Character.toCodePoint(lowSurrogate,
710                            highSurrogate);
711                        final int lcp = Character.toLowerCase(cp);
712                        final char lowerLowSurrogate = Character.lowSurrogate(lcp);
713                        final char lowerHighSurrogate = Character.highSurrogate(lcp);
714                        this._theBuilder.setCharAt(iNext, lowerLowSurrogate);
715                        this._theBuilder.setCharAt(i++, lowerHighSurrogate);
716                        continue;
717                    }
718                }
719            }
720            final char lc = Character.toLowerCase(lowSurrogate);
721            this._theBuilder.setCharAt(i, lc);
722        }
723        return this;
724    }
725
726    @Override
727    public final TextPrimitive prepend( final boolean aValue )
728    {
729        this._theBuilder.insert(0, aValue);
730        return this;
731    }
732
733    @Override
734    public final TextPrimitive prepend( final char aValue )
735    {
736        this._theBuilder.insert(0, aValue);
737        return this;
738    }
739
740    @Override
741    public final TextPrimitive prepend( final char[] content )
742    {
743        this._theBuilder.insert(0, content);
744        return this;
745    }
746
747    @Override
748    public final TextPrimitive prepend(
749        final char[] content,
750        final int contentIndex )
751    {
752        this._theBuilder.insert(0, content, contentIndex, content.length
753                - contentIndex);
754        return this;
755    }
756
757    @Override
758    public final TextPrimitive prepend(
759        final char[] content,
760        final int contentIndex,
761        final int contentLength )
762    {
763        this._theBuilder.insert(0, content, contentIndex, contentLength);
764        return this;
765    }
766
767    @Override
768    public final TextPrimitive prepend( final CharSequence content )
769    {
770        this._theBuilder.insert(0, content);
771        return this;
772    }
773
774    @Override
775    public final TextPrimitive prepend(
776        final CharSequence content,
777        final int contentStartIndex )
778    {
779        return this.prepend(content, contentStartIndex, content.length());
780    }
781
782    @Override
783    public final TextPrimitive prepend(
784        final CharSequence content,
785        final int contentStartIndex,
786        final int contentEndIndexPlusOne )
787    {
788        this._theBuilder.insert(0, content, contentStartIndex,
789            contentEndIndexPlusOne);
790        return this;
791    }
792
793    @Override
794    public final TextPrimitive prepend( final double aValue )
795    {
796        this._theBuilder.insert(0, aValue);
797        return this;
798    }
799
800    @Override
801    public final TextPrimitive prepend( final float aValue )
802    {
803        this._theBuilder.insert(0, aValue);
804        return this;
805    }
806
807    @Override
808    public final TextPrimitive prepend( final int aValue )
809    {
810        this._theBuilder.insert(0, aValue);
811        return this;
812    }
813
814    @Override
815    public final TextPrimitive prepend( final long aValue )
816    {
817        this._theBuilder.insert(0, aValue);
818        return this;
819    }
820
821    @Override
822    public final TextPrimitive prepend( final Object aValue )
823    {
824        this._theBuilder.insert(0, aValue);
825        return this;
826    }
827
828    @Override
829    public final TextPrimitive replace(
830        final CharSequence target,
831        final CharSequence replacement )
832    {
833        final String myString = this.toString();
834        return this.setText(myString.replace(target, replacement));
835    }
836
837    @Override
838    public final TextPrimitive replace(
839        final int start,
840        final int end,
841        final String str )
842    {
843        this._theBuilder.replace(start, end, str);
844        return this;
845    }
846
847    @Override
848    public final TextPrimitive replaceAll(
849        final String regex,
850        final String replacement )
851    {
852        final String myString = this.toString();
853        return this.setText(myString.replaceAll(regex, replacement));
854    }
855
856    @Override
857    public final TextPrimitive replaceCharacter(
858        final char oldChar,
859        final char newChar )
860    {
861        final int myLength = this._theBuilder.length();
862        for (int i = 0; i < myLength; i++) {
863            final char aCharacter = this._theBuilder.charAt(i);
864            if (aCharacter == oldChar) {
865                this._theBuilder.setCharAt(i, newChar);
866            }
867        }
868        return this;
869    }
870
871    @Override
872    public final TextPrimitive replaceFirst(
873        final String regex,
874        final String replacement )
875    {
876        final String myString = this.toString();
877        return this.setText(myString.replaceFirst(regex, replacement));
878    }
879
880    @Override
881    public final TextPrimitive reverse()
882    {
883        this._theBuilder.reverse();
884        return this;
885    }
886
887    @Override
888    public final TextPrimitive setCharAt( final int index, final char ch )
889    {
890        this._theBuilder.setCharAt(index, ch);
891        return this;
892    }
893
894    @Override
895    public final TextPrimitive setLength( final int newLength )
896    {
897        this._theBuilder.setLength(newLength);
898        return this;
899    }
900
901    @Override
902    public final TextPrimitive setText( final CharSequence content )
903        throws UnsupportedOperationException,
904            IllegalArgumentException,
905            ArithmeticException,
906            NullPointerException
907    {
908        this._theBuilder.setLength(0);
909        this._theBuilder.append(content);
910        return this;
911    }
912
913    @Override
914    public final CharSequence subSequence( final int start, final int end )
915    {
916        return this._theBuilder.subSequence(start, end);
917    }
918
919    @Override
920    public final String substring( final int start )
921    {
922        return this._theBuilder.substring(start);
923    }
924
925    @Override
926    public final String substring( final int start, final int end )
927    {
928        return this._theBuilder.substring(start, end);
929    }
930
931    @Override
932    public TextPrimitive titleCase()
933    {
934        final int myLength = this.length();
935        for (int i = 0; i < myLength; i++) {
936            final char lowSurrogate = this._theBuilder.charAt(i);
937            if (Character.isHighSurrogate(lowSurrogate)) {
938                final int iNext = i + 1;
939                if (iNext < myLength) {
940                    final char highSurrogate = this._theBuilder.charAt(iNext);
941                    if (Character.isLowSurrogate(highSurrogate)) {
942                        final int cp = Character.toCodePoint(lowSurrogate,
943                            highSurrogate);
944                        final int tcp = Character.toTitleCase(cp);
945                        final char titleLowSurrogate = Character.lowSurrogate(tcp);
946                        final char titleHighSurrogate = Character.highSurrogate(tcp);
947                        this._theBuilder.setCharAt(iNext, titleLowSurrogate);
948                        this._theBuilder.setCharAt(i++, titleHighSurrogate);
949                        continue;
950                    }
951                }
952            }
953            final char tc = Character.toTitleCase(lowSurrogate);
954            this._theBuilder.setCharAt(i, tc);
955        }
956        return this;
957    }
958
959    @Override
960    public final String toString()
961    {
962        return this._theBuilder.toString();
963    }
964
965    @Override
966    public TextPrimitive upperCase()
967    {
968        final int myLength = this.length();
969        for (int i = 0; i < myLength; i++) {
970            final char lowSurrogate = this._theBuilder.charAt(i);
971            if (Character.isHighSurrogate(lowSurrogate)) {
972                final int iNext = i + 1;
973                if (iNext < myLength) {
974                    final char highSurrogate = this._theBuilder.charAt(iNext);
975                    if (Character.isLowSurrogate(highSurrogate)) {
976                        final int cp = Character.toCodePoint(lowSurrogate,
977                            highSurrogate);
978                        final int ucp = Character.toUpperCase(cp);
979                        final char upperLowSurrogate = Character.lowSurrogate(ucp);
980                        final char upperHighSurrogate = Character.highSurrogate(ucp);
981                        this._theBuilder.setCharAt(iNext, upperLowSurrogate);
982                        this._theBuilder.setCharAt(i++, upperHighSurrogate);
983                        continue;
984                    }
985                }
986            }
987            final char uc = Character.toUpperCase(lowSurrogate);
988            this._theBuilder.setCharAt(i, uc);
989        }
990        return this;
991    }
992}