I've tried to use Collections.sort(shapes)
but it's giving me this error:
Bound mismatch: The generic method sort(List<T>) of type Collections is not applicable for the
arguments (ArrayList<CreateShape>). The inferred type CreateShape is not a valid substitute for the
bounded parameter <T extends Comparable<? super T>>
How should I fix that?
CreateSpace class
public class CreateSpace implements Space{
private int height;
private int width;
private String layout;
private char[][] space;
private Shape originalShape;
private ArrayList<CreateShape> shapes = new ArrayList<CreateShape>();
public CreateSpace(int height, int width, char[][] space, String layout)
{
this.height = height;
this.width = width;
this.space = space;
this.layout = layout;
}
public void placeShapeAt(int row, int col, Shape shape)
{
int sHeight = shape.getHeight();
int sWidth = shape.getWidth();
if(shape.getHeight() + row > space.length || shape.getWidth() + col > space[0].length)
throw new FitItException("Out of bounds!");
char [][] spaceWithShapes = space;
if(shapeFitsAt(row, col, shape) == true)
{
for(int r = 0; r < sHeight; r++)
{
for(int c = 0; c < sWidth; c++)
{
if(spaceWithShapes[r+row][c+col] == '.' && shape.isFilledAt(r, c) == false)
spaceWithShapes[r+row][c+col] = (((CreateShape)shape).getShape()[r][c]);
}
// shapes.add((CreateShape)shape);
Collections.sort(shapes); // <<------- getting an error here
}
spaceWithShapes = space;
shapes.add((CreateShape)shape);
Collections.sort(shapes); // <<------- getting an error here
}
}