From dff4c991263062129ff144ca7caa0afcbd56df3a Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 24 Jul 2017 13:57:14 -0700 Subject: [PATCH] Add a way to get a value of a primitive number to the Number interface. --- src/org/nwapw/abacus/number/NaiveNumber.java | 20 ++++++++++++++++++++ src/org/nwapw/abacus/number/Number.java | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/src/org/nwapw/abacus/number/NaiveNumber.java b/src/org/nwapw/abacus/number/NaiveNumber.java index 10b89a4..1bb73b8 100644 --- a/src/org/nwapw/abacus/number/NaiveNumber.java +++ b/src/org/nwapw/abacus/number/NaiveNumber.java @@ -37,4 +37,24 @@ public class NaiveNumber implements Number { public Number negate() { return new NaiveNumber(-value); } + + @Override + public Number zero() { + return new NaiveNumber(0); + } + + @Override + public Number one() { + return new NaiveNumber(1); + } + + @Override + public Number valueOf(int val) { + return new NaiveNumber(value); + } + + @Override + public Number valueOf(double val) { + return new NaiveNumber(value); + } } diff --git a/src/org/nwapw/abacus/number/Number.java b/src/org/nwapw/abacus/number/Number.java index 5a42949..0f11c45 100755 --- a/src/org/nwapw/abacus/number/Number.java +++ b/src/org/nwapw/abacus/number/Number.java @@ -9,4 +9,10 @@ public interface Number { Number subtract(Number subtrahend); Number negate(); + Number zero(); + Number one(); + + Number valueOf(int val); + Number valueOf(double val); + }