If the item is a stacked item then what you posted should work.
If it is not however, then it will be a little more complex.
If you don't care if the ground items are all in the same position then you can do:
List<GroundItem> items = getGroundItems().filter(getGroundItems().getAll(), new NameFilter<>("Item name"));
if (items.size() >= 28) {
...
}
If you want to check if the ground items are all in the same stack, then it is a little more complicated. I *think* there is a way to get the stack in the API but i'm not sure.
I can post some code if you really need.