Could we try to share this logic among Double/Long/String terms aggregators by having a common superclass?