2 * Copyright 2007 ZXing authors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.zxing.qrcode.decoder;
19 import com.google.zxing.ReaderException;
22 * <p>See ISO 18004:2006, 6.5.1. This enum encapsulates the four error correction levels
23 * defined by the QR code standard.</p>
27 public final class ErrorCorrectionLevel {
29 // No, we can't use an enum here. J2ME doesn't support it.
34 public static final ErrorCorrectionLevel L = new ErrorCorrectionLevel(0, 0x01, "L");
38 public static final ErrorCorrectionLevel M = new ErrorCorrectionLevel(1, 0x00, "M");
42 public static final ErrorCorrectionLevel Q = new ErrorCorrectionLevel(2, 0x03, "Q");
46 public static final ErrorCorrectionLevel H = new ErrorCorrectionLevel(3, 0x02, "H");
48 private static final ErrorCorrectionLevel[] FOR_BITS = {M, L, H, Q};
50 private final int ordinal;
51 private final int bits;
52 private final String name;
54 private ErrorCorrectionLevel(int ordinal, int bits, String name) {
55 this.ordinal = ordinal;
60 public int ordinal() {
64 public int getBits() {
68 public String getName() {
72 public String toString() {
77 * @param bits int containing the two bits encoding a QR Code's error correction level
78 * @return {@link ErrorCorrectionLevel} representing the encoded error correction level
80 public static ErrorCorrectionLevel forBits(int bits) {
81 if (bits < 0 || bits >= FOR_BITS.length) {
82 throw new IllegalArgumentException();
84 return FOR_BITS[bits];