src/main/java/org/jmxtrans/agent/util/GcdCalculator.java
public static long gcd(List<Long> l) {
        if (l.isEmpty()) {
            throw new IllegalArgumentException("List must contain at least one element");
        }
        BigInteger gcd = BigInteger.valueOf(l.get(0));
        for (Long num : l.subList(1, l.size())) {
            gcd = gcd.gcd(BigInteger.valueOf(num));
        }
        return gcd.longValue();
        
    }
public static long gcd(List<Long> l) {
        if (l.isEmpty()) {
            throw new IllegalArgumentException("List must contain at least one element");
        }
        BigInteger gcd = BigInteger.valueOf(l.get(0));
        for (Long num : l.subList(1, l.size())) {
            gcd = gcd.gcd(BigInteger.valueOf(num));
        }
        return gcd.longValue();
        
    }
Finds the greatest common divisor of all numbers in the list.

@return the GCD or Long.MAX_VALUE if the list is empty.