Class Primes

java.lang.Object
it.unimi.di.prog2.h14.Primes
All Implemented Interfaces:
Iterator<Integer>

public class Primes extends Object implements Iterator<Integer>
Iteratore che genera i numeri primi.
  • Field Details

    • candidate

      private int candidate
      Il prossimo potenziale numero primo.
    • foundPrimes

      private final List<Integer> foundPrimes
      L'elenco di primi restiuiti da next.
  • Constructor Details

    • Primes

      public Primes()
  • Method Details

    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<Integer>
    • isDivisibleByAFoundPrime

      private boolean isDivisibleByAFoundPrime(int n)
      Verifica se n è divisibile per un dei primi in foundPrimes.
      Parameters:
      n - il numero da verificare.
      Returns:
      true se n è divisibile per un dei primi già trovati.
    • next

      public Integer next()
      Specified by:
      next in interface Iterator<Integer>