diff --git a/eo-runtime/src/main/java/org/eolang/PhConst.java b/eo-runtime/src/main/java/org/eolang/PhConst.java index 615a2c19be..7463a62d4d 100644 --- a/eo-runtime/src/main/java/org/eolang/PhConst.java +++ b/eo-runtime/src/main/java/org/eolang/PhConst.java @@ -35,12 +35,7 @@ * @since 0.16 */ @Versionized -public final class PhConst implements Phi { - - /** - * The origin being turned into a const. - */ - private final Phi origin; +public final class PhConst extends PhDecorator { /** * Cached attributes. @@ -53,7 +48,7 @@ public final class PhConst implements Phi { * @param phi The origin */ public PhConst(final Phi phi) { - this.origin = phi; + super(phi); } @Override diff --git a/eo-runtime/src/main/java/org/eolang/PhDecorator.java b/eo-runtime/src/main/java/org/eolang/PhDecorator.java new file mode 100644 index 0000000000..5d2c093cc5 --- /dev/null +++ b/eo-runtime/src/main/java/org/eolang/PhDecorator.java @@ -0,0 +1,23 @@ +package org.eolang; + +public abstract class PhDecorator implements Phi{ + + /** + * The original. + */ + protected final Phi origin; + + PhDecorator(final Phi phi) { + this.origin = phi; + } + + @Override + public boolean equals(final Object obj) { + return this.origin.equals(obj); + } + + @Override + public int hashCode() { + return this.origin.hashCode(); + } +} diff --git a/eo-runtime/src/main/java/org/eolang/PhImmovable.java b/eo-runtime/src/main/java/org/eolang/PhImmovable.java index eda2831af9..6ce8df8ac1 100644 --- a/eo-runtime/src/main/java/org/eolang/PhImmovable.java +++ b/eo-runtime/src/main/java/org/eolang/PhImmovable.java @@ -30,12 +30,7 @@ * @since 0.23 */ @Versionized -final class PhImmovable implements Phi { - - /** - * The original. - */ - private final Phi origin; +final class PhImmovable extends PhDecorator { /** * Ctor. @@ -43,17 +38,7 @@ final class PhImmovable implements Phi { * @param phi The object */ PhImmovable(final Phi phi) { - this.origin = phi; - } - - @Override - public boolean equals(final Object obj) { - return this.origin.equals(obj); - } - - @Override - public int hashCode() { - return this.origin.hashCode(); + super(phi); } @Override diff --git a/eo-runtime/src/main/java/org/eolang/PhLocated.java b/eo-runtime/src/main/java/org/eolang/PhLocated.java index 8532baed29..6bc53201f3 100644 --- a/eo-runtime/src/main/java/org/eolang/PhLocated.java +++ b/eo-runtime/src/main/java/org/eolang/PhLocated.java @@ -30,12 +30,7 @@ * @since 0.21 */ @Versionized -public final class PhLocated implements Phi { - - /** - * The original. - */ - private final Phi origin; +public final class PhLocated extends PhDecorator { /** * The line number. @@ -73,22 +68,12 @@ public PhLocated(final Phi phi, final int lne, final int pos) { * @checkstyle ParameterNumberCheck (5 lines) */ public PhLocated(final Phi phi, final int lne, final int pos, final String loc) { - this.origin = phi; + super(phi); this.line = lne; this.position = pos; this.location = loc; } - @Override - public boolean equals(final Object obj) { - return this.origin.equals(obj); - } - - @Override - public int hashCode() { - return this.origin.hashCode(); - } - @Override public String toString() { return String.format( diff --git a/eo-runtime/src/main/java/org/eolang/PhLogged.java b/eo-runtime/src/main/java/org/eolang/PhLogged.java index e0d2725904..ffdf6b15a7 100644 --- a/eo-runtime/src/main/java/org/eolang/PhLogged.java +++ b/eo-runtime/src/main/java/org/eolang/PhLogged.java @@ -33,12 +33,7 @@ * @since 0.24 */ @Versionized -public final class PhLogged implements Phi { - - /** - * The origin being turned into a const. - */ - private final Phi origin; +public final class PhLogged extends PhDecorator { /** * Ctor. @@ -46,7 +41,7 @@ public final class PhLogged implements Phi { * @param phi The origin */ public PhLogged(final Phi phi) { - this.origin = phi; + super(phi); } @Override diff --git a/eo-runtime/src/main/java/org/eolang/PhNamed.java b/eo-runtime/src/main/java/org/eolang/PhNamed.java index ab292f634f..38fea6a743 100644 --- a/eo-runtime/src/main/java/org/eolang/PhNamed.java +++ b/eo-runtime/src/main/java/org/eolang/PhNamed.java @@ -30,12 +30,7 @@ * @since 0.17 */ @Versionized -final class PhNamed implements Phi { - - /** - * The original. - */ - private final Phi origin; +final class PhNamed extends PhDecorator { /** * The name. @@ -49,7 +44,7 @@ final class PhNamed implements Phi { * @param txt The name */ PhNamed(final Phi phi, final String txt) { - this.origin = phi; + super(phi); this.name = txt; } diff --git a/eo-runtime/src/main/java/org/eolang/PhSafe.java b/eo-runtime/src/main/java/org/eolang/PhSafe.java index 2513de6be3..516da46e3a 100644 --- a/eo-runtime/src/main/java/org/eolang/PhSafe.java +++ b/eo-runtime/src/main/java/org/eolang/PhSafe.java @@ -33,29 +33,13 @@ * @since 0.26 */ @Versionized -public final class PhSafe implements Phi { - - /** - * The original. - */ - private final Phi origin; - +public final class PhSafe extends PhDecorator { /** * Ctor. * @param phi The object */ public PhSafe(final Phi phi) { - this.origin = phi; - } - - @Override - public boolean equals(final Object obj) { - return this.origin.equals(obj); - } - - @Override - public int hashCode() { - return this.origin.hashCode(); + super(phi); } @Override