AbstractStringBuilder抽象类

java.lang.AbstractStringBuilder分析摘要:
<1>offsetByCodePoints(int index, int codePointOffset)
<2>getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
<3>setCharAt(int index, char ch)方法
<4>append重载方法

1.offsetByCodePoints(int index, int codePointOffset)
 该方法是用于获取某个Unicode解码值在字符缓存区的下标位置。

public int offsetByCodePontes(int index, int codePointOffset){
if(index<0 || index >count){
throw new IndexOutOfBoundsException();
}
return Character.offsetByCodePointsImpl(value, 0,
count, index, codePointOffset);
}
1
2
3
4
5
6
7
这个方法是的属性有:public公有的。
参数:index
参数说明:从某个位置开始查找
参数:codePointOffset
参数说明:Unideco值,用于查找对应的解码值。
返回值:intl类型
返回值说明:Unicode解码值,查找对应的编码在字符中的位置。

 该方法的主要作用是:返回指定位置的char字符的前一位字符的Unixode的解码值。
 
2. getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
 该方法的作用是将字符缓存区的字符复制到一个数组中dst中。

public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin){
if(srcBegin < 0){
throw new StringIndexOutOfBoundsException(srcBegin);
}
if((srcEnd<0) || (srcEnd>count)){
throw new StringIndexOutOfBoundsException(srcEnd);
}
if(srcBegin > srcEnd){
throw new StirngIndexOutOfBoundsException("srcBegin > srcEnd");
}
System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd-srcBegin);
}
1
2
3
4
5
6
7
8
9
10
11
12
这个方法是的属性有:public公有。
参数:srcBegin
参数说明:要复制的开始位置(基于this而言)
参数:srcEnd
参数说明:复制的结束位置(基于this而言)
参数:dst
参数说明:char数组,将this字符复制后存放的数组。
参数:dstBegin
参数说明:dst数组存放this的复制字符,其存在的开始位置。
异常:StringIndexOfBoundsException
异常说明:如果传入的下标位置不合法,就会抛出该异常。
返回值:int
返回值说明:返回给定坐标之间的的字符串的Unicode解码数量。


 

3.setCharAt(int index, char ch)方法
  该方法的作用是设置字符串缓存区的字符,将制定的位置的字符替换新字符。

public void setCharAt(int index, char ch){
if((index<0)||(index>=count)){
throw new StringIndexOutOfBoundsException(index);
}
value[index] = ch;
}
1
2
3
4
5
6
这个方法是的属性有:public公有。
参数:index
参数说明:int类型,替换的下标位置
参数:ch
参数说明:char类型,将制定位置替换成该字符。
异常:StringIndexOfBoundsException
异常说明:如果输入的实参index下标位置不存在,则抛出此异常。

 该方法的主要作用是:该方法的作用是设置字符串缓存区的字符,将制定的位置的字符替换新字符。
 

4. append重载方法
 该方法的作用是在字符缓存后面添加内容,这也是这个抽象类中最重要的方法之一。

public AbstractStringBuilder append(Object obj){
return append(String.valueOf(obj));
}

public AbstractStringBuilder append(String str){
if(str == null){
return appendNull();
}
int len = str.length();
ensureCapacityInternal(count+length);
str.getChars(0, len, value, count);
count += len;
return this;
}

public AbstractStringBuilder append(StringBuffer sb){
if(sb == null){
return appendNull();
}
int len = sb.length();
ensureCapacityInternal(count+len);
sb.getChars(0, len, value, count);
count += len;
return this;
}

AbstractStringBuilder append(AbstractStringBuilder asb){
if(asb == null){
return appendNull();
}
int len = asb.length();
ensureCapacityInternal(count+len);
asb.getChar(0, len, value, count);
count += len;
return this;
}

public AbstractStringBuilder append(CharSequence s){
if(s == null){
return appendNull();
}
if(s instanceof String){
return this.append((String)s);
}
if(s instanceof AbstractStringBuilder){
return this.append((AbstractStringBuilder)s);
}
return this.append(s, 0, s.length());
}

public AbstractStringBuilder append(CharSequence s, int start, int end){
if(s == null){
s = "null";
}
if((start<0)||(start>end)||(end>s.length())){
throw new IndexOutOfBoundsException("start"+start+",end"
+end+",s.length()"+s.length());
}
int len = end - start;
ensureCapacityInternal(count+len);
for(int i=start,j=count; i<end; i++,j++){
value[j] = s.charAt(i);
}
count += len;
return this;
}

