Beispiel #1
0
 /**
  * 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);
 }
Beispiel #2
0
  /**
   * 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;
  }
Beispiel #3
0
 /** 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);
     }
   }
 }