⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mutablestring.java

📁 MG4J (Managing Gigabytes for Java) is a free full-text search engine for large document collections
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     */    final public MutableString append( final long l ) { return append( String.valueOf( l ) ); }    /** Appends a float to this mutable string.     *     * @param f the float to be appended.     * @return this mutable string.     */    final public MutableString append( final float f ) { return append( String.valueOf( f ) ); }    /** Appends a double to this mutable string.     *     * @param d the double to be appended.     * @return this mutable string.     */    final public MutableString append( final double d ) { return append( String.valueOf( d ) ); }    /** Appends the string representation of an object to this mutable string.     *     * @param o the object to append.     * @return  a reference to this mutable string.     */    final public MutableString append( final Object o ) {		return append( String.valueOf( o ) );    }    /** Inserts a mutable string in this mutable string, starting from index <code>index</code>.     *     * @param index position at which to insert the <code>String</code>.     * @param s the mutable string to be inserted.     * @return this mutable string.     * @throws NullPointerException if <code>s</code> is <code>null</code>     * @throws IndexOutOfBoundsException if <code>index</code>     * is negative or greater than {@link #length()}.     */    final public MutableString insert( final int index, final MutableString s ) {		final int length = length();        if  ( index > length ) throw new StringIndexOutOfBoundsException();		final int l = s.length();		if ( l == 0 ) return this;		final int newLength = length + l;		expand( newLength );		System.arraycopy( array, index, array, index + l, length - index );		System.arraycopy( s.array, 0, array, index, l );		hashLength = hashLength < 0 ? -1 : newLength;		return this;    }    /** Inserts a <code>String</code> in this mutable string, starting from index <code>index</code>.     *     * @param index position at which to insert the <code>String</code>.     * @param s the <code>String</code> to be inserted.     * @return this mutable string.     * @throws NullPointerException if <code>s</code> is <code>null</code>     * @throws IndexOutOfBoundsException if <code>index</code>     * is negative or greater than {@link #length()}.     */    final public MutableString insert( final int index, final String s ) {		final int length = length();        if  ( index > length ) throw new StringIndexOutOfBoundsException();		final int l = s.length();		if ( l == 0 ) return this;		final int newLength = length + l;		expand( newLength );		System.arraycopy( array, index, array, index + l, length - index );		s.getChars( 0, l, array, index ); 		hashLength = hashLength < 0 ? -1 : newLength;		return this;    }    /** Inserts a <code>CharSequence</code> in this mutable string, starting from index <code>index</code>.     *     * @param index position at which to insert the <code>CharSequence</code>.     * @param s the <code>CharSequence</code> to be inserted.     * @return this mutable string.     * @throws NullPointerException if <code>s</code> is <code>null</code>     * @throws IndexOutOfBoundsException if <code>index</code>     * is negative or greater than {@link #length()}.     */    final public MutableString insert( final int index, final CharSequence s ) {		final int length = length();        if  ( index > length ) throw new StringIndexOutOfBoundsException();		final int l = s.length();		if ( l == 0 ) return this;		final int newLength = length + l;		if ( newLength >= array.length ) expand( newLength );		System.arraycopy( array, index, array, index + l, length - index );		getChars( s, 0, l, array, index ); 		hashLength = hashLength < 0 ? -1 : newLength;		return this;    }    /** Inserts characters in this mutable string. All of the characters     * of the array <code>c</code> are inserted in this mutable string,     * and the first inserted character is going to have index <code>index</code>.     *     * @param index position at which to insert subarray.     * @param c the character array.     * @return this mutable string.     * @throws NullPointerException if <code>c</code> is <code>null</code>     * @throws IndexOutOfBoundsException  if <code>index</code>     * is negative or greater than {@link #length()}.     */    final public MutableString insert( final int index, final char[] c ) {		final int length = length();        if  ( index > length ) throw new StringIndexOutOfBoundsException();		final int l = c.length;		if ( l == 0 ) return this;		final int newLength = length + l;		expand( newLength );		System.arraycopy( array, index, array, index + l, length - index );		System.arraycopy( c, 0, array, index, l );		hashLength = hashLength < 0 ? -1 : newLength;		return this;    }    /** Inserts characters in this mutable string. <code>len</code> characters     * of the array <code>c</code>, with indices starting from     * <code>offset</code>, are inserted in this mutable string,     * and the first inserted character is going to have index <code>index</code>.     *     * @param index position at which to insert subarray.     * @param c the character array.     * @param offset the index of the first character of <code>c</code> to     * to be inserted.     * @param len the number of characters of <code>c</code> to     * to be inserted.     * @return this mutable string.     * @throws NullPointerException if <code>c</code> is <code>null</code>     * @throws IndexOutOfBoundsException  if <code>index</code>     * is negative or greater than {@link #length()}, or     * <code>offset</code> or <code>len</code> are negative, or     * <code>offset+len</code> is greater than     * <code>c.length</code>.     */    final public MutableString insert( final int index, final char[] c, final int offset, final int len ) {		final int length = length();        if ( index > length ) throw new StringIndexOutOfBoundsException();		if ( offset < 0 || offset + len < 0 || offset + len > c.length ) throw new StringIndexOutOfBoundsException( offset );		if ( len == 0 ) return this;		final int newLength = length + len;		expand( newLength );		System.arraycopy( array, index, array, index + len, length - index );		System.arraycopy( c, offset, array, index, len );		hashLength = hashLength < 0 ? -1 : newLength;		return this;    }    /** Inserts a boolean in this mutable string, starting from index <code>index</code>.     *     * @param index position at which to insert the <code>String</code>.     * @param b the boolean to be inserted.     * @return this mutable string.     * @throws IndexOutOfBoundsException if <code>index</code>     * is negative or greater than {@link #length()}.     */    final public MutableString insert( final int index, final boolean b ) { return insert( index, String.valueOf( b ) ); }    /** Inserts a char in this mutable string, starting from index <code>index</code>.     *     * <P>Note that this method <em>will not expand the capacity of a compact     * mutable string by more than one character</em>.  Do not call it     * lightly.     *     * @param index position at which to insert the <code>String</code>.     * @param c the char to be inserted.     * @return this mutable string.     * @throws IndexOutOfBoundsException if <code>index</code>     * is negative or greater than {@link #length()}.     */    final public MutableString insert( final int index, final char c ) { return insert( index, String.valueOf( c ) ); }    /** Inserts a double in this mutable string, starting from index <code>index</code>.     *     * @param index position at which to insert the <code>String</code>.     * @param d the double to be inserted.     * @return this mutable string.     * @throws IndexOutOfBoundsException if <code>index</code>     * is negative or greater than {@link #length()}.     */    final public MutableString insert( final int index, final double d ) { return insert( index, String.valueOf( d ) ); }    /** Inserts a float in this mutable string, starting from index <code>index</code>.     *     * @param index position at which to insert the <code>String</code>.     * @param f the float to be inserted.     * @return this mutable string.     * @throws IndexOutOfBoundsException if <code>index</code>     * is negative or greater than {@link #length()}.     */    final public MutableString insert( final int index, final float f ) { return insert( index, String.valueOf( f ) ); }    /** Inserts an int in this mutable string, starting from index <code>index</code>.     *     * @param index position at which to insert the <code>String</code>.     * @param x the int to be inserted.     * @return this mutable string.     * @throws IndexOutOfBoundsException if <code>index</code>     * is negative or greater than {@link #length()}.     */    final public MutableString insert( final int index, final int x ) { return insert( index, String.valueOf( x ) ); }    /** Inserts a long in this mutable string, starting from index <code>index</code>.     *     * @param index position at which to insert the <code>String</code>.     * @param l the long to be inserted.     * @return this mutable string.     * @throws IndexOutOfBoundsException if <code>index</code>     * is negative or greater than {@link #length()}.     */    final public MutableString insert( final int index, final long l ) { return insert( index, String.valueOf( l ) ); }    /** Inserts the string representation of an object in this mutable string, starting from index <code>index</code>.     *     * @param index position at which to insert the <code>String</code>.     * @param o the object to be inserted.     * @return this mutable string.     * @throws IndexOutOfBoundsException if <code>index</code>     * is negative or greater than {@link #length()}.     */    final public MutableString insert( final int index, final Object o ) { return insert( index, String.valueOf( o ) ); }	/** Removes the characters of this mutable string with      * indices in the range from <code>start</code> (inclusive) to <code>end</code>      * (exclusive). If <code>end</code> is greater than or equal to the length     * of this mutable string, all characters with indices greater     * than or equal to <code>start</code> are deleted.     *     * @param start The beginning index (inclusive).     * @param end The ending index (exclusive).     * @return this mutable string.     * @throws IndexOutOfBoundsException  if <code>start</code>     * is greater than {@link #length()}, or greater than <code>end</code>.     */    final public MutableString delete( final int start, int end ) {		final int length = length();		if ( end > length ) end = length;		if ( start > end ) throw new StringIndexOutOfBoundsException();        final int l = end - start;        if ( l > 0 ) {            System.arraycopy( array, start + l, array, start, length - end );			if ( hashLength < 0 ) {				setCapacity( length - l );				hashLength = -1;			}			else hashLength -= l;        }        return this;    }    /** Removes the character at the given index.     *     * <P>Note that this method <em>will reallocate the backing array of a compact     * mutable string for each character deleted</em>.  Do not call it     * lightly.     *     * @param index Index of character to remove     * @return this mutable string.     * @throws IndexOutOfBoundsException if <code>index</code>     * is negative, or greater than or equal to {@link #length()}.     */    final public MutableString deleteCharAt( final int index ) {		final int length = length();        if ( index >= length ) throw new StringIndexOutOfBoundsException();		System.arraycopy( array, index + 1, array, index, length - index - 1 );		if ( hashLength < 0 ) {			setCapacity( length - 1 );			hashLength = -1;		}		else hashLength--;        return this;    }    /** Removes all occurrences of the given character.    *    * @param c the character to remove.    * @return this mutable string.    */    final public MutableString delete( final char c ) {		final int length = length();    	final char[] a = array;    	int l = 0;		for( int i = 0; i < length; i++ ) if ( a[ i ] != c ) a[ l++ ] = a[ i ];				if ( l != length ) {			if ( hashLength < 0 ) {				hashLength = -1;				array = CharArrays.trim( array, l );			}			else hashLength = l;		}    	return this;    }        /** Removes all occurrences of the given characters.    *    * @param s the set of characters to remove.    * @return this mutable string.    */    final public MutableString delete( final CharSet s ) {		final int length = length();    	final char[] a = array;    	int l = 0;		for( int i = 0; i < length; i++ ) if ( ! s.contains( a[ i ] ) ) a[ l++ ] = a[ i ];				if ( l != length ) {			if ( hashLength < 0 ) {				hashLength = -1;				array = CharArrays.trim( array, l );			}			else hashLength = l;		}    	return this;    }        /** Removes all occurrences of the given characters.    *    * @param c an array containing the characters to remove.    * @return this mutable string.    */    final public MutableString delete( final char[] c ) {		final int n = c.length;		if ( n == 0 ) return this;		final char[] a = array;		final int length = length();		int i = length, k, bloomFilter = 0;		k = n;		while ( k-- != 0 ) bloomFilter |= 1 << ( c[ k ] & 0x1F );		       	int l = 0;       	for( i = 0; i < length; i++ ) { 			if ( ( bloomFilter & ( 1 << ( a[ i ] & 0x1F ) ) ) != 0 ) {				k = n;				while ( k-- != 0 ) if ( a[ i ] == c[ k ] ) break;				if ( k >= 0 ) continue;			}			a[ l++ ] = a[ i ];    	}				if ( l != length ) {			if ( hashLength < 0 ) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -