Skip to content

Commit

Permalink
Contexts must actually clear their underlying map.
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Dec 5, 2014
1 parent 407f4f5 commit 373b433
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/src/main/java/org/ocpsoft/rewrite/config/RuleBuilder.java
Expand Up @@ -292,6 +292,16 @@ public void call(Parameterized parameterized)
+ "] and cannot be configured.");
}

@Override
public void clear()
{
if (wrapped instanceof Context)
{
((Context) wrapped).clear();;
}
contextMap.clear();;
}

@Override
public Object get(Object key)
{
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/org/ocpsoft/rewrite/config/Subset.java
Expand Up @@ -207,10 +207,12 @@ public String toString()
/**
* Clears the state of this context so that it may be reused, saving instantiation cost during rule iteration.
*/
@Override
public void clear()
{
this.postOperations.clear();
this.postOperations.clear();
super.clear();
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions api/src/main/java/org/ocpsoft/rewrite/context/Context.java
Expand Up @@ -22,6 +22,11 @@
*/
public interface Context
{
/**
* Clear the contents of this context and reset to a "like-new" state.
*/
void clear();

/**
* Get the value in the context map defined by the given key. Return <code>null</code> if no such key exists, or if
* they key maps to a <code>null</code> value.
Expand Down
Expand Up @@ -29,6 +29,12 @@ public abstract class ContextBase implements Context

private final Map<Object, Object> map = new LinkedHashMap<Object, Object>();

@Override
public void clear()
{
map.clear();
}

@Override
public Object get(final Object key)
{
Expand Down
Expand Up @@ -30,6 +30,10 @@ public class RuleBuilderTest
{
private final EvaluationContext context = new EvaluationContext() {

@Override
public void clear()
{}

@Override
public void put(Object key, Object value)
{}
Expand Down
Expand Up @@ -78,11 +78,13 @@ public String toString()
/**
* Clears the state of this context so that it may be reused, saving instantiation cost during rule iteration.
*/
@Override
public void clear()
{
this.postOperations.clear();
this.postOperations.clear();
state = null;
super.clear();
}

@Override
Expand Down
Expand Up @@ -116,4 +116,10 @@ public boolean containsKey(final Object key)
return map.containsKey(key);
}

@Override
public void clear()
{
map.clear();
}

}

0 comments on commit 373b433

Please sign in to comment.