Flyweight pattern for sorts in java backend

ready for review
You should probably add this back since it's a transitive dependency.