Skip to content

Commit

Permalink
objectionary#3047: Renamed to PhTracing
Browse files Browse the repository at this point in the history
  • Loading branch information
levBagryansky committed Apr 17, 2024
1 parent 0df59c8 commit 525c156
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.PhTracedLocator;
import org.eolang.PhTracing;
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 PhTracedLocator(
return new PhTracing(
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 PhTracedLocator implements Phi {
public final class PhTracing implements Phi {

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

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

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

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

@Override
public boolean put(final String name, final Phi obj) {
return new PhTracedLocator.TracingWhileGetting<>(
return new PhTracing.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 PhTracedLocator#DATAIZING_CAGES}.
* Increments counter of cage in the {@link PhTracing#DATAIZING_CAGES}.
* @return New value in the map.
*/
private Integer incrementCageCounter() {
return PhTracedLocator.DATAIZING_CAGES.get().compute(
PhTracedLocator.this.locator, (key, counter) -> {
return PhTracing.DATAIZING_CAGES.get().compute(
PhTracing.this.locator, (key, counter) -> {
final int ret = this.incremented(counter);
if (ret > PhTracedLocator.this.depth) {
if (ret > PhTracing.this.depth) {
throw new ExFailure(
"The cage %s with locator %d has reached the maximum nesting depth = %d",
PhTracedLocator.this.object,
PhTracedLocator.this.locator,
PhTracedLocator.this.depth
PhTracing.this.object,
PhTracing.this.locator,
PhTracing.this.depth
);
}
return ret;
Expand All @@ -221,19 +221,19 @@ private Integer incremented(final Integer number) {
}

/**
* Decrements counter in the {@link PhTracedLocator#DATAIZING_CAGES}.
* Decrements counter in the {@link PhTracing#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) {
PhTracedLocator.DATAIZING_CAGES.get().remove(
PhTracedLocator.this.locator
PhTracing.DATAIZING_CAGES.get().remove(
PhTracing.this.locator
);
} else {
PhTracedLocator.DATAIZING_CAGES.get().put(
PhTracedLocator.this.locator, decremented
PhTracing.DATAIZING_CAGES.get().put(
PhTracing.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.PhTracedLocator;
import org.eolang.PhTracing;
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(
PhTracedLocator.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME, String.valueOf(MAX_DEPTH)
PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME, String.valueOf(MAX_DEPTH)
);
}

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

@Test
Expand Down Expand Up @@ -244,7 +244,7 @@ void doesNotThrowIfDataizesConcurrently() {
@Test
void rewritesItselfToItselfViaDummy() {
System.setProperty(
PhTracedLocator.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME, "2"
PhTracing.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",
PhTracedLocator.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME,
System.getProperty(PhTracedLocator.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME),
PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME,
System.getProperty(PhTracing.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",
PhTracedLocator.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME,
System.getProperty(PhTracedLocator.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME),
PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME,
System.getProperty(PhTracing.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",
PhTracedLocator.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME,
System.getProperty(PhTracedLocator.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME),
PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME,
System.getProperty(PhTracing.MAX_CAGE_RECURSION_DEPTH_PROPERTY_NAME),
ExAbstract.class
)
);
Expand Down

0 comments on commit 525c156

Please sign in to comment.