1 /*
2  * Copyright 2011 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.modelmapper.convention;
17
18 import java.util.List;
19
20 import org.modelmapper.spi.MatchingStrategy;
21 import org.modelmapper.spi.PropertyNameInfo;
22 import org.modelmapper.spi.Tokens;
23
24 /**
25  * See {@link MatchingStrategies#STRICT}.
26  * 
27  * @author Jonathan Halterman
28  */

29 final class StrictMatchingStrategy implements MatchingStrategy {
30   @Override
31   public boolean isExact() {
32     return true;
33   }
34
35   @Override
36   public boolean matches(PropertyNameInfo propertyNameInfo) {
37     List<Tokens> sourceTokens = propertyNameInfo.getSourcePropertyTokens();
38     List<Tokens> destTokens = propertyNameInfo.getDestinationPropertyTokens();
39     if (sourceTokens.size() != destTokens.size())
40       return false;
41
42     for (int propIndex = 0; propIndex < destTokens.size(); propIndex++) {
43       Tokens sTokens = sourceTokens.get(propIndex);
44       Tokens dTokens = destTokens.get(propIndex);
45
46       if (sTokens.size() != dTokens.size())
47         return false;
48
49       for (int tokenIndex = 0; tokenIndex < sTokens.size(); tokenIndex++)
50         if (!sTokens.token(tokenIndex).equalsIgnoreCase(dTokens.token(tokenIndex)))
51           return false;
52     }
53
54     return true;
55   }
56
57   @Override
58   public String toString() {
59     return "Strict";
60   }
61 }
62