Portfolio Code | Clement Colmerauer
Repositories
Site
Kata refactoring
Code
Commits
Branches
Tags
Search
Tree:
7810d3f
Branches
Tags
master
Kata refactoring
build
reports
jacoco
test
html
re.forestier.edu.lib
Natural.java.html
Ajout interface Job, enum Ability et enum Jobs / pas de test écrit
Clement COLMERAUER
commited
7810d3f
at 2024-10-24 17:42:22
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="pc bpc" id="L15" title="1 of 2 branches missed."> if(i == null)</span> <span class="nc" id="L16"> throw new IllegalArgumentException();</span> <span class="fc bfc" id="L17" title="All 2 branches covered."> if(i < 0)</span> <span class="fc" id="L18"> throw new IllegalArgumentException("Natural >=0");</span> <span class="fc" id="L19"> this.value = i;</span> <span class="fc" id="L20"> }</span> private Natural(int i) <span class="fc" id="L23"> {</span> <span class="fc bfc" id="L24" title="All 2 branches covered."> if(i < 0)</span> <span class="fc" id="L25"> throw new IllegalArgumentException("Natural >=0");</span> <span class="fc" id="L26"> this.value = i;</span> <span class="fc" id="L27"> }</span> public Integer toInteger() { <span class="fc" id="L31"> return Integer.valueOf(this.value);</span> } public int toInt() { <span class="fc" id="L36"> return this.value;</span> } public static Natural valueOf(Integer i) { <span class="fc bfc" id="L41" title="All 2 branches covered."> if(i == null)</span> <span class="fc" id="L42"> throw new IllegalArgumentException();</span> <span class="fc" id="L43"> return new Natural(i);</span> } public static Natural valueOf(int i) { <span class="fc" id="L48"> return new Natural(i);</span> } public void add(Natural n) { <span class="fc bfc" id="L53" title="All 2 branches covered."> if(n == null)</span> <span class="fc" id="L54"> throw new IllegalArgumentException();</span> <span class="fc" id="L55"> this.value += n.toInt();</span> <span class="fc" id="L56"> }</span> public void substract(Natural n) { <span class="pc bpc" id="L61" title="1 of 4 branches missed."> if(n == null || this.compareTo(n) == 1)</span> <span class="fc" id="L62"> throw new IllegalArgumentException();</span> <span class="fc" id="L63"> this.value -= n.toInt();</span> <span class="fc" id="L64"> } </span> public void divide(Natural n) { <span class="nc bnc" id="L68" title="All 4 branches missed."> if(n == null || n == Natural.ZERO)</span> <span class="nc" id="L69"> throw new IllegalArgumentException();</span> <span class="nc" id="L70"> this.value /= n.toInt();</span> <span class="nc" id="L71"> }</span> @Override public Object clone() { <span class="fc" id="L77"> return Natural.valueOf(this.value);</span> } @Override public String toString() { <span class="fc" id="L83"> return String.valueOf(this.value);</span> } @Override public boolean equals(Object o) { <span class="fc bfc" id="L89" title="All 2 branches covered."> if(o == null)</span> <span class="fc" id="L90"> return false;</span> <span class="fc bfc" id="L91" title="All 2 branches covered."> if(o == this)</span> <span class="fc" id="L92"> return true;</span> <span class="fc bfc" id="L93" title="All 2 branches covered."> if(!(o instanceof Natural))</span> <span class="fc" id="L94"> return false;</span> <span class="fc bfc" id="L95" title="All 2 branches covered."> return this.value == ((Natural)o).value;</span> } @Override public int compareTo(Natural n) { <span class="fc bfc" id="L101" title="All 2 branches covered."> if(n == null)</span> <span class="fc" id="L102"> throw new IllegalArgumentException();</span> <span class="fc bfc" id="L103" title="All 2 branches covered."> if(n.value > this.value)</span> <span class="fc" id="L104"> return 1;</span> <span class="fc bfc" id="L105" title="All 2 branches covered."> else if(n.value == this.value)</span> <span class="fc" id="L106"> return 0;</span> else <span class="fc" id="L108"> return -1;</span> } private static class ZERO extends Natural { private ZERO() { <span class="fc" id="L115"> super(0);</span> <span class="fc" id="L116"> }</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>