callgraph/src/main/java/org/netbeans/lib/callgraph/util/EightBitStrings.java
author Tim Boudreau <tboudreau@netbeans.org>
Sat, 03 Sep 2016 02:41:36 -0400
changeset 18374 04a79821e760
parent 18373 3527a32a19f0
child 18400 c87c223efe6a
permissions -rw-r--r--
Eliminate duplicates in graph files
     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * Copyright (C) 1997-2015 Oracle and/or its affiliates. All rights reserved.
     5  *
     6  * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
     7  * Other names may be trademarks of their respective owners.
     8  *
     9  * The contents of this file are subject to the terms of either the GNU
    10  * General Public License Version 2 only ("GPL") or the Common
    11  * Development and Distribution License("CDDL") (collectively, the
    12  * "License"). You may not use this file except in compliance with the
    13  * License. You can obtain a copy of the License at
    14  * http://www.netbeans.org/cddl-gplv2.html
    15  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    16  * specific language governing permissions and limitations under the
    17  * License.  When distributing the software, include this License Header
    18  * Notice in each file and include the License file at
    19  * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    20  * particular file as subject to the "Classpath" exception as provided
    21  * by Oracle in the GPL Version 2 section of the License file that
    22  * accompanied this code. If applicable, add the following below the
    23  * License Header, with the fields enclosed by brackets [] replaced by
    24  * your own identifying information:
    25  * "Portions Copyrighted [year] [name of copyright owner]"
    26  *
    27  * Contributor(s):
    28  *
    29  * The Original Software is NetBeans. The Initial Developer of the Original
    30  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
    31  * Microsystems, Inc. All Rights Reserved.
    32  *
    33  * If you wish your version of this file to be governed by only the CDDL
    34  * or only the GPL Version 2, indicate your decision by adding
    35  * "[Contributor] elects to include this software in this distribution
    36  * under the [CDDL or GPL Version 2] license." If you do not indicate a
    37  * single choice of license, a recipient has the option to distribute
    38  * your version of this file under either the CDDL, the GPL Version 2 or
    39  * to extend the choice of license to its licensees as provided above.
    40  * However, if you add GPL Version 2 code and therefore, elected the GPL
    41  * Version 2 license, then the option applies only if the new code is
    42  * made subject to such option by the copyright holder.
    43  */
    44 package org.netbeans.lib.callgraph.util;
    45 
    46 import java.io.ByteArrayOutputStream;
    47 import java.io.IOException;
    48 import java.io.UnsupportedEncodingException;
    49 import java.nio.ByteBuffer;
    50 import java.nio.charset.CharacterCodingException;
    51 import java.nio.charset.Charset;
    52 import java.util.ArrayList;
    53 import java.util.Arrays;
    54 import java.util.Collection;
    55 import java.util.Iterator;
    56 import java.util.List;
    57 import java.util.Locale;
    58 
    59 /**
    60  * byte[] backed string to cut memory consumption from Strings in half for most
    61  * codebases, to reduce memory footprint to process larger codebases by using 8
    62  * bits per character instead of 16.
    63  *
    64  * @author Tim Boudreau
    65  */
    66 public class EightBitStrings {
    67 
    68     private static final Charset UTF = Charset.forName("UTF-8");
    69 
    70     private final InternTable INTERN_TABLE = new InternTable();
    71     public final CharSequence DOT = create(".");
    72     public final CharSequence QUOTE = create("\"");
    73     public final CharSequence SPACE = create(" ");
    74     public final CharSequence QUOTE_SPACE = create("\" ");
    75     public final CharSequence CLOSE_OPEN_QUOTE = create("\" \"");
    76 
    77     private final boolean disabled;
    78     private final boolean aggressive;
    79 
    80     public EightBitStrings(boolean disabled) {
    81         this (disabled, false);
    82     }
    83 
    84     public EightBitStrings(boolean disabled, boolean aggressive) {
    85         this.disabled = disabled;
    86         this.aggressive = aggressive;
    87     }
    88     
    89     public void clear() {
    90         INTERN_TABLE.dispose();
    91     }
    92 
    93     public ComparableCharSequence create(CharSequence string) {
    94         if (disabled) {
    95             return string instanceof ComparableCharSequence ? (ComparableCharSequence) string
    96                     : new StringWrapper(string.toString());
    97         }
    98         if (aggressive) {
    99             return concat(string);
   100         }
   101         return INTERN_TABLE.intern(string);
   102     }
   103 
   104     public ComparableCharSequence concat(CharSequence... seqs) {
   105         if (seqs.length == 1 && seqs[0] instanceof ComparableCharSequence) {
   106             return (ComparableCharSequence) seqs[0];
   107         }
   108         if (disabled) {
   109             StringBuilder sb = new StringBuilder();
   110             for (CharSequence c : seqs) {
   111                 sb.append(c);
   112             }
   113             return new StringWrapper(sb.toString());
   114         } else if (aggressive) {
   115             List<CharSequence> nue = new ArrayList<>(seqs.length + (seqs.length / 2));
   116             for (CharSequence seq : seqs) {
   117                 int ln = seq.length();
   118                 StringBuilder sb = new StringBuilder();
   119                 for(int i=0; i < ln; i++) {
   120                     char c = seq.charAt(i);
   121                     if (Character.isLetter(c) || Character.isDigit(c)) {
   122                         sb.append(c);
   123                     } else {
   124                         nue.add(sb.toString());
   125                         sb = new StringBuilder();
   126                         nue.add(new String(new char[] { c }));
   127                     }
   128                 }
   129                 if (sb.length() > 0) {
   130                     nue.add(sb.toString());
   131                 }
   132             }
   133             if (nue.size() != seqs.length) {
   134                 seqs = nue.toArray(new CharSequence[nue.size()]);
   135             }
   136         }
   137         return new Concatenation(seqs);
   138     }
   139 
   140     public ComparableCharSequence concatQuoted(Collection<Object> seqs) {
   141         if (disabled) {
   142             StringBuilder sb = new StringBuilder("\"");
   143             boolean first = true;
   144             for (Iterator<Object> it = seqs.iterator(); it.hasNext();) {
   145                 Object c = it.next();
   146                 if (!first) {
   147                     sb.append(SPACE);
   148                 }
   149                 if (c instanceof CharSequence) {
   150                     sb.append(QUOTE);
   151                 }
   152                 sb.append(c);
   153                 if (c instanceof CharSequence) {
   154                     sb.append(QUOTE);
   155                 }
   156                 first = false;
   157             }
   158             return new StringWrapper(sb.toString());
   159         } else {
   160             List<CharSequence> quoted = new ArrayList<>((seqs.size() * 3) + 1);
   161             for (Iterator<Object> it = seqs.iterator(); it.hasNext();) {
   162                 Object c = it.next();
   163                 if (c instanceof CharSequence) {
   164                     quoted.add(QUOTE);
   165                     quoted.add((CharSequence)c);
   166                     if (it.hasNext()) {
   167                         quoted.add(QUOTE_SPACE);
   168                     } else {
   169                         quoted.add(QUOTE);
   170                     }
   171                 } else {
   172                     quoted.add(create(c.toString()));
   173                     quoted.add(SPACE);
   174                 }
   175             }
   176             return new Concatenation(quoted.toArray(new CharSequence[quoted.size()]));
   177         }
   178     }
   179 
   180     private static byte[] toBytes(CharSequence seq) {
   181         try {
   182             ByteArrayOutputStream out = new ByteArrayOutputStream();
   183             out.write(seq.toString().getBytes(UTF));
   184             return out.toByteArray();
   185         } catch (IOException ex) {
   186             throw new IllegalArgumentException(ex);
   187         }
   188     }
   189 
   190     private static CharSequence toCharSequence(byte[] bytes) {
   191         try {
   192             return UTF.newDecoder().decode(ByteBuffer.wrap(bytes));
   193         } catch (CharacterCodingException ex) {
   194             throw new IllegalArgumentException(ex);
   195         }
   196     }
   197 
   198     int internTableSize() {
   199         return INTERN_TABLE.last + 1;
   200     }
   201     
   202     List<CharSequence> dumpInternTable() {
   203         return INTERN_TABLE.dumpInternTable();
   204     }
   205 
   206     static class InternTable {
   207 
   208         private static final int SIZE_INCREMENT = 50;
   209 
   210         private int last = -1;
   211         private Entry[] entries = new Entry[SIZE_INCREMENT];
   212 
   213         void dispose() {
   214             entries = new Entry[SIZE_INCREMENT];
   215             last = -1;
   216         }
   217 
   218         Entry intern(CharSequence seq) {
   219             if (seq instanceof Entry) {
   220                 return (Entry) seq;
   221             }
   222             // We are using an array and binary search to conserve memory
   223             // here.  This is slower than a HashMap (we sort on insert so
   224             // we can binary search later), but involves far fewer allocations
   225             Entry entry = new Entry(toBytes(seq), (short) seq.length());
   226             int offset = last == -1 ? -1 : Arrays.binarySearch(entries, 0, last + 1, entry);
   227             if (offset > 0) {
   228                 return entries[offset];
   229             }
   230             if (last == entries.length - 1) {
   231                 Entry[] nue = new Entry[entries.length + SIZE_INCREMENT];
   232                 System.arraycopy(entries, 0, nue, 0, entries.length);
   233                 entries = nue;
   234             }
   235             entries[++last] = entry;
   236             Arrays.sort(entries, 0, last + 1);
   237             return entry;
   238         }
   239         
   240         List<CharSequence> dumpInternTable() {
   241             return Arrays.asList(entries);
   242         }
   243 
   244         private static final class Entry implements ComparableCharSequence {
   245 
   246             private final byte[] bytes;
   247             private final short length;
   248 
   249             public Entry(byte[] bytes, short length) {
   250                 if (length < 0) {
   251                     throw new Error("String too large");
   252                 }
   253                 this.bytes = bytes;
   254                 this.length = length;
   255             }
   256 
   257             public int hashCode() {
   258                 int h = 0;
   259                 if (h == 0 && bytes.length > 0) {
   260                     CharSequence val = toChars();
   261                     int max = val.length();
   262                     for (int i = 0; i < max; i++) {
   263                         h = 31 * h + val.charAt(i);
   264                     }
   265                 }
   266                 return h;
   267             }
   268 
   269             @Override
   270             public boolean equals(Object o) {
   271                 if (o == null) {
   272                     return false;
   273                 } else if (o == this) {
   274                     return true;
   275                 } else if (o instanceof Entry) {
   276                     Entry other = (Entry) o;
   277                     if (other.bytes.length < bytes.length) {
   278                         return false;
   279                     }
   280                     return Arrays.equals(bytes, other.bytes);
   281                 } else if (o instanceof CharSequence) {
   282                     return charSequencesEqual(this, (CharSequence) o);
   283                 } else {
   284                     return false;
   285                 }
   286             }
   287 
   288             public int compare(Entry o) {
   289                 if (o == this) {
   290                     return 0;
   291                 }
   292                 int max = Math.min(bytes.length, o.bytes.length);
   293                 for (int i = 0; i < max; i++) {
   294                     if (bytes[i] > o.bytes[i]) {
   295                         return 1;
   296                     } else if (bytes[i] < o.bytes[i]) {
   297                         return -1;
   298                     }
   299                 }
   300                 if (bytes.length == o.bytes.length) {
   301                     return 0;
   302                 } else if (bytes.length > o.bytes.length) {
   303                     return 1;
   304                 } else {
   305                     return -1;
   306                 }
   307             }
   308 
   309             @Override
   310             public String toString() {
   311                 return new String(bytes, UTF);
   312             }
   313 
   314             @Override
   315             public int length() {
   316                 return length;
   317             }
   318 
   319             CharSequence toChars() {
   320                 return toCharSequence(bytes);
   321             }
   322 
   323             @Override
   324             public char charAt(int index) {
   325                 return toCharSequence(bytes).charAt(index);
   326             }
   327 
   328             @Override
   329             public CharSequence subSequence(int start, int end) {
   330                 return toCharSequence(bytes).subSequence(start, end);
   331             }
   332 
   333             @Override
   334             public int compareTo(CharSequence o) {
   335                 if (o instanceof Entry) {
   336                     return compare((Entry) o);
   337                 }
   338                 return compareCharSequences(this, o);
   339             }
   340         }
   341     }
   342 
   343     static int compareCharSequences(CharSequence a, CharSequence b) {
   344         if (a == b) {
   345             return 0;
   346         }
   347         int aLength = a.length();
   348         int bLength = b.length();
   349         int max = Math.min(aLength, bLength);
   350         for (int i = 0; i < max; i++) {
   351             if (a.charAt(i) > b.charAt(i)) {
   352                 return 1;
   353             } else if (a.charAt(i) < b.charAt(i)) {
   354                 return -1;
   355             }
   356         }
   357         if (aLength == bLength) {
   358             return 0;
   359         } else if (aLength > bLength) {
   360             return 1;
   361         } else {
   362             return -1;
   363         }
   364     }
   365 
   366     static boolean debug;
   367     class Concatenation implements ComparableCharSequence, Comparable<CharSequence> {
   368 
   369         private final InternTable.Entry[] entries;
   370 
   371         Concatenation(CharSequence... entries) {
   372             List<InternTable.Entry> l = new ArrayList<>(entries.length);
   373             for (CharSequence cs : entries) {
   374                 if (cs instanceof Concatenation) {
   375                     Concatenation c1 = (Concatenation) cs;
   376                     l.addAll(Arrays.asList(c1.entries));
   377                 } else {
   378                     l.add(INTERN_TABLE.intern(cs));
   379                 }
   380             }
   381             this.entries = l.toArray(new InternTable.Entry[l.size()]);
   382         }
   383 
   384         @Override
   385         public int length() {
   386             int result = 0;
   387             for (int i = 0; i < entries.length; i++) {
   388                 result += entries[i].length;
   389             }
   390             return result;
   391         }
   392 
   393         @Override
   394         public char charAt(int index) {
   395             if (entries.length == 0) {
   396                 throw new IndexOutOfBoundsException("0 length but asked for " + index);
   397             }
   398             for (int i = 0; i < entries.length; i++) {
   399                 InternTable.Entry e = entries[i];
   400                 if (index >= e.length) {
   401                     index -= e.length;
   402                 } else {
   403                     return e.charAt(index);
   404                 }
   405             }
   406             throw new IndexOutOfBoundsException(index + " of " + length() + " in " + this + " with entries " + Arrays.asList(entries));
   407         }
   408 
   409         @Override
   410         public CharSequence subSequence(int start, int end) {
   411             return INTERN_TABLE.intern(toString().subSequence(start, end));
   412         }
   413 
   414         public String toString() {
   415             StringBuilder sb = new StringBuilder();
   416             for (InternTable.Entry e : entries) {
   417                 sb.append(e);
   418             }
   419             if (debug) {
   420                 sb.append(" - ").append (Arrays.asList(entries));
   421             }
   422             return sb.toString();
   423         }
   424 
   425         private int hash = 0;
   426 
   427         public int hashCode() {
   428             int h = hash;
   429             if (h == 0 && length() > 0) {
   430                 for (InternTable.Entry e : entries) {
   431                     CharSequence chars = e.toChars();
   432                     int max = chars.length();
   433                     for (int i = 0; i < max; i++) {
   434                         h = 31 * h + chars.charAt(i);
   435                     }
   436                 }
   437                 hash = h;
   438             }
   439             return h;
   440         }
   441 
   442         public boolean equals(Object o) {
   443             if (true) {
   444                 if (o instanceof CharSequence) {
   445                     return charSequencesEqual(this, (CharSequence) o);
   446                 }
   447             }
   448             if (o == this) {
   449                 return true;
   450             } else if (o == null) {
   451                 return false;
   452             } else if (o instanceof Concatenation) {
   453                 Concatenation c = (Concatenation) o;
   454                 if (c.entries.length != entries.length) {
   455                     return charSequencesEqual(this, c);
   456                 }
   457                 for (int i = 0; i < entries.length; i++) {
   458                     if (entries[i].length() != entries[i].length) {
   459                         return charSequencesEqual(this, c);
   460                     }
   461                     if (!entries[i].equals(c.entries[i])) {
   462                         return false;
   463                     }
   464                 }
   465                 return true;
   466             } else if (o instanceof CharSequence) {
   467                 return charSequencesEqual(this, (CharSequence) o);
   468             } else {
   469                 return false;
   470             }
   471         }
   472 
   473         @Override
   474         public int compareTo(CharSequence o) {
   475             return compareCharSequences(this, o);
   476         }
   477     }
   478 
   479     private static boolean charSequencesEqual(CharSequence a, CharSequence b) {
   480         int maxA = a.length();
   481         int maxB = b.length();
   482         if (maxA != maxB) {
   483             return false;
   484         }
   485         for (int i = 0; i < maxA; i++) {
   486             char aa = a.charAt(i);
   487             char bb = b.charAt(i);
   488             if (aa != bb) {
   489                 return false;
   490             }
   491         }
   492         return true;
   493     }
   494 
   495     static class StringWrapper implements ComparableCharSequence {
   496 
   497         private final String s;
   498 
   499         public StringWrapper(String s) {
   500             this.s = s;
   501         }
   502 
   503         public int length() {
   504             return s.length();
   505         }
   506 
   507         public boolean isEmpty() {
   508             return s.isEmpty();
   509         }
   510 
   511         public char charAt(int index) {
   512             return s.charAt(index);
   513         }
   514 
   515         public int codePointAt(int index) {
   516             return s.codePointAt(index);
   517         }
   518 
   519         public int codePointBefore(int index) {
   520             return s.codePointBefore(index);
   521         }
   522 
   523         public int codePointCount(int beginIndex, int endIndex) {
   524             return s.codePointCount(beginIndex, endIndex);
   525         }
   526 
   527         public int offsetByCodePoints(int index, int codePointOffset) {
   528             return s.offsetByCodePoints(index, codePointOffset);
   529         }
   530 
   531         public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) {
   532             s.getChars(srcBegin, srcEnd, dst, dstBegin);
   533         }
   534 
   535         public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin) {
   536             s.getBytes(srcBegin, srcEnd, dst, dstBegin);
   537         }
   538 
   539         public byte[] getBytes(String charsetName) throws UnsupportedEncodingException {
   540             return s.getBytes(charsetName);
   541         }
   542 
   543         public byte[] getBytes(Charset charset) {
   544             return s.getBytes(charset);
   545         }
   546 
   547         public byte[] getBytes() {
   548             return s.getBytes();
   549         }
   550 
   551         public boolean equals(Object anObject) {
   552             if (anObject == this) {
   553                 return true;
   554             }
   555             if (anObject == null) {
   556                 return false;
   557             }
   558             if (!(anObject instanceof CharSequence)) {
   559                 return false;
   560             }
   561             return charSequencesEqual(this, (CharSequence) anObject);
   562         }
   563 
   564         public boolean contentEquals(StringBuffer sb) {
   565             return s.contentEquals(sb);
   566         }
   567 
   568         public boolean contentEquals(CharSequence cs) {
   569             return s.contentEquals(cs);
   570         }
   571 
   572         public boolean equalsIgnoreCase(String anotherString) {
   573             return s.equalsIgnoreCase(anotherString);
   574         }
   575 
   576         public int compareTo(CharSequence anotherString) {
   577             return compareCharSequences(this, anotherString);
   578         }
   579 
   580         public int compareToIgnoreCase(String str) {
   581             return s.compareToIgnoreCase(str);
   582         }
   583 
   584         public boolean regionMatches(int toffset, String other, int ooffset, int len) {
   585             return s.regionMatches(toffset, other, ooffset, len);
   586         }
   587 
   588         public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len) {
   589             return s.regionMatches(ignoreCase, toffset, other, ooffset, len);
   590         }
   591 
   592         public boolean startsWith(String prefix, int toffset) {
   593             return s.startsWith(prefix, toffset);
   594         }
   595 
   596         public boolean startsWith(String prefix) {
   597             return s.startsWith(prefix);
   598         }
   599 
   600         public boolean endsWith(String suffix) {
   601             return s.endsWith(suffix);
   602         }
   603 
   604         @Override
   605         public int hashCode() {
   606             return s.hashCode();
   607         }
   608 
   609         public int indexOf(int ch) {
   610             return s.indexOf(ch);
   611         }
   612 
   613         public int indexOf(int ch, int fromIndex) {
   614             return s.indexOf(ch, fromIndex);
   615         }
   616 
   617         public int lastIndexOf(int ch) {
   618             return s.lastIndexOf(ch);
   619         }
   620 
   621         public int lastIndexOf(int ch, int fromIndex) {
   622             return s.lastIndexOf(ch, fromIndex);
   623         }
   624 
   625         public int indexOf(String str) {
   626             return s.indexOf(str);
   627         }
   628 
   629         public int indexOf(String str, int fromIndex) {
   630             return s.indexOf(str, fromIndex);
   631         }
   632 
   633         public int lastIndexOf(String str) {
   634             return s.lastIndexOf(str);
   635         }
   636 
   637         public int lastIndexOf(String str, int fromIndex) {
   638             return s.lastIndexOf(str, fromIndex);
   639         }
   640 
   641         public String substring(int beginIndex) {
   642             return s.substring(beginIndex);
   643         }
   644 
   645         public String substring(int beginIndex, int endIndex) {
   646             return s.substring(beginIndex, endIndex);
   647         }
   648 
   649         public CharSequence subSequence(int beginIndex, int endIndex) {
   650             return s.subSequence(beginIndex, endIndex);
   651         }
   652 
   653         public String concat(String str) {
   654             return s.concat(str);
   655         }
   656 
   657         public String replace(char oldChar, char newChar) {
   658             return s.replace(oldChar, newChar);
   659         }
   660 
   661         public boolean matches(String regex) {
   662             return s.matches(regex);
   663         }
   664 
   665         public boolean contains(CharSequence s) {
   666             return this.s.contains(s);
   667         }
   668 
   669         public String replaceFirst(String regex, String replacement) {
   670             return s.replaceFirst(regex, replacement);
   671         }
   672 
   673         public String replaceAll(String regex, String replacement) {
   674             return s.replaceAll(regex, replacement);
   675         }
   676 
   677         public String replace(CharSequence target, CharSequence replacement) {
   678             return s.replace(target, replacement);
   679         }
   680 
   681         public String[] split(String regex, int limit) {
   682             return s.split(regex, limit);
   683         }
   684 
   685         public String[] split(String regex) {
   686             return s.split(regex);
   687         }
   688 
   689         public static String join(CharSequence delimiter, CharSequence... elements) {
   690             return String.join(delimiter, elements);
   691         }
   692 
   693         public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements) {
   694             return String.join(delimiter, elements);
   695         }
   696 
   697         public String toLowerCase(Locale locale) {
   698             return s.toLowerCase(locale);
   699         }
   700 
   701         public String toLowerCase() {
   702             return s.toLowerCase();
   703         }
   704 
   705         public String toUpperCase(Locale locale) {
   706             return s.toUpperCase(locale);
   707         }
   708 
   709         public String toUpperCase() {
   710             return s.toUpperCase();
   711         }
   712 
   713         public String trim() {
   714             return s.trim();
   715         }
   716 
   717         public String toString() {
   718             return s.toString();
   719         }
   720 
   721         public char[] toCharArray() {
   722             return s.toCharArray();
   723         }
   724 
   725         public static String format(String format, Object... args) {
   726             return String.format(format, args);
   727         }
   728 
   729         public static String format(Locale l, String format, Object... args) {
   730             return String.format(l, format, args);
   731         }
   732 
   733         public static String valueOf(Object obj) {
   734             return String.valueOf(obj);
   735         }
   736 
   737         public static String valueOf(char[] data) {
   738             return String.valueOf(data);
   739         }
   740 
   741         public static String valueOf(char[] data, int offset, int count) {
   742             return String.valueOf(data, offset, count);
   743         }
   744 
   745         public static String copyValueOf(char[] data, int offset, int count) {
   746             return String.copyValueOf(data, offset, count);
   747         }
   748 
   749         public static String copyValueOf(char[] data) {
   750             return String.copyValueOf(data);
   751         }
   752 
   753         public static String valueOf(boolean b) {
   754             return String.valueOf(b);
   755         }
   756 
   757         public static String valueOf(char c) {
   758             return String.valueOf(c);
   759         }
   760 
   761         public static String valueOf(int i) {
   762             return String.valueOf(i);
   763         }
   764 
   765         public static String valueOf(long l) {
   766             return String.valueOf(l);
   767         }
   768 
   769         public static String valueOf(float f) {
   770             return String.valueOf(f);
   771         }
   772 
   773         public static String valueOf(double d) {
   774             return String.valueOf(d);
   775         }
   776 
   777         public String intern() {
   778             return s.intern();
   779         }
   780 
   781     }
   782 }