Class DensePoly

java.lang.Object
it.unimi.di.prog2.h19.AbstractPoly
it.unimi.di.prog2.h19.DensePoly
All Implemented Interfaces:
Poly, Iterable<Poly.Term>

public class DensePoly extends AbstractPoly
A dense polynomial with integer coefficients.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface it.unimi.di.prog2.h19.Poly

    Poly.Term
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int[]
    The array of coefficients, the coeffs[i] is the coefficient of \( x^i \).
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    Initializes this to be the zero polynomial, that is \( p = 0 \).
    private
    DensePoly(int degree)
    Initializes a polynomial of given degree (with all coefficients equal to 0).
     
    DensePoly(int coeff, int degree)
    Initializes this to be the polynomial \(p = cx^n\).
  • Method Summary

    Modifier and Type
    Method
    Description
    add(Poly q)
    Performs polynomial addition.
    int
    coeff(int degree)
    Returns the coefficient of the term of given exponent.
     
    Returns the negated polynomial.
    mul(Poly q)
    Performs polynomial multiplication.

    Methods inherited from class it.unimi.di.prog2.h19.AbstractPoly

    degree, equals, hashCode, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface it.unimi.di.prog2.h19.Poly

    sub
  • Field Details

    • coeffs

      private final int[] coeffs
      The array of coefficients, the coeffs[i] is the coefficient of \( x^i \).
  • Constructor Details

    • DensePoly

      public DensePoly()
      Initializes this to be the zero polynomial, that is \( p = 0 \).
    • DensePoly

      public DensePoly(int coeff, int degree) throws IllegalArgumentException
      Initializes this to be the polynomial \(p = cx^n\).
      Parameters:
      coeff - the coefficient.
      degree - the degree.
      Throws:
      IllegalArgumentException - if n < 0.
    • DensePoly

      private DensePoly(int degree)
      Initializes a polynomial of given degree (with all coefficients equal to 0).
      Parameters:
      degree - the degree.
  • Method Details

    • coeff

      public int coeff(int degree)
      Description copied from interface: Poly
      Returns the coefficient of the term of given exponent.
      Parameters:
      degree - the exponent of the term to consider.
      Returns:
      the coefficient of the considered term.
    • add

      public DensePoly add(Poly q) throws NullPointerException
      Description copied from interface: Poly
      Performs polynomial addition.

      If \( p \) is this polynomial, returns \( p + q \).

      Parameters:
      q - the polynomial to add to this one.
      Returns:
      the sum among this and the given polynomial.
      Throws:
      NullPointerException - if q is null.
    • mul

      public DensePoly mul(Poly q) throws NullPointerException
      Description copied from interface: Poly
      Performs polynomial multiplication.

      If \( p \) is this polynomial, returns \( p q \).

      Parameters:
      q - the polynomial to multiply by this one.
      Returns:
      the product among this and the given polynomial.
      Throws:
      NullPointerException - if q is null.
    • minus

      public DensePoly minus()
      Description copied from interface: Poly
      Returns the negated polynomial.

      If \( p \) is this polynomial, returns \( -p \).

      Returns:
      this polynomial multiplied by \( -1 \).
    • iterator

      public Iterator<Poly.Term> iterator()