View Javadoc
1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  package com.gisgraphy.helper;
24  
25  import com.gisgraphy.domain.geoloc.entity.Adm;
26  import com.gisgraphy.domain.geoloc.entity.City;
27  import com.gisgraphy.domain.geoloc.entity.Country;
28  
29  /**
30   * Provides some useful methods
31   * 
32   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
33   */
34  public enum FeatureClassCodeHelper {
35      /**
36       * The city feature Code
37       */
38      P_PPL, P_PPLA, P_PPLA2, P_PPLA3, P_PPLA4,P_PPLA5, P_PPLC, P_PPLG, P_PPLL, P_PPLR, P_PPLS, P_STLMT, P_PPLQ, P_PPLW;
39  
40      /**
41       * Whether the feature code and the feature class are for {@link City}
42       * objects. This method is case sensitive : if you provide lower case
43       * feature Class or feature code it will return false. <br>
44       * If you provide null feature class or feature code it will return false.
45       * 
46       * @param featureClass
47       *                The feature class of the gisFeature
48       * @param featureCode
49       *                The feature code of the gisFeature
50       * @return true if the featureClass="P" and the featurecode belongs to the
51       *         {@linkplain FeatureClassCodeHelper} Enum
52       */
53      public static boolean isCity(String featureClass, String featureCode) {
54  	if (featureClass != null && featureCode != null
55  		&& featureClass.equals("P")) {
56  	    FeatureClassCodeHelper[] featureCodes = FeatureClassCodeHelper
57  		    .values();
58  	    String classCode = "";
59  	    for (FeatureClassCodeHelper element : featureCodes) {
60  		classCode = featureClass + "_" + featureCode;
61  		if (classCode.equals(element.toString())) {
62  		    return true;
63  		}
64  	    }
65  	}
66  	return false;
67      }
68  
69      /**
70       * Whether the feature code and the feature class are for {@link Country}
71       * object. This method is case sensitive : if you provide lower case feature
72       * Class or Feature Code it will return false. <br>
73       * If you provide null featureClass or FeatureCode it will return false.
74       * 
75       * @param featureClass
76       *                The feature class to test
77       * @param featureCode
78       *                The feature code to test
79       * @return true if the feature class and the feature code are for
80       *         {@link Country} Object
81       */
82      public static boolean isCountry(String featureClass, String featureCode) {
83  	if (featureCode != null && featureClass != null
84  		&& featureClass.equals("A")) {
85  	    return (featureCode.startsWith("PCL"))
86  		    && (!featureCode.equals("PCLIX"));
87  	}
88  	return false;
89      }
90  
91      /**
92       * Whether the feature code and the feature class are for {@link Adm} object
93       * It will return true if featureClass equals 'A' and featureCode is
94       * ADM1,ADM2,ADM3,ADM4. it is case sensitive and will retrun false for
95       * A.ADM.ADMD are not considered as ADM
96       * 
97       * @param featureClass
98       *                The feature class to test
99       * @param featureCode
100      *                The feature code to test
101      * @return true if the feature class and the feature code are for
102      *         {@link Adm} Object
103      */
104     public static boolean is_Adm(String featureClass, String featureCode) {
105 	// TODO V2 why if this method is named isAdm =>test fails
106 	if (featureCode != null
107 		&& featureClass != null
108 		&& featureClass.equals("A")
109 		&& featureCode.length() == 4
110 		&& (featureCode.equals("ADM1") || featureCode.equals("ADM2")
111 			|| featureCode.equals("ADM3") || featureCode
112 			.equals("ADM4"))) {
113 	    return true;
114 	}
115 	return false;
116     }
117 }