9b9adb569b49810ec359c13d92e4fbc09adcc68f
[zxing.git] / core / src / com / google / zxing / qrcode / decoder / ErrorCorrectionLevel.java
1 /*
2  * Copyright 2007 Google Inc.
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.qrcode.decoder;
18
19 /**
20  * <p>See ISO 18004:2006, 6.5.1. This enum encapsulates the four error correction levels
21  * defined by the QR code standard.</p>
22  *
23  * @author srowen@google.com (Sean Owen)
24  */
25 final class ErrorCorrectionLevel {
26
27   // No, we can't use an enum here. J2ME doesn't support it.
28
29   /** L = ~7% correction */
30   static final ErrorCorrectionLevel L = new ErrorCorrectionLevel(0);
31   /** M = ~15% correction */
32   static final ErrorCorrectionLevel M = new ErrorCorrectionLevel(1);
33   /** Q = ~25% correction */
34   static final ErrorCorrectionLevel Q = new ErrorCorrectionLevel(2);
35   /** H = ~30% correction */
36   static final ErrorCorrectionLevel H = new ErrorCorrectionLevel(3);
37
38   private static final ErrorCorrectionLevel[] FOR_BITS = new ErrorCorrectionLevel[] { M, L, H, Q };
39
40   private final int ordinal;
41
42   private ErrorCorrectionLevel(final int ordinal) {
43     this.ordinal = ordinal;
44   }
45
46   int ordinal() {
47     return ordinal;
48   }
49
50   static ErrorCorrectionLevel forBits(int bits) {
51     return FOR_BITS[bits];
52   }
53
54
55 }