Investigate reusable witness implementation class

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • None
    • Affects Version/s: None
    • Component/s: core-libs

      The witness implementations to allow operator usage are very stylized a boilerplate pattern:

          public static final __witness Numerical<NUM_TYPE> NUM =
              new Numerical<NUM_TYPE>() {

              public NUM_TYPE add(NUM_TYPE addend,
                                  NUM_TYPE augend) {
                  return NUM_TYPE.add(addend, augend);
              }

              public NUM_TYPE subtract(NUM_TYPE minuend,
                                       NUM_TYPE subtrahend) {
                  return NUM_TYPE.subtract(minuend, subtrahend);
              }

              public NUM_TYPE multiply(NUM_TYPE multiplier,
                                       NUM_TYPE multiplicand) {
                  return NUM_TYPE.multiply(multiplier, multiplicand);
              }

              public NUM_TYPE divide(NUM_TYPE dividend,
                                     NUM_TYPE divisor) {
                  return NUM_TYPE.divide(dividend, divisor);
              }

              public NUM_TYPE remainder(NUM_TYPE dividend,
                                        NUM_TYPE divisor) {
                  return NUM_TYPE.remainder( dividend, divisor);
              }

              public NUM_TYPE plus(NUM_TYPE operand) {
                  return NUM_TYPE.plus(operand);
              }

              public NUM_TYPE negate(NUM_TYPE operand) {
                  return NUM_TYPE.negate( operand);
              }
          };

      where NUM_TYPE is numerical type where operators are useful and

      NUM_TYPE.$METHOD_NAME($OPERANDS)

      are calls into _static_ methods defined on the NUM_TYPE class.

      It would be helpful to explore techniques to avoid writing this code explicitly, or even having to IDE-generated.

            Assignee:
            Joe Darcy
            Reporter:
            Joe Darcy
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: