package org.netmelody.cieye.core.domain;

import static java.lang.Math.min;

public final class Percentage {

    private final int value;
    
    public Percentage() {
        this(0);
    }

    public Percentage(int value) {
        if (value < 0 || value > 100) {
            throw new IllegalArgumentException("Percentage must be between 0 and 100 inclusive.");
        }
        this.value = value;
    }

    public static Percentage percentageOf(int value) {
        return new Percentage(value);
    }
    
    public static Percentage percentageOf(long numerator, long denominator) {
        return (denominator <= 0L) ? percentageOf(0) : percentageOf((int)min((((double)numerator) / denominator) * 100, 100));
    }
    
    public int value() {
        return value;
    }
}

@@ -596,22 +596,18 @@
         
-return
+if
  (denomi
@@ -621,55 +621,200 @@
 = 0L
-) ? percentageOf(0) : percentageOf((int)min(
+ %7C%7C numerator %3C= 0L) %7B%0A            return percentageOf(0);%0A        %7D%0A        if (numerator %3E= denominator) %7B%0A            return percentageOf(100);%0A        %7D%0A        final double magnetude = 
 ((
-(
 doub
@@ -825,17 +825,16 @@
 umerator
-)
  / denom
@@ -846,16 +846,64 @@
 r) * 100
+;%0A        return percentageOf(min((int)magnetude
 , 100));

robustificate the percentage class in the face of negative values