コード例 #1
0
ファイル: TestPrimes.java プロジェクト: siwiwit/EMFText
 /**
  * Filter non-primes
  *
  * @param numbers
  */
 private ATermList filterNonPrimes(ATermList numbers) {
   ATermList primes = factory.makeList();
   numbers = numbers.getNext();
   while (!numbers.isEmpty()) {
     ATermInt prime = (ATermInt) numbers.getFirst();
     numbers = filterMultiples(prime.getInt(), numbers);
     primes = primes.append(prime);
   }
   return factory.makeList(factory.makeInt(1), primes);
 }
コード例 #2
0
ファイル: TestPrimes.java プロジェクト: siwiwit/EMFText
  /**
   * Filter multiples of n.
   *
   * @param n
   * @param numbers
   */
  private ATermList filterMultiples(int n, ATermList numbers) {
    int nr, len = numbers.getLength();

    for (int i = 0; i < len; i++) {
      ATermInt el = (ATermInt) numbers.elementAt(i);
      nr = el.getInt();
      if (nr % n == 0) {
        len--;
        numbers = numbers.removeElementAt(i);
      }
    }
    return numbers;
  }
コード例 #3
0
ファイル: ParseTreeTools.java プロジェクト: siwiwit/EMFText
 /** Private helper for the yield method. */
 private void yieldAppl(ATermAppl appl, StringBuilder builder) {
   for (ATerm t : (ATermList) appl.getArgument(APPL_ARGS)) {
     if (t instanceof ATermAppl) {
       ATermAppl arg = (ATermAppl) t;
       if (arg.getAFun() == applFun) {
         yieldAppl(arg, builder);
       } else {
         throw new IllegalArgumentException("Don't know how to yield " + arg);
       }
     } else if (t instanceof ATermInt) {
       ATermInt arg = (ATermInt) t;
       builder.append((char) arg.getInt());
     } else {
       throw new IllegalArgumentException("Don't know how to yield " + t);
     }
   }
 }