public AbstractStringBuilder append(char[] str){
int len = str.length;
ensureCapacityInternal(count+len);
System.arraycopy(str, 0, value, count, len);
count += len;
return this;
}

public AbstractStringBuilder append(boolean b){
if(b){
ensureCapacityInternal(count+4);
value[count++] = 't';
value[count++] = 'u';
value[count++] = 'r';
value[count++] = 'e';
}else{
ensureCapacityInternal(count+5);
value[count++] = 'f';
value[count++] = 'a';
value[count++] = 'l';
value[count++] = 's';
value[count++] = 'e';
}
return this;
}

public AbstractStringBuilder apeend(char c){
ensureCapacityInternal(count+1);
value[count++] = c;
return this;
}

public AbstractStringBuilder append(int i){
if(i == Integer.MIN_VALUE){
append("-2147483648");
return this;
}
int appendLength = (i<0)?Integer.StringSize(-i)+1
: Integer.StringSize(i);
int spaceNeeded = count + appendLength;
ensureCapacityInternal(spaceNeeded);
Integer.gerChars(i,spaceNeed,value);
count = spaceNeeded;
return this;
}

public AbstractStringBuilder append(long l){
if(l == Long.MIN_VALUE){
append("-9223372036854775808");
return this;
}
int appendedLength = (l<0)?Long.stringSize(-l)+1
: Long.stringSize(l);
int spaceNeeded = count + appendLength;
ensureCapacityInternal(spaceNeeded);
Long.getChars(l,spaceNeeded,value);
count = spaceNeeded;
return this;
}

public AbstractStringBuilder append(float f){
FloatingDecimal.appendTo(f,this);
return this;
}

public AbstractStringBuilder append(double d){
FloatingDecimal.append(d,this);
return this;
}

