fixed class references

pull/8/head
Mariotaku Lee 9 years ago
parent 8bc3053cb5
commit fcab3ea7f4
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535

@ -33,7 +33,6 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
public final class QrSegmentAdvanced { public final class QrSegmentAdvanced {
@ -282,7 +281,8 @@ public final class QrSegmentAdvanced {
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
InputStream is = null; InputStream is = null;
try { try {
is = QrSegmentAdvanced.class.getResourceAsStream("qr_kanji_to_unicode.bin"); ClassLoader classloader = Thread.currentThread().getContextClassLoader();
is = classloader.getResourceAsStream("qr_kanji_to_unicode.bin");
byte[] buffer = new byte[8192]; byte[] buffer = new byte[8192];
int read; int read;
while ((read = is.read(buffer)) != -1) { while ((read = is.read(buffer)) != -1) {

@ -25,7 +25,6 @@
package io.nayuki.qrcodegen; package io.nayuki.qrcodegen;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects;
/** /**

@ -0,0 +1,14 @@
package io.nayuki.qrcodegen;
/**
* Created by mariotaku on 2017/4/5.
*/
public class Objects {
static <T> T requireNonNull(T obj) {
if (obj == null)
throw new NullPointerException();
return obj;
}
}

@ -27,7 +27,6 @@ package io.nayuki.qrcodegen;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale;
/** /**
* Represents an immutable square grid of black and white cells for a QR Code symbol, and * Represents an immutable square grid of black and white cells for a QR Code symbol, and
@ -51,8 +50,8 @@ public final class QrCode {
* @throws IllegalArgumentException if the text fails to fit in the largest version QR Code, which means it is too long * @throws IllegalArgumentException if the text fails to fit in the largest version QR Code, which means it is too long
*/ */
public static QrCode encodeText(String text, Ecc ecl) { public static QrCode encodeText(String text, Ecc ecl) {
requireNonNull(text); Objects.requireNonNull(text);
requireNonNull(ecl); Objects.requireNonNull(ecl);
List<QrSegment> segs = QrSegment.makeSegments(text); List<QrSegment> segs = QrSegment.makeSegments(text);
return encodeSegments(segs, ecl); return encodeSegments(segs, ecl);
} }
@ -70,8 +69,8 @@ public final class QrCode {
* @throws IllegalArgumentException if the data fails to fit in the largest version QR Code, which means it is too long * @throws IllegalArgumentException if the data fails to fit in the largest version QR Code, which means it is too long
*/ */
public static QrCode encodeBinary(byte[] data, Ecc ecl) { public static QrCode encodeBinary(byte[] data, Ecc ecl) {
requireNonNull(data); Objects.requireNonNull(data);
requireNonNull(ecl); Objects.requireNonNull(ecl);
QrSegment seg = QrSegment.makeBytes(data); QrSegment seg = QrSegment.makeBytes(data);
return encodeSegments(Collections.singletonList(seg), ecl); return encodeSegments(Collections.singletonList(seg), ecl);
} }
@ -112,8 +111,8 @@ public final class QrCode {
* &lt; &minus;1 or mask > 7, or if the data is too long to fit in a QR Code at maxVersion at the ECL * &lt; &minus;1 or mask > 7, or if the data is too long to fit in a QR Code at maxVersion at the ECL
*/ */
public static QrCode encodeSegments(List<QrSegment> segs, Ecc ecl, int minVersion, int maxVersion, int mask, boolean boostEcl) { public static QrCode encodeSegments(List<QrSegment> segs, Ecc ecl, int minVersion, int maxVersion, int mask, boolean boostEcl) {
requireNonNull(segs); Objects.requireNonNull(segs);
requireNonNull(ecl); Objects.requireNonNull(ecl);
if (!(1 <= minVersion && minVersion <= maxVersion && maxVersion <= 40) || mask < -1 || mask > 7) if (!(1 <= minVersion && minVersion <= maxVersion && maxVersion <= 40) || mask < -1 || mask > 7)
throw new IllegalArgumentException("Invalid value"); throw new IllegalArgumentException("Invalid value");
@ -201,10 +200,10 @@ public final class QrCode {
*/ */
public QrCode(int ver, Ecc ecl, byte[] dataCodewords, int mask) { public QrCode(int ver, Ecc ecl, byte[] dataCodewords, int mask) {
// Check arguments // Check arguments
requireNonNull(ecl); Objects.requireNonNull(ecl);
if (ver < 1 || ver > 40 || mask < -1 || mask > 7) if (ver < 1 || ver > 40 || mask < -1 || mask > 7)
throw new IllegalArgumentException("Value out of range"); throw new IllegalArgumentException("Value out of range");
requireNonNull(dataCodewords); Objects.requireNonNull(dataCodewords);
// Initialize fields // Initialize fields
version = ver; version = ver;
@ -232,7 +231,7 @@ public final class QrCode {
*/ */
public QrCode(QrCode qr, int mask) { public QrCode(QrCode qr, int mask) {
// Check arguments // Check arguments
requireNonNull(qr); Objects.requireNonNull(qr);
if (mask < -1 || mask > 7) if (mask < -1 || mask > 7)
throw new IllegalArgumentException("Mask value out of range"); throw new IllegalArgumentException("Mask value out of range");
@ -435,7 +434,7 @@ public final class QrCode {
// Draws the given sequence of 8-bit codewords (data and error correction) onto the entire // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
// data area of this QR Code symbol. Function modules need to be marked off before this is called. // data area of this QR Code symbol. Function modules need to be marked off before this is called.
private void drawCodewords(byte[] data) { private void drawCodewords(byte[] data) {
requireNonNull(data); Objects.requireNonNull(data);
if (data.length != getNumRawDataModules(version) / 8) if (data.length != getNumRawDataModules(version) / 8)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
@ -769,7 +768,7 @@ public final class QrCode {
* @throws NullPointerException if the data is {@code null} * @throws NullPointerException if the data is {@code null}
*/ */
public byte[] getRemainder(byte[] data) { public byte[] getRemainder(byte[] data) {
requireNonNull(data); Objects.requireNonNull(data);
// Compute the remainder by performing polynomial division // Compute the remainder by performing polynomial division
byte[] result = new byte[coefficients.length]; byte[] result = new byte[coefficients.length];
@ -804,10 +803,4 @@ public final class QrCode {
} }
private static <T> T requireNonNull(T obj) {
if (obj == null)
throw new NullPointerException();
return obj;
}
} }

@ -28,7 +28,6 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern; import java.util.regex.Pattern;

@ -2,4 +2,5 @@ dependencies {
compile project(':core') compile project(':core')
compile project(':javase') compile project(':javase')
compile project(':svg') compile project(':svg')
compile project(':advanced')
} }
Loading…
Cancel
Save