當前位置: 首頁>>代碼示例>>Java>>正文


Java CharArrayFields類代碼示例

本文整理匯總了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;
}
 
開發者ID:grzesuav,項目名稱:gjpf-core,代碼行數:20,代碼來源:JPF_java_lang_String.java

示例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;
}
 
開發者ID:grzesuav,項目名稱:gjpf-core,代碼行數:20,代碼來源:JPF_java_lang_String.java

示例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));
}
 
開發者ID:grzesuav,項目名稱:gjpf-core,代碼行數:23,代碼來源:JPF_java_lang_String.java

示例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;
}
 
開發者ID:grzesuav,項目名稱:gjpf-core,代碼行數:36,代碼來源:JPF_java_lang_String.java

示例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;
  }
}
 
開發者ID:grzesuav,項目名稱:gjpf-core,代碼行數:40,代碼來源:JPF_java_lang_String.java

示例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);
}
 
開發者ID:grzesuav,項目名稱:gjpf-core,代碼行數:29,代碼來源:JPF_java_lang_String.java


注:本文中的gov.nasa.jpf.vm.CharArrayFields類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。