Skip to content

Commit

Permalink
objectionary#3058: Renamed to PhTraced
Browse files Browse the repository at this point in the history
  • Loading branch information
levBagryansky committed Apr 18, 2024
1 parent 525c156 commit 6e5dc17
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.eolang.Attr;
import org.eolang.Param;
import org.eolang.PhDefault;
import org.eolang.PhTracing;
import org.eolang.PhTraced;
import org.eolang.Phi;
import org.eolang.Versionized;
import org.eolang.XmirObject;
Expand All @@ -57,7 +57,7 @@ public Phi lambda() throws Exception {
final int locator = Math.toIntExact(
new Param(this.take(Attr.RHO), "locator").strong(Long.class)
);
return new PhTracing(
return new PhTraced(
Cages.INSTANCE.get(locator),
locator
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @since 0.36
*/
@Versionized
public final class PhTracing implements Phi {
public final class PhTraced implements Phi {

/**
* Name of property that responsible for keeping max depth.
Expand Down Expand Up @@ -70,12 +70,12 @@ public final class PhTracing implements Phi {
* @param object Encaged object
* @param locator Locator of encaged object
*/
public PhTracing(final Phi object, final Integer locator) {
public PhTraced(final Phi object, final Integer locator) {
this(
object,
locator,
Integer.parseInt(
System.getProperty(PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME, "100")
System.getProperty(PhTraced.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME, "100")
)
);
}
Expand All @@ -86,34 +86,34 @@ public PhTracing(final Phi object, final Integer locator) {
* @param locator Locator of encaged object
* @param depth Max depth of cage recursion
*/
public PhTracing(final Phi object, final Integer locator, final int depth) {
public PhTraced(final Phi object, final Integer locator, final int depth) {
this.object = object;
this.locator = locator;
this.depth = depth;
}

@Override
public Phi copy() {
return new PhTracing(this.object.copy(), this.locator);
return new PhTraced(this.object.copy(), this.locator);
}

@Override
public Phi take(final String name) {
return new PhTracing.TracingWhileGetting<>(
return new PhTraced.TracingWhileGetting<>(
() -> this.object.take(name)
).get();
}

@Override
public boolean put(final int pos, final Phi obj) {
return new PhTracing.TracingWhileGetting<>(
return new PhTraced.TracingWhileGetting<>(
() -> this.object.put(pos, obj)
).get();
}

@Override
public boolean put(final String name, final Phi obj) {
return new PhTracing.TracingWhileGetting<>(
return new PhTraced.TracingWhileGetting<>(
() -> this.object.put(name, obj)
).get();
}
Expand Down Expand Up @@ -183,19 +183,19 @@ public T get() {
}

/**
* Increments counter of cage in the {@link PhTracing#DATAIZING_CAGES}.
* Increments counter of cage in the {@link PhTraced#DATAIZING_CAGES}.
* @return New value in the map.
*/
private Integer incrementCageCounter() {
return PhTracing.DATAIZING_CAGES.get().compute(
PhTracing.this.locator, (key, counter) -> {
return PhTraced.DATAIZING_CAGES.get().compute(
PhTraced.this.locator, (key, counter) -> {
final int ret = this.incremented(counter);
if (ret > PhTracing.this.depth) {
if (ret > PhTraced.this.depth) {
throw new ExFailure(
"The cage %s with locator %d has reached the maximum nesting depth = %d",
PhTracing.this.object,
PhTracing.this.locator,
PhTracing.this.depth
PhTraced.this.object,
PhTraced.this.locator,
PhTraced.this.depth
);
}
return ret;
Expand All @@ -221,19 +221,19 @@ private Integer incremented(final Integer number) {
}

/**
* Decrements counter in the {@link PhTracing#DATAIZING_CAGES}.
* Decrements counter in the {@link PhTraced#DATAIZING_CAGES}.
* @param incremented Current value of counter. This argument ensures
* temporal coupling with {@link TracingWhileGetting#incrementCageCounter} method.
*/
private void decrementCageCounter(final int incremented) {
final int decremented = incremented - 1;
if (decremented == 0) {
PhTracing.DATAIZING_CAGES.get().remove(
PhTracing.this.locator
PhTraced.DATAIZING_CAGES.get().remove(
PhTraced.this.locator
);
} else {
PhTracing.DATAIZING_CAGES.get().put(
PhTracing.this.locator, decremented
PhTraced.DATAIZING_CAGES.get().put(
PhTraced.this.locator, decremented
);
}
}
Expand Down
20 changes: 10 additions & 10 deletions eo-runtime/src/test/java/EOorg/EOeolang/EOcageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.eolang.PhCopy;
import org.eolang.PhDefault;
import org.eolang.PhMethod;
import org.eolang.PhTracing;
import org.eolang.PhTraced;
import org.eolang.PhWith;
import org.eolang.Phi;
import org.hamcrest.MatcherAssert;
Expand Down Expand Up @@ -200,13 +200,13 @@ class RecursionTests {
@BeforeEach
void setDepth() {
System.setProperty(
PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME, String.valueOf(MAX_DEPTH)
PhTraced.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME, String.valueOf(MAX_DEPTH)
);
}

@AfterEach
void clearDepth() {
System.clearProperty(PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME);
System.clearProperty(PhTraced.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME);
}

@Test
Expand Down Expand Up @@ -244,7 +244,7 @@ void doesNotThrowIfDataizesConcurrently() {
@Test
void rewritesItselfToItselfViaDummy() {
System.setProperty(
PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME, "2"
PhTraced.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME, "2"
);
final Phi cage = EOcageTest.encaged(
new PhWith(new EOcageTest.Dummy(Phi.Φ), 0, new Data.ToPhi(1L))
Expand Down Expand Up @@ -282,8 +282,8 @@ void doesNotThrowExceptionIfSmallDepth() {
() -> new Dataized(cage).take(),
String.format(
"We expect that dataizing of nested cage which recursion depth is less than property %s = %s does not throw %s",
PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME,
System.getProperty(PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME),
PhTraced.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME,
System.getProperty(PhTraced.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME),
ExAbstract.class
)
);
Expand All @@ -303,8 +303,8 @@ void doesNotThrowExceptionIfMaxDepth() {
() -> new Dataized(cage).take(),
String.format(
"We expect that dataizing of nested cage which recursion depth is equal to property %s = %s does not throw %s",
PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME,
System.getProperty(PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME),
PhTraced.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME,
System.getProperty(PhTraced.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME),
ExAbstract.class
)
);
Expand All @@ -322,8 +322,8 @@ void throwsExceptionIfBigDepth() {
() -> new Dataized(cage).take(),
String.format(
"We expect that dataizing of nested cage which recursion depth is more than property %s = %s does not throw %s",
PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME,
System.getProperty(PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME),
PhTraced.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME,
System.getProperty(PhTraced.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME),
ExAbstract.class
)
);
Expand Down

0 comments on commit 6e5dc17

Please sign in to comment.