This repository has been archived by the owner on Jan 7, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduced AssertionMap in domain model
- Loading branch information
1 parent
8ce0df9
commit 97db253
Showing
11 changed files
with
106 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
gcontracts-core/src/main/java/org/gcontracts/domain/AssertionMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.gcontracts.domain; | ||
|
||
import org.codehaus.groovy.ast.MethodNode; | ||
import org.gcontracts.util.Validate; | ||
|
||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author andre.steingress@gmail.com | ||
*/ | ||
public class AssertionMap<T extends Assertion<T>> implements Iterable<Map.Entry<MethodNode, T>> { | ||
|
||
private final Map<MethodNode, T> internalMap; | ||
|
||
public AssertionMap() { | ||
this.internalMap = new HashMap<MethodNode, T>(); | ||
} | ||
|
||
public void and(final MethodNode methodNode, final T assertion) { | ||
Validate.notNull(methodNode); | ||
Validate.notNull(assertion); | ||
|
||
if (!internalMap.containsKey(methodNode)) { | ||
internalMap.put(methodNode, assertion); | ||
} else { | ||
internalMap.get(methodNode).and(assertion); | ||
} | ||
} | ||
|
||
public void or(final MethodNode methodNode, final T assertion) { | ||
Validate.notNull(methodNode); | ||
Validate.notNull(assertion); | ||
|
||
if (!internalMap.containsKey(methodNode)) { | ||
internalMap.put(methodNode, assertion); | ||
} else { | ||
internalMap.get(methodNode).or(assertion); | ||
} | ||
} | ||
|
||
public void join(final MethodNode methodNode, final T assertion) { | ||
and(methodNode, assertion); | ||
} | ||
|
||
public boolean contains(final MethodNode methodNode) { | ||
return internalMap.containsKey(methodNode); | ||
} | ||
|
||
public Iterator<Map.Entry<MethodNode, T>> iterator() { | ||
return internalMap.entrySet().iterator(); | ||
} | ||
|
||
public int size() { | ||
return internalMap.size(); | ||
} | ||
|
||
public T get(final MethodNode methodNode) { | ||
return internalMap.get(methodNode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters