Class PrimeFactors

java.lang.Object
eu.bandm.tools.util2.PrimeFactors

public class PrimeFactors extends Object
Calculates prime factor combinations for Rationals, i.e. positive or negative exponents. Objects exist in two flavours:
Modifiable for setting and clearing exponents.
Unmodifiable for being cached and cheaply retrieved.
Between these flavours there are conversion functions, making new copies.
Internally they maintain a Map from bases to exponents. Bases with exponent==0 are removed from the maps.
  • Field Details

  • Method Details

    • modifiable

      public PrimeFactors modifiable()
      Always makes a new copy, which is modifiable.
    • unmodifiable

      public PrimeFactors unmodifiable()
      Make a new unmodifiable version, iff not already unmodifiable.
    • get

      public static PrimeFactors get(BigInteger bi)
      Returns:
      an unmodifiable prime factor map for the given value.
    • get

      public static PrimeFactors get(int value)
      Returns:
      an unmodifiable prime factor map for the given value.
    • get

      public static PrimeFactors get(Rational rat)
      Returns:
      the prime factor map for the given value.
    • isPrime

      public static boolean isPrime(int i)
      Whether the argument is a prim number >=1. 1 and 2 count as prime.
    • isSingleBased

      public static boolean isSingleBased(int i)
      Whether the argument is a power of only one single basis.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isOne

      public boolean isOne()
    • isInteger

      public boolean isInteger()
    • count

      public int count(int p)
      Returns:
      the exponent for the given base.
    • countBases

      public int countBases()
      Returns:
      the number of different bases.
    • countFactors

      public int countFactors()
      Returns:
      the number of different factors, which is the sum of the absolute values of all exponents.
    • intValue

      public int intValue()
      Return the integer value. If there is no such, ie. some exponent is negative, an IllegalArgumentException is thrown. If "this" was created with an exponent map, this value must be calculated and is stored locally iff this is not modifiable.
    • ratValue

      public Rational ratValue()
      Return the rational value. If "this" was created with an exponent map, this value must be calculated and is stored locally iff this is not modifiable.
    • domain

      public SortedSet<Integer> domain()
      Only those bases with exp!=0
    • isPowerOf

      public boolean isPowerOf(int b)
      Whether this is a power (with an exponent !=0) of the one single basis.
    • simpleFactors

      public List<Integer> simpleFactors(boolean reverse)
      Iterate over identic factors seperated, like "2, 2, 3, 5, 5", not "4,3,25".
    • add

      public void add(int p)
      Add 1(one) to the currently present exponent (maybe ==0) of p. Only supported if modifiable==true.
    • add

      public void add(int p, int v)
      Add exponent v to the currently present exponent (maybe ==0) of p. Only supported if modifiable==true.
    • removeDomain

      public void removeDomain(int p)
      Remove basis from domain. Only supported if modifiable==true.
    • clear

      public void clear()
      Clear all exponents to zero(0). Only supported if modifiable==true.
    • cmp

      public int cmp(PrimeFactors other)
      Returns -1/0/+1 for inclusion or equality, negative exponents are smaller than positives, and returns a different int (here: -100) iff not comparable.
    • containsAsFactor

      public boolean containsAsFactor(PrimeFactors b)
      Returns whether arg is a factor of this
    • max

      public PrimeFactors max(PrimeFactors b)
      Return an instance with the more positive exponents of both arguments.
    • min

      public PrimeFactors min(PrimeFactors b)
      Return an instance with the more negative exponents of both arguments.
    • with

      public PrimeFactors with(int base, int exp)
      Return an instance with the base and ecponent overwritten.
    • minus

      public PrimeFactors minus(PrimeFactors b)
      Subtract exponents, ie. divide values.
    • plus

      public PrimeFactors plus(PrimeFactors b)
      Add exponents, ie. multiply values.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object b)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(PrimeFactors b)
    • denominator

      public PrimeFactors denominator()
      Returns:
      prime factors in denominator, as positive exponents of the original negatives.
    • numerator

      public PrimeFactors numerator()
      Returns:
      prime factors in numerators, i.e. all which are originally positive.