Fixed the build.
[zxing.git] / core / src / com / google / zxing / qrcode / encoder / Matrix.java
1 /*
2  * Copyright 2008 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.encoder;
18
19 /**
20  * A class which wraps a 2D array.
21  *
22  * JAVAPORT: I'm not happy about the argument ordering throughout the file, as I always like to have
23  * the horizontal component first, but this is for compatibility with the C++ code. The original
24  * code was a 2D array of ints, but since it only ever gets assigned -1, 0, and 1, I'm going to use
25  * less memory and go with bytes.
26  *
27  * @author dswitkin@google.com (Daniel Switkin)
28  */
29 public final class Matrix {
30
31   private final byte[][] bytes;
32   private final int height;
33   private final int width;
34
35   public Matrix(int height, int width) {
36     bytes = new byte[height][width];
37     this.height = height;
38     this.width = width;
39   }
40
41   public final int height() {
42     return height;
43   }
44
45   public final int width() {
46     return width;
47   }
48
49   public final byte get(int y, int x) {
50     return bytes[y][x];
51   }
52
53   public final void set(int y, int x, byte value) {
54     bytes[y][x] = value;
55   }
56
57   public final void set(int y, int x, int value) {
58     bytes[y][x] = (byte) value;
59   }
60
61   public final void clear(byte value) {
62     for (int y = 0; y < height; ++y) {
63       for (int x = 0; x < width; ++x) {
64         bytes[y][x] = value;
65       }
66     }
67   }
68
69   public final String toString() {
70     StringBuffer result = new StringBuffer();
71     for (int y = 0; y < height; ++y) {
72       for (int x = 0; x < width; ++x) {
73         switch (bytes[y][x]) {
74           case 0:
75             result.append(" 0");
76             break;
77           case 1:
78             result.append(" 1");
79             break;
80           default:
81             result.append("  ");
82             break;
83         }
84       }
85       result.append("\n");
86     }
87     return result.toString();
88   }
89
90 }