📄 block.java
字号:
package ranab.tpl;
/**
* Template block representation class.
* Here block means all the data between '{' and '}'
* - excluding both first '{' and last '}'.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
class
Block {
final int miStart;
final int miLength;
final byte[] mbyArray;
/**
* Constructors
*/
Block(byte[] by) {
miStart = 0;
miLength = by.length;
mbyArray = by;
}
Block(byte[] by, int start, int length) {
miStart = start;
miLength = length;
mbyArray = by;
}
/**
* Next index from where processing should start.
* It assumes a '}' at the end of each block.
*/
int nextIndex() {
return miStart + miLength + 1;
}
/**
* Get subblock.
*/
byte[] getBlock() {
byte[] block = new byte[miLength];
for (int i=0; i<miLength; i++)
block[i] = mbyArray[i + miStart];
return block;
}
/**
* Compare the block with a <code>byte[]</code>
*/
boolean equals(String str) {
// compare size
if (str.length() != miLength)
return false;
// now compare value
boolean bEqual = true;
for (int i=0; i<miLength; i++) {
if (str.charAt(i) != mbyArray[miStart+i]) {
bEqual = false;
break;
}
}
return bEqual;
}
/**
* Compare the block with a <code>byte[]</code>
*/
boolean equals(byte[] by) {
// compare size
if (by.length != miLength)
return false;
// now compare value
boolean bEqual = true;
for (int i=0; i<miLength; i++) {
if (by[i] != mbyArray[miStart+i]) {
bEqual = false;
break;
}
}
return bEqual;
}
/**
* String representation of this block
*/
public String toString() {
return new String(mbyArray, miStart, miLength);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -