X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fdatamatrix%2Fdecoder%2FVersion.java;h=5f97854495a3e067f36af17d518b9fe86a49804b;hb=HEAD;hp=dc6469b5fa8029dd40469a1cd2e3935b72267ca3;hpb=0ee5f7050379e4edac731b8bc15ff68b6e03949c;p=zxing.git diff --git a/core/src/com/google/zxing/datamatrix/decoder/Version.java b/core/src/com/google/zxing/datamatrix/decoder/Version.java index dc6469b5..5f978544 100644 --- a/core/src/com/google/zxing/datamatrix/decoder/Version.java +++ b/core/src/com/google/zxing/datamatrix/decoder/Version.java @@ -1,5 +1,5 @@ /* - * Copyright 2007 Google Inc. + * Copyright 2007 ZXing authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,7 @@ package com.google.zxing.datamatrix.decoder; -import com.google.zxing.ReaderException; -import com.google.zxing.common.BitMatrix; +import com.google.zxing.FormatException; /** * The Version object encapsulates attributes about a particular @@ -52,11 +51,11 @@ public final class Version { // Calculate the total number of codewords int total = 0; - int ecCodewords = ecBlocks.ecCodewords; - ECB[] ecbArray = ecBlocks.ecBlocks; + int ecCodewords = ecBlocks.getECCodewords(); + ECB[] ecbArray = ecBlocks.getECBlocks(); for (int i = 0; i < ecbArray.length; i++) { ECB ecBlock = ecbArray[i]; - total += ecBlock.count * (ecBlock.dataCodewords + ecCodewords); + total += ecBlock.getCount() * (ecBlock.getDataCodewords() + ecCodewords); } this.totalCodewords = total; } @@ -93,13 +92,13 @@ public final class Version { *

Deduces version information from Data Matrix dimensions.

* * @param numRows Number of rows in modules - * @param numRows Number of columns in modules + * @param numColumns Number of columns in modules * @return {@link Version} for a Data Matrix Code of those dimensions - * @throws ReaderException if dimensions do correspond to a valid Data Matrix size + * @throws FormatException if dimensions do correspond to a valid Data Matrix size */ - public static Version getVersionForDimensions(int numRows, int numColumns) throws ReaderException { + public static Version getVersionForDimensions(int numRows, int numColumns) throws FormatException { if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) { - throw new ReaderException("Dimension must be 0 mod 2"); + throw FormatException.getFormatInstance(); } // TODO(bbrown): This is doing a linear search through the array of versions. @@ -108,14 +107,12 @@ public final class Version { int numVersions = VERSIONS.length; for (int i = 0; i < numVersions; ++i){ Version version = VERSIONS[i]; - if (version.symbolSizeRows == numRows) { - if (version.symbolSizeColumns == numColumns) { - return version; - } + if (version.symbolSizeRows == numRows && version.symbolSizeColumns == numColumns) { + return version; } } - throw new ReaderException("Dimensions do not correspond to a valid Data Matrix Version."); + throw FormatException.getFormatInstance(); } /** @@ -125,8 +122,8 @@ public final class Version { * will be the same across all blocks within one version.

*/ static final class ECBlocks { - private int ecCodewords; - private ECB[] ecBlocks; + private final int ecCodewords; + private final ECB[] ecBlocks; private ECBlocks(int ecCodewords, ECB ecBlocks) { this.ecCodewords = ecCodewords; @@ -153,8 +150,8 @@ public final class Version { * parameters is used consecutively in the Data Matrix code version's format.

*/ static final class ECB { - private int count; - private int dataCodewords; + private final int count; + private final int dataCodewords; private ECB(int count, int dataCodewords) { this.count = count; @@ -235,7 +232,7 @@ public final class Version { new ECBlocks(14, new ECB(1, 16))), new Version(28, 12, 36, 10, 16, new ECBlocks(18, new ECB(1, 22))), - new Version(29, 16, 36, 10, 16, + new Version(29, 16, 36, 14, 16, new ECBlocks(24, new ECB(1, 32))), new Version(30, 16, 48, 14, 22, new ECBlocks(28, new ECB(1, 49)))