Here you can find the source of isPrimeNumber(BigDecimal inBd)
public static boolean isPrimeNumber(BigDecimal inBd)
//package com.java2s; //License from project: Open Source License import java.math.BigDecimal; import java.math.BigInteger; public class Main { public static final BigInteger BI_2 = new BigInteger("2"); public static final BigInteger BI_3 = new BigInteger("3"); public static boolean isPrimeNumber(BigDecimal inBd) { if (inBd == null || isNotZero(inBd.remainder(BigDecimal.ONE))) { return false; }//from w w w . j ava2 s. c o m return isPrimeNumber(inBd.toBigInteger()); } public static boolean isPrimeNumber(BigInteger inBi) { if (inBi == null) { return false; } if (!inBi.isProbablePrime(5)) return false; if (!BI_2.equals(inBi) && BigInteger.ZERO.equals(inBi.mod(BI_2))) return false; for (BigInteger i = BI_3; i.multiply(i).compareTo(inBi) < 1; i = i.add(BI_2)) { if (BigInteger.ZERO.equals(inBi.mod(i))) return false; } return true; } public static boolean isNotZero(BigDecimal inValue) { return inValue == null || BigDecimal.ZERO.compareTo(inValue) != 0; } public static boolean equals(Object inO1, Object inO2) { return equals(inO1, inO2, true); } /** * TODO: make external equal function which can be injected into Utils; just like the toString() methods * @param inO1 * @param inO2 * @param isBothNullEqual * @return */ public static boolean equals(Object inO1, Object inO2, boolean isBothNullEqual) { if (inO1 == null && inO2 == null) { return isBothNullEqual; } else if (inO1 == null && inO2 != null) { return false; } else if (inO2 == null && inO1 != null) { return false; } return inO1.equals(inO2); } public static <T extends Comparable<T>> int compareTo(T t1, T t2) { return compareToNullLast(t1, t2); } public static <T extends Comparable<T>> int compareToNullLast(T t1, T t2) { if (t1 == t2) { return 0; } else if (t1 == null) { return 1; } else if (t2 == null) { return -1; } else { return t1.compareTo(t2); } } }