Class NullSafeRing<E>

java.lang.Object
dk.jonaslindstrom.ruffini.common.helpers.NullSafeRing<E>
All Implemented Interfaces:
AdditiveGroup<E>, CommutativeMonoid<E>, Monoid<E>, Ring<E>, Semigroup<E>, SemiRing<E>, Set<E>

public class NullSafeRing<E> extends Object implements Ring<E>
This class wraps a ring but operations will treat null operands as if they were zero.
  • Constructor Details

    • NullSafeRing

      public NullSafeRing(Ring<E> ring)
  • Method Details

    • multiply

      public E multiply(E a, E b)
      Description copied from interface: Semigroup
      Return the result of the product ab in this group.
      Specified by:
      multiply in interface Semigroup<E>
    • add

      public E add(E a, E b)
      Description copied from interface: CommutativeMonoid
      Return the result of a+b.
      Specified by:
      add in interface CommutativeMonoid<E>
    • negate

      public E negate(E a)
      Description copied from interface: AdditiveGroup
      Return -a.
      Specified by:
      negate in interface AdditiveGroup<E>
    • identity

      public E identity()
      Description copied from interface: Monoid
      Return the identity element of this monoid.
      Specified by:
      identity in interface Monoid<E>
    • toString

      public String toString(E a)
      Description copied from interface: Set
      Returns a human-readable string representation of an element in this set.
      Specified by:
      toString in interface Set<E>
    • equals

      public boolean equals(E a, E b)
      Description copied from interface: Set
      Returns true if and only if a = b as elements of this set.
      Specified by:
      equals in interface Set<E>
    • zero

      public E zero()
      Description copied from interface: CommutativeMonoid
      Return the zero element.
      Specified by:
      zero in interface CommutativeMonoid<E>