Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
23   98   10   3.29
0   58   0.43   2.33
7     1.43  
3    
 
  KeyStrokeMappingProviderNames       Line # 32 5 0% 3 0 100% 1.0
  KeyStrokeMappingProviderNames.NameIterator       Line # 52 18 0% 7 0 100% 1.0
  KeyStrokeMappingProviderNames.NameIterator.State       Line # 63 0 - 0 0 - -1.0
 
No Tests
 
1    /*
2    * Created on Mar 26, 2010
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2010 the original author or authors.
15    */
16    package org.fest.swing.keystroke;
17   
18    import static org.fest.util.Strings.join;
19   
20    import java.util.*;
21   
22    import org.fest.swing.util.OSFamily;
23   
24    /**
25    * Understands a generated name for a <code>{@link KeyStrokeMappingProvider}</code> to use, based on operating system
26    * family and locale.
27    *
28    * @author Alex Ruiz
29    *
30    * @since 1.2
31    */
 
32    class KeyStrokeMappingProviderNames implements Iterable<String> {
33   
34    private final String osFamily;
35    private final String language;
36    private final String country;
37   
 
38  30 toggle static KeyStrokeMappingProviderNames generateNamesFrom(OSFamily osFamily, Locale locale) {
39  30 return new KeyStrokeMappingProviderNames(osFamily, locale);
40    }
41   
 
42  30 toggle private KeyStrokeMappingProviderNames(OSFamily osFamily, Locale locale) {
43  30 this.osFamily = osFamily.key();
44  30 language = locale.getLanguage();
45  30 country = locale.getCountry();
46    }
47   
 
48  32 toggle public Iterator<String> iterator() {
49  32 return new NameIterator(osFamily, language, country);
50    }
51   
 
52    private static class NameIterator implements Iterator<String> {
53    private static final String PREFIX = KeyStrokeMappingProvider.class.getName();
54   
55    private static final String DELIMETER = "_";
56   
57    private final String osFamily;
58    private final String language;
59    private final String country;
60   
61    private State state;
62   
 
63    private enum State {
64    FULL_NAME, WITHOUT_COUNTRY, LANGUAGE_ONLY, END
65    }
66   
 
67  32 toggle NameIterator(String osFamily, String language, String country) {
68  32 this.osFamily = osFamily;
69  32 this.language = language;
70  32 this.country = country;
71  32 state = State.FULL_NAME;
72    }
73   
 
74  90 toggle public String next() {
75  90 switch(state) {
76  31 case FULL_NAME:
77  31 state = State.WITHOUT_COUNTRY;
78  31 return join(PREFIX, osFamily, language, country).with(DELIMETER);
79  29 case WITHOUT_COUNTRY:
80  29 state = State.LANGUAGE_ONLY;
81  29 return join(PREFIX, osFamily, language).with(DELIMETER);
82  29 case LANGUAGE_ONLY:
83  29 state = State.END;
84  29 return join(PREFIX, language).with(DELIMETER);
85  1 default:
86  1 throw new NoSuchElementException("There are no more names to generate");
87    }
88    }
89   
 
90  88 toggle public boolean hasNext() {
91  88 return state != State.END;
92    }
93   
 
94  1 toggle public void remove() {
95  1 throw new UnsupportedOperationException("This iterator does not support 'remove'");
96    }
97    }
98    }