Skip to content

Commit

Permalink
objectionary#2863 add PhDecorator abstract class to reduce code dupli…
Browse files Browse the repository at this point in the history
…cation
  • Loading branch information
c71n93 committed Mar 8, 2024
1 parent 31572d1 commit 0a6fa6f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 73 deletions.
9 changes: 2 additions & 7 deletions eo-runtime/src/main/java/org/eolang/PhConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions eo-runtime/src/main/java/org/eolang/PhDecorator.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
19 changes: 2 additions & 17 deletions eo-runtime/src/main/java/org/eolang/PhImmovable.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,15 @@
* @since 0.23
*/
@Versionized
final class PhImmovable implements Phi {

/**
* The original.
*/
private final Phi origin;
final class PhImmovable extends PhDecorator {

/**
* Ctor.
*
* @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
Expand Down
19 changes: 2 additions & 17 deletions eo-runtime/src/main/java/org/eolang/PhLocated.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 2 additions & 7 deletions eo-runtime/src/main/java/org/eolang/PhLogged.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,15 @@
* @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.
*
* @param phi The origin
*/
public PhLogged(final Phi phi) {
this.origin = phi;
super(phi);
}

@Override
Expand Down
9 changes: 2 additions & 7 deletions eo-runtime/src/main/java/org/eolang/PhNamed.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

Expand Down
20 changes: 2 additions & 18 deletions eo-runtime/src/main/java/org/eolang/PhSafe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0a6fa6f

Please sign in to comment.