How do I fix my StackOverflow Error for my Optional?

112 views Asked by At

I am working on an assignment for class, and I just can't seem to figure out what is causing this StackOverflow Error.

Some Background:

The point of this specific method is to return an Optional that is moving in a straight line using the MoveStrategy interface. The parameters dx and dy act as our "offsets" and we have to add them to our BlobView's current location.

public class StraightLineMovement implements MoveStrategy
{

  private final int dx;
  private final int dy;

  /**
   * Construct an instance which will, on each call to move, move the blob by the given offsets.
   *
   * @param dx the distance the Blob should move along the x axis
   * @param dy the distance the Blob should move along the y axis
   */
  public StraightLineMovement(int dx, int dy) 
  {
      this.dx = dx;
      this.dy = dy;
  }

  @Override
  public Optional<Point> move(BlobView bv) 
  {
        Point bvLocation = bv.getLocation();
        double bvRadius = bv.getRadius();
        
        int bv_X = bvLocation.x + dx;
        int bv_Y = bvLocation.y + dy;
        
        Point newLocation = new SimplePoint (bv_X, bv_Y);
        
        StraightLineMovement strategy = new StraightLineMovement (dx, dy);
        
        
        BlobView newView = new BlobView (newLocation, bvRadius);
        System.out.println ("Point: (" + newLocation.x + ", " + newLocation.y + ")");
        
        Optional <Point> movement = strategy.move(newView);
       
        return movement;
        //return movement.map(point -> point.moveTo(new_X, new_Y));
  }
}

It keeps giving me that error when I actually make the optional.

Here is the MoveStrategy Interface:

import java.util.Optional;

public interface MoveStrategy 
{

    public Optional<Point> move(BlobView bv);
}

I want to note that the results I am getting from the print statement are correct (as in, they are moving correctly), but I just cannot figure out how to fix this. At first, I thought it was my return statement (and it still could be), but I have tried to use .map, .filter, ect. to try and fix it, but I couldn't figure it out.

Any help would be greatly appreciated, thank you!

0

There are 0 answers