1) Command pattern 2) applyMask 3) switch statement

pull/90/head
wslbal 5 years ago
parent d99f534b61
commit 5dc8f476f7

@ -0,0 +1,17 @@
package io.nayuki.qrcodegen;
public class Button {
public Command theCommand;
public Button(Command theCommand) {
setCommand(theCommand);
}
public void setCommand(Command newCommand) {
this.theCommand = newCommand;
}
public boolean pressed(int y, int x, int msk) {
return theCommand.excute(y, x, msk);
}
}

@ -0,0 +1,5 @@
package io.nayuki.qrcodegen;
public interface Command {
public abstract boolean excute(int y, int x, int msk);
}

@ -0,0 +1,7 @@
package io.nayuki.qrcodegen;
public class Msk0 {
public boolean operation(int y, int x, int msk) {
return ((x + y) % 2 == 0);
}
}

@ -546,9 +546,15 @@ public final class QrCode {
private void applyMask(int msk) { private void applyMask(int msk) {
if (msk < 0 || msk > 7) if (msk < 0 || msk > 7)
throw new IllegalArgumentException("Mask value out of range"); throw new IllegalArgumentException("Mask value out of range");
for (int y = 0; y < size; y++) { for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) { for (int x = 0; x < size; x++) {
boolean invert; boolean invert;
Msk0 msk0 = new Msk0();
Command mskCommand = new msk0Command(msk0);
Button button = new Button(mskCommand);
invert = button.pressed(y, x, msk);
/*
switch (msk) { switch (msk) {
case 0: invert = (x + y) % 2 == 0; break; case 0: invert = (x + y) % 2 == 0; break;
case 1: invert = y % 2 == 0; break; case 1: invert = y % 2 == 0; break;
@ -560,6 +566,7 @@ public final class QrCode {
case 7: invert = ((x + y) % 2 + x * y % 3) % 2 == 0; break; case 7: invert = ((x + y) % 2 + x * y % 3) % 2 == 0; break;
default: throw new AssertionError(); default: throw new AssertionError();
} }
*/
modules[y][x] ^= invert & !isFunction[y][x]; modules[y][x] ^= invert & !isFunction[y][x];
} }
} }

@ -0,0 +1,13 @@
package io.nayuki.qrcodegen;
public class msk0Command implements Command{
private Msk0 theMsk0;
public msk0Command(Msk0 theMsk0) {
this.theMsk0 = theMsk0;
}
public boolean excute(int y, int x, int msk) {
return theMsk0.operation(y, x, msk);
}
}
Loading…
Cancel
Save