mirror of
https://bitbucket.org/Mattrixwv/javaclasses.git
synced 2025-12-06 23:13:57 -05:00
31 lines
2.0 KiB
Markdown
31 lines
2.0 KiB
Markdown
# JavaClasses
|
|
This is a set of classes and functions, not part of the standard library, that I have found it helpful to keep around.
|
|
|
|
#Stopwatch
|
|
This is a class that allows you to determine the execution time of an algorithm.
|
|
You can get specific resolutions of time through their own get functions, all of which return double.
|
|
However I have built it a function, getStr(), that automatically chooses the best resolution and returns both the number and resolution as a string.
|
|
This is used extensively in my ProjectEuler code found at https://bitbucket.org/Mattrixwv/ProjectEuler
|
|
Example of usage:
|
|
Stopwatch timer = new Stopwatch();
|
|
timer.start();
|
|
//Code to time here
|
|
timer.stop();
|
|
System.out.printf("It took %s to run this algorithm", timer.getStr());
|
|
//You could also do something like this if you prefered
|
|
System.out.printf("It took %f milliseconds to run this algorithm", timer.getMilli());
|
|
|
|
#Algorithms
|
|
This is a class that contains many different algorithms that I have found it useful to keep around.
|
|
All algorithms are overloaded to allow for using both Integer and BigInteger types.
|
|
Examples of usage:
|
|
primes = getPrimes(topNum); //primes now holds all primes less than or equal to topNum
|
|
primes = getNumPrimes(numPrimes); //primes now holds an ArrayList containing the first numPrimes prime numbers
|
|
factors = getFactors(number); //factors now holds an ArrayList containing the factors of number
|
|
divisors = getDivisors(number); //divisors now holds an ArrayList containing all the divisors of number
|
|
fib = getFib(number); //fib now holds the number element in the fibonacci sequence
|
|
fib = getAllFib(highestNumber); //fib now holds an ArrayList containing all fibonacci numbers less than or equal to highestNumber
|
|
sum = getSum(numbers); //sum now holds the sum of all elements in the ArrayList numbers
|
|
sum = getBigSum(numbers): //Same as getSum, but for BigInteger
|
|
prod = getProd(numbers); //prod now holds the product of all elements in the ArrayList numbers
|
|
prod = getBigProd(numbers); //Same as getProd, but for BigInteger |