Fixed the build.
[zxing.git] / core / src / com / google / zxing / qrcode / decoder / ErrorCorrectionLevel.java
index 9b9adb5..3d1f2d0 100644 (file)
@@ -16,6 +16,8 @@
 
 package com.google.zxing.qrcode.decoder;
 
+import com.google.zxing.ReaderException;
+
 /**
  * <p>See ISO 18004:2006, 6.5.1. This enum encapsulates the four error correction levels
  * defined by the QR code standard.</p>
@@ -26,20 +28,28 @@ final class ErrorCorrectionLevel {
 
   // No, we can't use an enum here. J2ME doesn't support it.
 
-  /** L = ~7% correction */
+  /**
+   * L = ~7% correction
+   */
   static final ErrorCorrectionLevel L = new ErrorCorrectionLevel(0);
-  /** M = ~15% correction */
+  /**
+   * M = ~15% correction
+   */
   static final ErrorCorrectionLevel M = new ErrorCorrectionLevel(1);
-  /** Q = ~25% correction */
+  /**
+   * Q = ~25% correction
+   */
   static final ErrorCorrectionLevel Q = new ErrorCorrectionLevel(2);
-  /** H = ~30% correction */
+  /**
+   * H = ~30% correction
+   */
   static final ErrorCorrectionLevel H = new ErrorCorrectionLevel(3);
 
-  private static final ErrorCorrectionLevel[] FOR_BITS = new ErrorCorrectionLevel[] { M, L, H, Q };
+  private static final ErrorCorrectionLevel[] FOR_BITS = {M, L, H, Q};
 
   private final int ordinal;
 
-  private ErrorCorrectionLevel(final int ordinal) {
+  private ErrorCorrectionLevel(int ordinal) {
     this.ordinal = ordinal;
   }
 
@@ -47,7 +57,14 @@ final class ErrorCorrectionLevel {
     return ordinal;
   }
 
-  static ErrorCorrectionLevel forBits(int bits) {
+  /**
+   * @param bits int containing the two bits encoding a QR Code's error correction level
+   * @return {@link ErrorCorrectionLevel} representing the encoded error correction level
+   */
+  static ErrorCorrectionLevel forBits(int bits) throws ReaderException {
+    if (bits < 0 || bits >= FOR_BITS.length) {
+      throw new ReaderException("Illegal error correction level bits" + bits);
+    }
     return FOR_BITS[bits];
   }