本文整理匯總了Java中gov.nasa.jpf.vm.CharArrayFields類的典型用法代碼示例。如果您正苦於以下問題:Java CharArrayFields類的具體用法?Java CharArrayFields怎麽用?Java CharArrayFields使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CharArrayFields類屬於gov.nasa.jpf.vm包,在下文中一共展示了CharArrayFields類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: indexOf__II__I
import gov.nasa.jpf.vm.CharArrayFields; //導入依賴的package包/類
@MJI
public int indexOf__II__I (MJIEnv env, int objref, int c, int fromIndex) {
int vref = env.getReferenceField(objref, "value");
ElementInfo ei = env.getElementInfo(vref);
char[] values = ((CharArrayFields) ei.getFields()).asCharArray();
int len = values.length;
if (fromIndex >= len) { return -1; }
if (fromIndex < 0) {
fromIndex = 0;
}
for (int i = fromIndex; i < len; i++) {
if (values[i] == c) { return i; }
}
return -1;
}
示例2: lastIndexOf__II__I
import gov.nasa.jpf.vm.CharArrayFields; //導入依賴的package包/類
@MJI
public int lastIndexOf__II__I (MJIEnv env, int objref, int c, int fromIndex) {
int vref = env.getReferenceField(objref, "value");
ElementInfo ei = env.getElementInfo(vref);
char[] values = ((CharArrayFields) ei.getFields()).asCharArray();
int len = values.length;
if (fromIndex < 0) { return -1; }
if (fromIndex > len - 1) {
fromIndex = len - 1;
}
for (int i = fromIndex; i > 0; i--) {
if (values[i] == c) { return i; }
}
return -1;
}
示例3: concat__Ljava_lang_String_2__Ljava_lang_String_2
import gov.nasa.jpf.vm.CharArrayFields; //導入依賴的package包/類
@MJI
public int concat__Ljava_lang_String_2__Ljava_lang_String_2 (MJIEnv env, int objRef, int strRef) {
Heap heap = env.getHeap();
ElementInfo thisStr = heap.get(objRef);
CharArrayFields thisFields = (CharArrayFields) heap.get(thisStr.getReferenceField("value")).getFields();
char[] thisChars = thisFields.asCharArray();
int thisLength = thisChars.length;
ElementInfo otherStr = heap.get(strRef);
CharArrayFields otherFields = (CharArrayFields) heap.get(otherStr.getReferenceField("value")).getFields();
char[] otherChars = otherFields.asCharArray();
int otherLength = otherChars.length;
if (otherLength == 0) { return objRef; }
char resultChars[] = new char[thisLength + otherLength];
System.arraycopy(thisChars, 0, resultChars, 0, thisLength);
System.arraycopy(otherChars, 0, resultChars, thisLength, otherLength);
return env.newString(new String(resultChars));
}
示例4: equals__Ljava_lang_Object_2__Z
import gov.nasa.jpf.vm.CharArrayFields; //導入依賴的package包/類
@MJI
public boolean equals__Ljava_lang_Object_2__Z (MJIEnv env, int objRef, int argRef) {
if (argRef == MJIEnv.NULL) {
return false;
}
Heap heap = env.getHeap();
ElementInfo s1 = heap.get(objRef);
ClassInfo ci1 = s1.getClassInfo();
ElementInfo s2 = heap.get(argRef);
ClassInfo ci2 = s2.getClassInfo();
if (!ci2.isInstanceOf(ci1)) {
return false;
}
Fields f1 = heap.get(s1.getReferenceField("value")).getFields();
Fields f2 = heap.get(s2.getReferenceField("value")).getFields();
char[] c1 = ((CharArrayFields) f1).asCharArray();
char[] c2 = ((CharArrayFields) f2).asCharArray();
if (c1.length != c2.length) {
return false;
}
for (int i = 0; i < c1.length; i++) {
if (c1[i] != c2[i]) {
return false;
}
}
return true;
}
示例5: replace__CC__Ljava_lang_String_2
import gov.nasa.jpf.vm.CharArrayFields; //導入依賴的package包/類
@MJI
public int replace__CC__Ljava_lang_String_2 (MJIEnv env, int objRef, char oldChar, char newChar) {
if (oldChar == newChar) { // nothing to replace
return objRef;
}
int vref = env.getReferenceField(objRef, "value");
ElementInfo ei = env.getModifiableElementInfo(vref);
char[] values = ((CharArrayFields) ei.getFields()).asCharArray();
int len = values.length;
char[] newValues = null;
for (int i = 0, j = 0; j < len; i++, j++) {
char c = values[i];
if (c == oldChar) {
if (newValues == null) {
newValues = new char[len];
if (j > 0) {
System.arraycopy(values, 0, newValues, 0, j);
}
}
newValues[j] = newChar;
} else {
if (newValues != null) {
newValues[j] = c;
}
}
}
if (newValues != null) {
String s = new String(newValues);
return env.newString(s);
} else { // oldChar not found, return the original string
return objRef;
}
}
示例6: trim____Ljava_lang_String_2
import gov.nasa.jpf.vm.CharArrayFields; //導入依賴的package包/類
@MJI
public int trim____Ljava_lang_String_2 (MJIEnv env, int objRef) {
Heap heap = env.getHeap();
ElementInfo thisStr = heap.get(objRef);
CharArrayFields thisFields = (CharArrayFields) heap.get(thisStr.getReferenceField("value")).getFields();
char[] thisChars = thisFields.asCharArray();
int thisLength = thisChars.length;
int start = 0;
int end = thisLength;
while ((start < end) && (thisChars[start] <= ' ')) {
start++;
}
while ((start < end) && (thisChars[end - 1] <= ' ')) {
end--;
}
if (start == 0 && end == thisLength) {
// if there was no white space, return the string itself
return objRef;
}
String result = new String(thisChars, start, end - start);
return env.newString(result);
}