Labelling - pure Java solution