< prev index next >

## src/java.base/share/classes/java/lang/AbstractStringBuilder.java

Print this page

       1 /*
       2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
       3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       4  *
       5  * This code is free software; you can redistribute it and/or modify it
       6  * under the terms of the GNU General Public License version 2 only, as
       7  * published by the Free Software Foundation.  Oracle designates this
       8  * particular file as subject to the "Classpath" exception as provided
       9  * by Oracle in the LICENSE file that accompanied this code.
      10  *
      11  * This code is distributed in the hope that it will be useful, but WITHOUT
      12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14  * version 2 for more details (a copy is included in the LICENSE file that
      15  * accompanied this code).
      16  *
      17  * You should have received a copy of the GNU General Public License version
      18  * 2 along with this work; if not, write to the Free Software Foundation,
      19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
      20  *
      21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
      22  * or visit www.oracle.com if you need additional information or have any
     568      * execution of the {@code append} method. Then the character at
     569      * index <i>k</i> in the new character sequence is equal to the character
     570      * at index <i>k</i> in the old character sequence, if <i>k</i> is less
     571      * than <i>n</i>; otherwise, it is equal to the character at index
     572      * <i>k-n</i> in the argument {@code str}.
     573      *
     574      * @param   str   a string.
     575      * @return  a reference to this object.
     576      */
     577     public AbstractStringBuilder append(String str) {
     578         if (str == null) {
     579             return appendNull();
     580         }
     581         int len = str.length();
     582         ensureCapacityInternal(count + len);
     583         putStringAt(count, str);
     584         count += len;
     585         return this;
     586     }
     587
     588     // Documentation in subclasses because of synchro difference

     589     public AbstractStringBuilder append(StringBuffer sb) {
     590         return this.append((AbstractStringBuilder)sb);
     591     }
     592
     593     /**
     594      * @since 1.8
     595      */
     596     AbstractStringBuilder append(AbstractStringBuilder asb) {
     597         if (asb == null) {
     598             return appendNull();
     599         }
     600         int len = asb.length();
     601         ensureCapacityInternal(count + len);
     602         if (getCoder() != asb.getCoder()) {
     603             inflate();
     604         }
     605         asb.getBytes(value, count, coder);
     606         count += len;
     607         return this;
     608     }
       1 /*
       2  * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
       3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       4  *
       5  * This code is free software; you can redistribute it and/or modify it
       6  * under the terms of the GNU General Public License version 2 only, as
       7  * published by the Free Software Foundation.  Oracle designates this
       8  * particular file as subject to the "Classpath" exception as provided
       9  * by Oracle in the LICENSE file that accompanied this code.
      10  *
      11  * This code is distributed in the hope that it will be useful, but WITHOUT
      12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14  * version 2 for more details (a copy is included in the LICENSE file that
      15  * accompanied this code).
      16  *
      17  * You should have received a copy of the GNU General Public License version
      18  * 2 along with this work; if not, write to the Free Software Foundation,
      19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
      20  *
      21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
      22  * or visit www.oracle.com if you need additional information or have any
     568      * execution of the {@code append} method. Then the character at
     569      * index <i>k</i> in the new character sequence is equal to the character
     570      * at index <i>k</i> in the old character sequence, if <i>k</i> is less
     571      * than <i>n</i>; otherwise, it is equal to the character at index
     572      * <i>k-n</i> in the argument {@code str}.
     573      *
     574      * @param   str   a string.
     575      * @return  a reference to this object.
     576      */
     577     public AbstractStringBuilder append(String str) {
     578         if (str == null) {
     579             return appendNull();
     580         }
     581         int len = str.length();
     582         ensureCapacityInternal(count + len);
     583         putStringAt(count, str);
     584         count += len;
     585         return this;
     586     }
     587
     588     /**
     589      * Appends the specified {@code StringBuffer} to this sequence.
     590      *
     591      * @param   sb   the {@code StringBuffer} to append.
     592      * @return  a reference to this object.
     593      */
     594     public AbstractStringBuilder append(StringBuffer sb) {
     595         return this.append((AbstractStringBuilder)sb);
     596     }
     597
     598     /**
     599      * @since 1.8
     600      */
     601     AbstractStringBuilder append(AbstractStringBuilder asb) {
     602         if (asb == null) {
     603             return appendNull();
     604         }
     605         int len = asb.length();
     606         ensureCapacityInternal(count + len);
     607         if (getCoder() != asb.getCoder()) {
     608             inflate();
     609         }
     610         asb.getBytes(value, count, coder);
     611         count += len;
     612         return this;
     613     }

< prev index next >