Пример #1
0
 /** element of content named name */
 public Term element(String name) {
   try {
     for (Term t : iContent) {
       if (t.getText() != null && t.getText().equals(name)) return t;
     }
     return null;
   } catch (Exception e) {
     return null;
   }
 }
Пример #2
0
 /** index of element of content named name */
 public int indexOf(String name) {
   try {
     int idx = 0;
     for (Term t : iContent) {
       if (t.getText() != null && t.getText().equals(name)) return idx;
       idx++;
     }
     return -1;
   } catch (Exception e) {
     return -1;
   }
 }
Пример #3
0
 /** return content as int array */
 public int[] toIntArray() {
   // System.err.println("ToIntArray: "+this);
   if (iContent.size() == 1 && iContent.get(0).toString().length() == 0) return new int[] {};
   int[] ret = new int[iContent.size()];
   for (int i = 0; i < ret.length; i++) {
     Term t = elementAt(i);
     ret[i] =
         (t.getText().length() > 0 ? Integer.parseInt(t.getText()) : t.elementAt(0).toInt());
     // System.err.println("  "+i+" .. "+ret[i]);
   }
   return ret;
 }
Пример #4
0
 /** Reads a prolog file. It returns a set of terms */
 public static List<Term> readTermsFromStream(java.io.InputStream is, String term)
     throws java.io.IOException {
   BufferedReader br = new BufferedReader(new InputStreamReader(is));
   List<Term> ret = new ArrayList<Term>();
   // int x=0;
   while (br.ready()) {
     Term t = readTerm(new SpecialReader(br));
     // System.out.println(t);
     // x++;
     // if (x>10) break;
     if (t != null && t.getText() != null && t.getText().startsWith(term)) {
       ret.add(t);
     }
     br.readLine();
   }
   br.close();
   return ret;
 }
Пример #5
0
 /** return content as string array */
 public String[] toStringArray() {
   if (iContent.size() == 1 && iContent.get(0).toString().length() == 0) return new String[] {};
   String[] ret = new String[iContent.size()];
   for (int i = 0; i < ret.length; i++) {
     Term t = elementAt(i);
     ret[i] = (t.getText().length() > 0 ? t.toString() : t.elementAt(0).toString());
   }
   return ret;
 }