-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added generic collection matching to support better validation.
- Loading branch information
1 parent
b9e20b8
commit 8b3c092
Showing
3 changed files
with
51 additions
and
10 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
38 changes: 38 additions & 0 deletions
38
parceler/src/main/java/org/parceler/internal/matcher/GenericCollectionMatcher.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,38 @@ | ||
package org.parceler.internal.matcher; | ||
|
||
import com.google.common.base.Predicate; | ||
import com.google.common.collect.FluentIterable; | ||
import org.androidtransfuse.adapter.ASTType; | ||
import org.androidtransfuse.util.matcher.Matcher; | ||
import org.androidtransfuse.util.matcher.Matchers; | ||
import org.parceler.internal.Generators; | ||
|
||
/** | ||
* Matches both the type of a collection and the | ||
* | ||
* @author John Ericksen | ||
*/ | ||
public class GenericCollectionMatcher implements Matcher<ASTType> { | ||
|
||
private final Matcher<ASTType> collectionMatcher; | ||
private final Generators generators; | ||
private final int parameterCount; | ||
|
||
public GenericCollectionMatcher(ASTType collectionType, Generators generators, int parameterCount) { | ||
this.collectionMatcher = Matchers.type(collectionType).ignoreGenerics().build(); | ||
this.generators = generators; | ||
this.parameterCount = parameterCount; | ||
} | ||
|
||
@Override | ||
public boolean matches(ASTType input) { | ||
|
||
return collectionMatcher.matches(input) && | ||
input.getGenericParameters().size() == parameterCount && | ||
FluentIterable.from(input.getGenericParameters()).allMatch(new Predicate<ASTType>() { | ||
public boolean apply(ASTType astType) { | ||
return generators.matches(astType); | ||
} | ||
}); | ||
} | ||
} |