java.lang.Object de.luschny.math.primes.PrimeSieve.PrimeCollection
private static class PrimeSieve.PrimeCollection
PrimeCollection.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface de.luschny.math.primes.IPrimeCollection |
---|
IPrimeCollection.PrintOption |
Field Summary | |
---|---|
private
int |
current
|
private
int |
end
|
private
PositiveRange |
primeRange
|
private
PrimeSieve |
sieve
|
private
PositiveRange |
sieveRange
|
private
int |
start
|
private
java.util.concurrent.atomic.AtomicInteger |
state
|
Constructor Summary | |
---|---|
PrimeSieve.PrimeCollection(PrimeSieve
sieve) Constructs the collection for the passed sieve. |
|
PrimeSieve.PrimeCollection(PrimeSieve
sieve,
PositiveRange
sieveRange) Constructs a collection over a subrange of the range of the sieve. |
Method Summary | |
---|---|
int |
getNumberOfPrimes()
Computes the number of primes in the collection. |
double |
getPrimeDensity()
Computes the density of primes in the collection. |
PositiveRange |
getPrimeRange()
Gives the range of the indices of the prime numbers in the collection. |
PositiveRange |
getSieveRange()
Gives the interval [a,b] of the sieve. |
boolean |
hasNext()
Checks the current status of the finite collection. |
(package
private) static int |
indexOf(int[] data, int value, int low, int high) Identifies the index of a prime number. |
java.util.Iterator<java.lang.Integer> |
iterator()
Provides an iterator over the current prime number collection. |
java.lang.Integer |
next()
Returns The next prime number in the collection. |
de.luschny.math.arithmetic.Xint |
primorial()
Computes the product of all primes in the range of this collection. |
void |
remove()
The (optional operation) to remove from the underlying collection the last element returned by the iterator is not supported. |
int[] |
toArray()
Gives the prime numbers in the collection as an array. |
void |
toFile(java.lang.String fileName,
IPrimeCollection.PrintOption format) Writes the primes collection to a file. |
private
void |
writeComma(java.io.PrintWriter file) Prints the list of primes in a comma separated format to a file. |
private
void |
writeFormatted(java.io.PrintWriter file) Prints the list of prime numbers in a formatted way to a file. |
private
void |
writeXml(java.io.PrintWriter file) Prints the list of prime numbers in XML format to a file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll,
toString, wait, wait, wait |
Field Detail |
---|
private int current
private final int end
private final PositiveRange primeRange
private final PrimeSieve sieve
private final PositiveRange sieveRange
private final int start
private final java.util.concurrent.atomic.AtomicInteger state
Constructor Detail |
---|
PrimeSieve.PrimeCollection(PrimeSieve sieve)
sieve
- The sieve which is to be enumerated.PrimeSieve.PrimeCollection(PrimeSieve sieve, PositiveRange sieveRange)
sieve
- Prime number sieve to be used.sieveRange
- Range of collection.Method Detail |
---|
public int getNumberOfPrimes()
getNumberOfPrimes
in interface
IPrimeCollection
public double getPrimeDensity()
getPrimeDensity
in interface
IPrimeCollection
public PositiveRange getPrimeRange()
getPrimeRange
in interface
IPrimeCollection
public PositiveRange getSieveRange()
getSieveRange
in interface
IPrimeCollection
IPrimeCollection.getPrimeRange()
public boolean hasNext()
hasNext
in interface java.util.Iterator<java.lang.Integer>
static final int indexOf(int[] data, int value, int low, int high)
data
- List of prime numbers.value
- The prime number given.low
- Lower bound for the index.high
- Upper bound for the index. public java.util.Iterator<java.lang.Integer> iterator()
iterator
in interface java.lang.Iterable<java.lang.Integer>
public java.lang.Integer next()
next
in interface java.util.Iterator<java.lang.Integer>
public de.luschny.math.arithmetic.Xint primorial()
public void remove()
remove
in interface java.util.Iterator<java.lang.Integer>
java.lang.UnsupportedOperationException
public int[] toArray()
toArray
in
interface
IPrimeCollection
public void toFile(java.lang.String fileName, IPrimeCollection.PrintOption format) throws java.io.IOException
toFile
in interface
IPrimeCollection
fileName
- Name of the file to write to.format
- The print-format requested. java.io.IOException
private void writeComma(java.io.PrintWriter file)
file
- The file to be printed to.private void writeFormatted(java.io.PrintWriter file)
file
- The file to be printed to.private void writeXml(java.io.PrintWriter file)
file
- The file to be printed to.