1
16 package org.modelmapper.convention;
17
18 import java.util.HashSet;
19 import java.util.Set;
20
21 import org.modelmapper.spi.MatchingStrategy;
22 import org.modelmapper.spi.PropertyNameInfo;
23 import org.modelmapper.spi.Tokens;
24
25
30 final class StandardMatchingStrategy implements MatchingStrategy {
31 @Override
32 public boolean matches(PropertyNameInfo propertyNameInfo) {
33 return new Matcher(propertyNameInfo).match();
34 }
35
36 static class Matcher extends InexactMatcher {
37 Matcher(PropertyNameInfo propertyNameInfo) {
38 super(propertyNameInfo);
39 }
40
41 boolean match() {
42 Set<Integer> matchSources = new HashSet<Integer>();
43 for (Tokens destTokens : propertyNameInfo.getDestinationPropertyTokens()) {
44 for (int destTokenIndex = 0; destTokenIndex < destTokens.size();) {
45 DestTokensMatcher matchedTokens = matchSourcePropertyName(destTokens, destTokenIndex);
46 if (matchedTokens.match()) {
47 destTokenIndex += matchedTokens.maxMatchTokens();
48 matchSources.addAll(matchedTokens.matchSources());
49 } else if (matchSourcePropertyType(destTokens.token(destTokenIndex))
50 || matchSourceClass(destTokens.token(destTokenIndex)))
51 destTokenIndex++;
52 else
53 return false;
54 }
55 }
56
57 return matchSources.size() == sourceTokens.size();
58 }
59 }
60
61 @Override
62 public boolean isExact() {
63 return false;
64 }
65
66 @Override
67 public String toString() {
68 return "Standard";
69 }
70 }
71