Class SSSSSReader

java.lang.Object
application.model.database.DatabaseReader
application.model.database.SSSSSReader

public class SSSSSReader
extends DatabaseReader
Reads the Smallest Spaceship Supporting Specific Speeds (5S) database. Assumes the database is sorted by period in ascending order and displacement by descending order.
Example Usage:

 SSSSSReader reader = new SSSSSReader(new File("5s.sss.txt"))

 // Will probably return NullPointerException until that elusive ship is found
 System.out.println(Utils.fullRLE(reader.getShipBySpeed("(7, 1)c/8")))
 
  • Constructor Summary

    Constructors 
    Constructor Description
    SSSSSReader​(java.io.File file)
    Constructs the reader
  • Method Summary

    Modifier and Type Method Description
    Spaceship getShipBySpeed​(int period, int dx, int dy)
    Gets an spaceship in the database by its speed / velocity Uses binary search for speed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SSSSSReader

      public SSSSSReader​(java.io.File file) throws java.io.IOException
      Constructs the reader
      Parameters:
      file - The file where the database is stored
      Throws:
      java.io.IOException - Thrown if there is an IOException while reading the file
  • Method Details

    • getShipBySpeed

      public Spaceship getShipBySpeed​(int period, int dx, int dy)
      Gets an spaceship in the database by its speed / velocity Uses binary search for speed.
      Parameters:
      period - The period of the spaceship
      dx - The x displacement of the spaceship
      dy - The y displacement of the spaceship
      Returns:
      Returns the spaceship speed