{
final List<CategoryV1> categories = tag.getCategories().getItems();
if (categories.size() == 0)
{
final NameIDSortMap categoryDetails = new NameIDSortMap("Uncatagorised", -1, 0);
if (!tags.containsKey(categoryDetails))
tags.put(categoryDetails, new ArrayList<TagV1>());
tags.get(categoryDetails).add(tag);
}
else
{
for (final CategoryV1 category : categories)
{
final NameIDSortMap categoryDetails = new NameIDSortMap(category.getName(), category.getId(), category.getSort() == null ? 0 : category.getSort());
if (!tags.containsKey(categoryDetails))
tags.put(categoryDetails, new ArrayList<TagV1>());
tags.get(categoryDetails).add(tag);