create a cache of positions then check the cache to see if it contains the position the player wants to plant over
Code:
// We use a set because a set cannot contain duplicate elements.
private static final Set<Position> FLOWERS = new HashSet<>();
// Planting a flower.
public void addFlower(Flower flower) {
if(!canPlant(flower.getPosition()))
return;
...
...
FLOWERS.add(flower.getPosition());
}
// Removing a planted flower.
public void removeFlower(Flower flower) {
...
...
FLOWERS.remove(flower.getPosition());
}
// Determining if the flower can be planted on 'position'.
public boolean canPlant(Position position) {
return !FLOWERS.contains(position);
}