Class SegmentSplitter

java.lang.Object
hlcd.testing.arrayTester.SegmentSplitter

public class SegmentSplitter extends Object
Uses a 1-D array of ints to mimic the splitting of segments. The length of the array represents the number of segments required. The value stored in each cell represents the length the segment.
 //minimal example to execute this class:
 public static void main(String[] args) {
     System.out.println("Running SegmentSplitter...");
     //number of complete 1D arrays
     long fullSegments = (long) (Math.random() * 100000);
     //extra is a value between 0 and maxSegmentLength, including both
     long extra = (long) (Math.random() * (MAX_SEGMENT_LENGTH + 1));

     long size = fullSegments * MAX_SEGMENT_LENGTH + extra;

     double sizeInGb = (64 * size) / 8000000000.0;
     //System.out.println("Total GBs of RAM used: " + sizeInGb);

     SegmentSplitter data = new SegmentSplitter(size);
     System.out.println("The size of each segment in the 2-D array: ");
     System.out.println(data);

     //count the number of cells allocated
     long cells = 0;
     for (int i = 0; i < data.array.length; i++) {
         cells += data.array[i];
     }
     //ensure the number of allocated cells matches the size specified
     if (size != cells) {
         System.out.println("Failed.");
     }else{
         System.out.println("Success!");
     }
     System.out.println("SegmentSplitter completed.");
 }
Since:
April 13th, 2022
Version:
1.0
Author:
Maysara Al Jumaily
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static int
    The maximum size of each 1-D array.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SegmentSplitter​(long size)
    The only constructor which uses the specified size to calculates the number of segments required as well as the length of each segment.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    main​(String[] args)
    Executes the program.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • MAX_SEGMENT_LENGTH

      public static int MAX_SEGMENT_LENGTH
      The maximum size of each 1-D array.
  • Constructor Details

    • SegmentSplitter

      public SegmentSplitter(long size)
      The only constructor which uses the specified size to calculates the number of segments required as well as the length of each segment.
      Parameters:
      size - the number of cells required to be stored
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • main

      public static void main(String[] args)
      Executes the program.
      Parameters:
      args - the arguments specified but will be ignored