/*
This file is created for testing/hardware benchmarking purposes.
It follows the Science and Technology Promotion License of Zhikai Wang/www.heteroclinic.net.
In addition, Zhikai Wang/www.heteroclinic.net gives up any rights upon this file.
Zhikai Wang/www.heteroclinic.net 2013
*/
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;

public class GenerateRandomNumberSet {

        /**
         * @param args
         * @throws InterruptedException
         */
        public static void main(String[] args) throws InterruptedException {
                double power = 24.0d;
                System.out.println("Integer.MAX_VALUE\t" + Integer.MAX_VALUE);
                System.out.println("Long.MAX_VALUE\t" + Long.MAX_VALUE);
                if (args.length >= 1) {
                        power = Double.parseDouble(args[0]);
                }
                // TODO Auto-generated method stub
                Set<Integer> setoflong = new HashSet<Integer>();
                //Set<Long> setoflong = new HashSet<Long>();
                long start = Calendar.getInstance().getTimeInMillis();
                int l = (int) Math.pow(2.0d, power);
                int c = 0;
                for (int i = 0; i < l-1; i++) {
                        if (i % (1024 * 1024 * 1.0) == 0)
                                System.out.println("i " + i + "\t" + (c++));
                        setoflong.add(i);
                }
                long stop = Calendar.getInstance().getTimeInMillis();
                System.out.println("Power " + power + " takes " + (stop - start)
                                + " milli-seconds.");
                System.out.println("Setoflong size is " + setoflong.size() + ".");

                //TimeUnit.MILLISECONDS.sleep(10000); // to observer memory usage.

                ClassLoader cl = ClassLoader.getSystemClassLoader();

                URL[] urls = ((URLClassLoader) cl).getURLs();

                for (URL url : urls) {
                        System.out.println(url.getFile());
                }
                /* Total number of processors or cores available to the JVM */
                System.out.println("Available processors (cores): "
                                + Runtime.getRuntime().availableProcessors());

                /* Total amount of free memory available to the JVM */
                System.out.println("Free memory (bytes): "
                                + Runtime.getRuntime().freeMemory());

                /* This will return Long.MAX_VALUE if there is no preset limit */
                long maxMemory = Runtime.getRuntime().maxMemory();
                /* Maximum amount of memory the JVM will attempt to use */
                System.out.println("Maximum memory (bytes): "
                                + (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));

                /* Total memory currently in use by the JVM */
                System.out.println("Total memory (bytes): "
                                + Runtime.getRuntime().totalMemory());

//              /* Get a list of all filesystem roots on this system */
//              File[] roots = File.listRoots();
//
//              /* For each filesystem root, print some info */
//              for (File root : roots) {
//                      System.out.println("File system root: " + root.getAbsolutePath());
//                      System.out.println("Total space (bytes): " + root.getTotalSpace());
//                      System.out.println("Free space (bytes): " + root.getFreeSpace());
//                      System.out
//                                      .println("Usable space (bytes): " + root.getUsableSpace());
//              }
                System.out.println("Setoflong size is " + setoflong.size() + ".");
        }
}