Small style stuff
[zxing.git] / core / src / com / google / zxing / qrcode / decoder / ErrorCorrectionLevel.java
1 /*
2  * Copyright 2007 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.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 Sean Owen
24  */
25 public final class ErrorCorrectionLevel {
26
27   // No, we can't use an enum here. J2ME doesn't support it.
28
29   /**
30    * L = ~7% correction
31    */
32   public static final ErrorCorrectionLevel L = new ErrorCorrectionLevel(0, 0x01, "L");
33   /**
34    * M = ~15% correction
35    */
36   public static final ErrorCorrectionLevel M = new ErrorCorrectionLevel(1, 0x00, "M");
37   /**
38    * Q = ~25% correction
39    */
40   public static final ErrorCorrectionLevel Q = new ErrorCorrectionLevel(2, 0x03, "Q");
41   /**
42    * H = ~30% correction
43    */
44   public static final ErrorCorrectionLevel H = new ErrorCorrectionLevel(3, 0x02, "H");
45
46   private static final ErrorCorrectionLevel[] FOR_BITS = {M, L, H, Q};
47
48   private final int ordinal;
49   private final int bits;
50   private final String name;
51
52   private ErrorCorrectionLevel(int ordinal, int bits, String name) {
53     this.ordinal = ordinal;
54     this.bits = bits;
55     this.name = name;
56   }
57
58   public int ordinal() {
59     return ordinal;
60   }
61
62   public int getBits() {
63     return bits;
64   }
65
66   public String getName() {
67     return name;
68   }
69
70   public String toString() {
71     return name;
72   }
73
74   /**
75    * @param bits int containing the two bits encoding a QR Code's error correction level
76    * @return {@link ErrorCorrectionLevel} representing the encoded error correction level
77    */
78   public static ErrorCorrectionLevel forBits(int bits) {
79     if (bits < 0 || bits >= FOR_BITS.length) {
80       throw new IllegalArgumentException();
81     }
82     return FOR_BITS[bits];
83   }
84
85
86 }