Display possible country origin info on product scan
[zxing.git] / core / src / com / google / zxing / oned / EANManufacturerOrgSupport.java
1 /*
2  * Copyright (C) 2010 ZXing 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
17 package com.google.zxing.oned;
18
19 import java.util.Vector;
20
21 /**
22  * Records EAN prefix to GS1 Member Organization, where the member organization
23  * correlates strongly with a country. This is an imperfect means of identifying
24  * a country of origin by EAN-13 barcode value. See
25  * <a href="http://en.wikipedia.org/wiki/List_of_GS1_country_codes">
26  * http://en.wikipedia.org/wiki/List_of_GS1_country_codes</a>.
27  *
28  * @author Sean Owen
29  */
30 final class EANManufacturerOrgSupport {
31
32   private final Vector ranges = new Vector();
33   private final Vector countryIdentifiers = new Vector();
34
35   String lookupCountryIdentifier(String productCode) {
36     initIfNeeded();
37     int prefix = Integer.parseInt(productCode.substring(0, 3));
38     int max = ranges.size();
39     for (int i = 0; i < max; i++) {
40       int[] range = (int[]) ranges.elementAt(i);
41       int start = range[0];
42       if (prefix < start) {
43         return null;
44       }
45       int end = range.length == 1 ? start : range[1];
46       if (prefix <= end) {
47         return (String) countryIdentifiers.elementAt(i);
48       }
49     }
50     return null;
51   }
52   
53   private void add(int[] range, String id) {
54     ranges.addElement(range);
55     countryIdentifiers.addElement(id);
56   }
57   
58   private synchronized void initIfNeeded() {
59     if (!ranges.isEmpty()) {
60       return;
61     }
62     add(new int[] {0,19},    "US/CA");
63     add(new int[] {30,39},   "US");
64     add(new int[] {60,139},  "US/CA");
65     add(new int[] {300,379}, "FR");
66     add(new int[] {380},     "BG");
67     add(new int[] {383},     "SI");
68     add(new int[] {385},     "HR");
69     add(new int[] {387},     "BA");
70     add(new int[] {400,440}, "DE");
71     add(new int[] {450,459}, "JP");
72     add(new int[] {460,469}, "RU");
73     add(new int[] {471},     "TW");
74     add(new int[] {474},     "EE");
75     add(new int[] {475},     "LV");
76     add(new int[] {476},     "AZ");
77     add(new int[] {477},     "LT");
78     add(new int[] {478},     "UZ");
79     add(new int[] {479},     "LK");
80     add(new int[] {480},     "PH");
81     add(new int[] {481},     "BY");
82     add(new int[] {482},     "UA");
83     add(new int[] {484},     "MD");
84     add(new int[] {485},     "AM");
85     add(new int[] {486},     "GE");
86     add(new int[] {487},     "KZ");
87     add(new int[] {489},     "HK");
88     add(new int[] {490,499}, "JP");    
89     add(new int[] {500,509}, "GB");    
90     add(new int[] {520},     "GR");
91     add(new int[] {528},     "LB");
92     add(new int[] {529},     "CY");
93     add(new int[] {531},     "MK");
94     add(new int[] {535},     "MT");
95     add(new int[] {539},     "IE");
96     add(new int[] {540,549}, "BE/LU");    
97     add(new int[] {560},     "PT");
98     add(new int[] {569},     "IS");
99     add(new int[] {570,579}, "DK");
100     add(new int[] {590},     "PL");
101     add(new int[] {594},     "RO");
102     add(new int[] {599},     "HU");
103     add(new int[] {600,601}, "ZA");
104     add(new int[] {603},     "GH");    
105     add(new int[] {608},     "BH");
106     add(new int[] {609},     "MU");
107     add(new int[] {611},     "MA");
108     add(new int[] {613},     "DZ");
109     add(new int[] {616},     "KE");
110     add(new int[] {618},     "CI");    
111     add(new int[] {619},     "TN");
112     add(new int[] {621},     "SY");
113     add(new int[] {622},     "EG");
114     add(new int[] {624},     "LY");
115     add(new int[] {625},     "JO");
116     add(new int[] {626},     "IR");
117     add(new int[] {627},     "KW");
118     add(new int[] {628},     "SA");
119     add(new int[] {629},     "AE");
120     add(new int[] {640,649}, "FI");
121     add(new int[] {690,695}, "CN");
122     add(new int[] {700,709}, "NO");
123     add(new int[] {729},     "IL");
124     add(new int[] {730,739}, "SE");
125     add(new int[] {740},     "GT");
126     add(new int[] {741},     "SV");
127     add(new int[] {742},     "HN");
128     add(new int[] {743},     "NI");
129     add(new int[] {744},     "CR");
130     add(new int[] {745},     "PA");
131     add(new int[] {746},     "DO");
132     add(new int[] {750},     "MX");
133     add(new int[] {754,755}, "CA");
134     add(new int[] {759},     "VE");
135     add(new int[] {760,769}, "CH");
136     add(new int[] {770},     "CO");
137     add(new int[] {773},     "UY");
138     add(new int[] {775},     "PE");
139     add(new int[] {777},     "BO");
140     add(new int[] {779},     "AR");
141     add(new int[] {780},     "CL");
142     add(new int[] {784},     "PY");
143     add(new int[] {785},     "PE");  
144     add(new int[] {786},     "EC");
145     add(new int[] {789,790}, "BR");
146     add(new int[] {800,839}, "IT");
147     add(new int[] {840,849}, "ES");
148     add(new int[] {850},     "CU");
149     add(new int[] {858},     "SK");
150     add(new int[] {859},     "CZ");
151     add(new int[] {860},     "YU");
152     add(new int[] {865},     "MN");    
153     add(new int[] {867},     "KP");
154     add(new int[] {868,869}, "TR");
155     add(new int[] {870,879}, "NL");
156     add(new int[] {880},     "KR");
157     add(new int[] {885},     "TH");
158     add(new int[] {888},     "SG");
159     add(new int[] {890},     "IN");
160     add(new int[] {893},     "VN");
161     add(new int[] {896},     "PK");    
162     add(new int[] {899},     "ID");
163     add(new int[] {900,919}, "AT");
164     add(new int[] {930,939}, "AU");
165     add(new int[] {940,949}, "AZ");
166     add(new int[] {955},     "MY");
167     add(new int[] {958},     "MO");
168   }
169
170 }