Added some useful outputs

This commit is contained in:
Klemek
2018-02-17 16:36:22 +01:00
parent 68a408c82b
commit 06ddcb5284
4 changed files with 24 additions and 2 deletions
+1
View File
@@ -3,3 +3,4 @@
/consumer_keys.txt /consumer_keys.txt
/info.txt /info.txt
/.classpath /.classpath
/primedate.jar
+7
View File
@@ -13,6 +13,8 @@ import java.util.TimerTask;
*/ */
public abstract class MainProcess { public abstract class MainProcess {
private final static String VERSION = "v1.1";
private final static SimpleDateFormat date2num = new SimpleDateFormat("yyyyMMddHHmm"); private final static SimpleDateFormat date2num = new SimpleDateFormat("yyyyMMddHHmm");
private final static SimpleDateFormat sdf = new SimpleDateFormat("MMMM d, yyyy 'at' HH:mm", Locale.ENGLISH); private final static SimpleDateFormat sdf = new SimpleDateFormat("MMMM d, yyyy 'at' HH:mm", Locale.ENGLISH);
private final static NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH); private final static NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH);
@@ -35,6 +37,8 @@ public abstract class MainProcess {
} }
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(String.format("PrimeDate %s%n%s",VERSION,Calendar.getInstance().getTime()));
if(args.length < 1) { if(args.length < 1) {
System.out.println("Argument 1 must be a file containing customer keys"); System.out.println("Argument 1 must be a file containing customer keys");
@@ -42,6 +46,9 @@ public abstract class MainProcess {
} }
if(TwitterClient.setUpTwitter(args[0])) { if(TwitterClient.setUpTwitter(args[0])) {
PrimeCalculator.computeList();
Timer timer = new Timer(); Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() { timer.scheduleAtFixedRate(new TimerTask() {
@Override @Override
+13 -2
View File
@@ -1,7 +1,10 @@
package fr.klemek.primedate; package fr.klemek.primedate;
import java.util.Arrays;
/** /**
* Calculate and check prime numbers * Calculate and check prime numbers
*
* @author Kleme * @author Kleme
*/ */
public abstract class PrimeCalculator { public abstract class PrimeCalculator {
@@ -12,12 +15,13 @@ public abstract class PrimeCalculator {
private static final long SQRT_MAX = (long) Math.sqrt(MAX) + 1; private static final long SQRT_MAX = (long) Math.sqrt(MAX) + 1;
private static final int MEMORY_SIZE = (int) (MAX >> 4); private static final int MEMORY_SIZE = (int) (MAX >> 4);
private static final int BLOCK_MAX = (int) (1 << 4); private static final int BLOCK_MAX = (int) (1 << 4);
private static boolean computed = false; private static boolean computed = false;
private static byte[] primes = new byte[MEMORY_SIZE]; private static byte[] primes = new byte[MEMORY_SIZE];
/** /**
* Get stored bit for number i * Get stored bit for number i
*
* @param i * @param i
* @return * @return
*/ */
@@ -29,6 +33,7 @@ public abstract class PrimeCalculator {
/** /**
* Set stored bit for number i * Set stored bit for number i
*
* @param i * @param i
*/ */
private static void setBit(long i) { private static void setBit(long i) {
@@ -41,7 +46,9 @@ public abstract class PrimeCalculator {
/** /**
* Computes first million numbers, (takes ~25 ms) * Computes first million numbers, (takes ~25 ms)
*/ */
private static void computeList() { public static void computeList() {
Arrays.fill(primes, (byte) 0);
long t0 = System.currentTimeMillis();
for (long i = 3; i < SQRT_MAX; i += 2) for (long i = 3; i < SQRT_MAX; i += 2)
if (!getBit(i)) { if (!getBit(i)) {
long j = (i * i); long j = (i * i);
@@ -51,10 +58,13 @@ public abstract class PrimeCalculator {
} }
} }
computed = true; computed = true;
System.out.println(
String.format("Calculated %d KB of primes in %d ms", MEMORY_SIZE / 1000, System.currentTimeMillis() - t0));
} }
/** /**
* Next prime stored * Next prime stored
*
* @param p * @param p
* @return * @return
*/ */
@@ -67,6 +77,7 @@ public abstract class PrimeCalculator {
/** /**
* Check if a number is prime by calculating its block * Check if a number is prime by calculating its block
*
* @param number * @param number
* @return * @return
*/ */
@@ -99,6 +99,9 @@ public abstract class TwitterClient {
} }
return false; return false;
} }
System.out.println("Successfuly connected to twitter");
return true; return true;
} }