//appendNull方法,因为是私有的,所以不外加说明
//其功能就是在this对象后加"null"字符
private AbstractStringBuilder appendNull(){
int c = count;
ensureCapacityInternal(c+4);
value[c++] = 'n';
value[c++] = 'u';
value[c++] = 'l';
value[c++] = 'l';
count = c ;

www.cnblogs.com/sflhw/articles/12962624.html
www.cnblogs.com/sflhw/articles/12962610.html
www.cnblogs.com/sflhw/articles/12962597.html
www.cnblogs.com/sflhw/articles/12962584.html
www.cnblogs.com/sflhw/articles/12962571.html
www.cnblogs.com/sflhw/articles/12962559.html
www.cnblogs.com/sflhw/articles/12962551.html
www.cnblogs.com/sflhw/articles/12962543.html
www.cnblogs.com/sflhw/articles/12962538.html
www.cnblogs.com/sflhw/articles/12962534.html
www.cnblogs.com/sflhw/articles/12962734.html
www.cnblogs.com/sflhw/articles/12962729.html
www.cnblogs.com/sflhw/articles/12962717.html
www.cnblogs.com/sflhw/articles/12962704.html
www.cnblogs.com/sflhw/articles/12962691.html
www.cnblogs.com/sflhw/articles/12962683.html
www.cnblogs.com/sflhw/articles/12962670.html
www.cnblogs.com/sflhw/articles/12962658.html
www.cnblogs.com/sflhw/articles/12962647.html
www.cnblogs.com/sflhw/articles/12962637.html
www.cnblogs.com/sflhw/articles/12962818.html
www.cnblogs.com/sflhw/articles/12962805.html
www.cnblogs.com/sflhw/articles/12962792.html
www.cnblogs.com/sflhw/articles/12962784.html
www.cnblogs.com/sflhw/articles/12962772.html
www.cnblogs.com/sflhw/articles/12962763.html
www.cnblogs.com/sflhw/articles/12962754.html
www.cnblogs.com/sflhw/articles/12962749.html
www.cnblogs.com/sflhw/articles/12962744.html
www.cnblogs.com/sflhw/articles/12962739.html
www.cnblogs.com/cutman/articles/12962618.html
www.cnblogs.com/cutman/articles/12962609.html
www.cnblogs.com/cutman/articles/12962596.html
www.cnblogs.com/cutman/articles/12962583.html
www.cnblogs.com/cutman/articles/12962569.html
www.cnblogs.com/cutman/articles/12962558.html
www.cnblogs.com/cutman/articles/12962549.html
www.cnblogs.com/cutman/articles/12962541.html
www.cnblogs.com/cutman/articles/12962536.html
www.cnblogs.com/cutman/articles/12962532.html
www.cnblogs.com/cutman/articles/12962732.html
www.cnblogs.com/cutman/articles/12962724.html
www.cnblogs.com/cutman/articles/12962716.html
www.cnblogs.com/cutman/articles/12962703.html
www.cnblogs.com/cutman/articles/12962690.html
www.cnblogs.com/cutman/articles/12962677.html
www.cnblogs.com/cutman/articles/12962665.html
www.cnblogs.com/cutman/articles/12962657.html
www.cnblogs.com/cutman/articles/12962644.html
www.cnblogs.com/cutman/articles/12962631.html
www.cnblogs.com/cutman/articles/12962813.html
www.cnblogs.com/cutman/articles/12962806.html
www.cnblogs.com/cutman/articles/12962794.html
www.cnblogs.com/cutman/articles/12962786.html
www.cnblogs.com/cutman/articles/12962773.html
www.cnblogs.com/cutman/articles/12962760.html
www.cnblogs.com/cutman/articles/12962752.html
www.cnblogs.com/cutman/articles/12962747.html
www.cnblogs.com/cutman/articles/12962743.html
www.cnblogs.com/cutman/articles/12962738.html
www.cnblogs.com/wxy8/p/12962604.html
www.cnblogs.com/wxy8/p/12962591.html
www.cnblogs.com/wxy8/p/12962578.html
www.cnblogs.com/wxy8/p/12962570.html
www.cnblogs.com/wxy8/p/12962557.html
www.cnblogs.com/wxy8/p/12962550.html
www.cnblogs.com/wxy8/p/12962542.html
www.cnblogs.com/wxy8/p/12962539.html
www.cnblogs.com/wxy8/p/12962535.html
www.cnblogs.com/wxy8/p/12962531.html
www.cnblogs.com/wxy8/p/12962723.html
www.cnblogs.com/wxy8/p/12962710.html
www.cnblogs.com/wxy8/p/12962702.html
www.cnblogs.com/wxy8/p/12962689.html
www.cnblogs.com/wxy8/p/12962678.html
www.cnblogs.com/wxy8/p/12962664.html
www.cnblogs.com/wxy8/p/12962656.html
www.cnblogs.com/wxy8/p/12962638.html
www.cnblogs.com/wxy8/p/12962630.html
www.cnblogs.com/wxy8/p/12962617.html
www.cnblogs.com/wxy8/p/12962812.html
www.cnblogs.com/wxy8/p/12962804.html
www.cnblogs.com/wxy8/p/12962779.html
www.cnblogs.com/wxy8/p/12962766.html
www.cnblogs.com/wxy8/p/12962759.html
www.cnblogs.com/wxy8/p/12962751.html
www.cnblogs.com/wxy8/p/12962746.html
www.cnblogs.com/wxy8/p/12962742.html
www.cnblogs.com/wxy8/p/12962737.html
www.cnblogs.com/wxy8/p/12962731.html
www.cnblogs.com/lucongrui/articles/12962811.html
www.cnblogs.com/lucongrui/articles/12962799.html
www.cnblogs.com/lucongrui/articles/12962793.html
www.cnblogs.com/lucongrui/articles/12962785.html
www.cnblogs.com/lucongrui/articles/12962771.html
www.cnblogs.com/lucongrui/articles/12962753.html
www.cnblogs.com/lucongrui/articles/12962748.html
www.cnblogs.com/lucongrui/articles/12962745.html
www.cnblogs.com/lucongrui/articles/12962740.html
www.cnblogs.com/lucongrui/articles/12962730.html
www.cnblogs.com/lucongrui/articles/12962722.html
www.cnblogs.com/lucongrui/articles/12962709.html
www.cnblogs.com/lucongrui/articles/12962700.html
www.cnblogs.com/lucongrui/articles/12962688.html
www.cnblogs.com/lucongrui/articles/12962676.html
www.cnblogs.com/lucongrui/articles/12962663.html
www.cnblogs.com/lucongrui/articles/12962650.html
www.cnblogs.com/lucongrui/articles/12962643.html
www.cnblogs.com/lucongrui/articles/12962632.html
www.cnblogs.com/lucongrui/articles/12962625.html
www.cnblogs.com/lucongrui/articles/12962611.html
www.cnblogs.com/lucongrui/articles/12962603.html
www.cnblogs.com/lucongrui/articles/12962590.html
www.cnblogs.com/lucongrui/articles/12962577.html
www.cnblogs.com/lucongrui/articles/12962564.html
www.cnblogs.com/lucongrui/articles/12962552.html
www.cnblogs.com/lucongrui/articles/12962544.html

猜你喜欢

转载自www.cnblogs.com/lucongrui/p/12963058.html