Portfolio Code | Clement Colmerauer
Repositories
Site
Kata refactoring
Code
Commits
Branches
Tags
Search
Tree:
f5182d0
Branches
Tags
master
Kata refactoring
build
reports
jacoco
test
html
re.forestier.edu.lib
Natural.java.html
Rendu
Clement Colmerauer
commited
f5182d0
at 2025-05-08 09:53:51
Natural.java.html
Blame
History
Raw
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="fr"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>Natural.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">kata</a> > <a href="index.source.html" class="el_package">re.forestier.edu.lib</a> > <span class="el_source">Natural.java</span></div><h1>Natural.java</h1><pre class="source lang-java linenums">package re.forestier.edu.lib; public class Natural implements Comparable<Natural>, Cloneable { private int value; <span class="fc" id="L6"> public static final Natural ZERO = new ZERO();</span> public Natural() <span class="fc" id="L9"> {</span> <span class="fc" id="L10"> this.value = 0;</span> <span class="fc" id="L11"> }</span> private Natural(Integer i) <span class="fc" id="L14"> { </span> <span class="fc bfc" id="L15" title="All 2 branches covered."> if(i < 0)</span> <span class="fc" id="L16"> throw new IllegalArgumentException("Natural >=0");</span> <span class="fc" id="L17"> this.value = i;</span> <span class="fc" id="L18"> }</span> private Natural(int i) <span class="fc" id="L21"> {</span> <span class="fc bfc" id="L22" title="All 2 branches covered."> if(i < 0)</span> <span class="fc" id="L23"> throw new IllegalArgumentException("Natural >=0");</span> <span class="fc" id="L24"> this.value = i;</span> <span class="fc" id="L25"> }</span> public Integer toInteger() { <span class="fc" id="L29"> return Integer.valueOf(this.value);</span> } public int toInt() { <span class="fc" id="L34"> return this.value;</span> } public static Natural valueOf(Integer i) { <span class="fc bfc" id="L39" title="All 2 branches covered."> assert i != null : "Argument must be non null";</span> <span class="fc" id="L41"> return new Natural(i);</span> } public static Natural valueOf(int i) { <span class="fc" id="L46"> return new Natural(i);</span> } public void add(Natural n) { <span class="fc bfc" id="L51" title="All 2 branches covered."> assert n != null : "Argument must be non null";</span> <span class="fc" id="L53"> this.value += n.toInt();</span> <span class="fc" id="L54"> }</span> public void substract(Natural n) { <span class="fc bfc" id="L59" title="All 2 branches covered."> assert n != null : "Argument must be non null";</span> <span class="fc bfc" id="L60" title="All 2 branches covered."> if(this.compareTo(n) == 1)</span> <span class="fc" id="L61"> throw new IllegalArgumentException("Too great to substract.");</span> <span class="fc" id="L62"> this.value -= n.toInt();</span> <span class="fc" id="L63"> } </span> @Override public Object clone() { <span class="fc" id="L68"> return Natural.valueOf(this.value);</span> } @Override public String toString() { <span class="fc" id="L74"> return String.valueOf(this.value);</span> } @Override public boolean equals(Object o) { <span class="fc bfc" id="L80" title="All 2 branches covered."> if(o == null)</span> <span class="fc" id="L81"> return false;</span> <span class="fc bfc" id="L82" title="All 2 branches covered."> if(o == this)</span> <span class="fc" id="L83"> return true;</span> <span class="fc bfc" id="L84" title="All 2 branches covered."> if(!(o instanceof Natural))</span> <span class="fc" id="L85"> return false;</span> <span class="fc bfc" id="L86" title="All 2 branches covered."> return this.value == ((Natural)o).value;</span> } @Override public int compareTo(Natural n) { <span class="fc bfc" id="L92" title="All 2 branches covered."> assert n != null : "Argument must be non null";</span> <span class="fc bfc" id="L93" title="All 2 branches covered."> if(n.value > this.value)</span> <span class="fc" id="L94"> return 1;</span> <span class="fc bfc" id="L95" title="All 2 branches covered."> else if(n.value == this.value)</span> <span class="fc" id="L96"> return 0;</span> else <span class="fc" id="L98"> return -1;</span> } private static class ZERO extends Natural { private ZERO() { <span class="fc" id="L105"> super(0);</span> <span class="fc" id="L106"> }</span> } } </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.11.202310140853</span></div></body></html>