| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| GroupTypeStatePatternMatcher |
|
| 6.5;6.5 |
| 1 | /* | |
| 2 | * Copyright 2009 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community 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.osedu.org/licenses/ECL-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.kuali.student.contract.model.util; | |
| 17 | ||
| 18 | /** | |
| 19 | * Matches patterns that define groups of types or groups of states | |
| 20 | * Currently supports comma separated lists and wildcard * at the end | |
| 21 | * @author nwright | |
| 22 | */ | |
| 23 | public class GroupTypeStatePatternMatcher | |
| 24 | { | |
| 25 | ||
| 26 | private String pattern; | |
| 27 | ||
| 28 | public GroupTypeStatePatternMatcher (String pattern) | |
| 29 | 0 | { |
| 30 | 0 | this.pattern = pattern; |
| 31 | 0 | } |
| 32 | ||
| 33 | public boolean matches (String key) | |
| 34 | { | |
| 35 | 0 | if (pattern.equals ("*")) |
| 36 | { | |
| 37 | 0 | return true; |
| 38 | } | |
| 39 | // check for wildcard * at the end | |
| 40 | 0 | if (pattern.endsWith ("*")) |
| 41 | { | |
| 42 | 0 | if (key.toLowerCase ().startsWith (pattern.substring (0, pattern.length () |
| 43 | - 1).toLowerCase ())) | |
| 44 | { | |
| 45 | 0 | return true; |
| 46 | } | |
| 47 | } | |
| 48 | // Check if key is in a comma separated list of keys | |
| 49 | // changed it so the list could contain a wildard as one of it's elements | |
| 50 | // for example kuali.type.foo.*,kuali.type.bar.joe | |
| 51 | 0 | if (pattern.indexOf (",") != -1) |
| 52 | { | |
| 53 | 0 | String[] patterns = pattern.split (","); |
| 54 | 0 | for (String pat : patterns) |
| 55 | { | |
| 56 | 0 | GroupTypeStatePatternMatcher matcher = |
| 57 | new GroupTypeStatePatternMatcher (pat); | |
| 58 | 0 | if (matcher.matches (key)) |
| 59 | { | |
| 60 | 0 | return true; |
| 61 | } | |
| 62 | } | |
| 63 | } | |
| 64 | //ok the pattern is the key so just compare | |
| 65 | 0 | if (pattern.equalsIgnoreCase (key)) |
| 66 | { | |
| 67 | 0 | return true; |
| 68 | } | |
| 69 | 0 | return false; |
| 70 | } | |
| 71 | ||
| 72 | } |