Refactoring operation name : extract class

Refactoring object : MakeBytesToSegment

Reason : makeBytes, changeByteToSegment has independent role.
So, make these function to class(MakeBytesToSegment).
pull/90/head^2
jaemin7666 5 years ago
parent 658630752e
commit 33c8042f00

@ -0,0 +1,36 @@
import java.nio.charset.StandardCharsets;
import java.util.Objects;
public class MakeBytesToSegment implements MakeSegment {
/**
* Returns a segment representing the specified binary data
* encoded in byte mode. All input byte arrays are acceptable.
* <p>Any text string can be converted to UTF-8 bytes ({@code
* s.getBytes(StandardCharsets.UTF_8)}) and encoded as a byte mode segment.</p>
* @param data the binary data (not {@code null})
* @return a segment (not {@code null}) containing the data
* @throws NullPointerException if the array is {@code null}
*/
public QrSegment excute(String text) {
byte[] data = text.getBytes(StandardCharsets.UTF_8));
Objects.requireNonNull(data);
BitBuffer bitBuffer = new BitBuffer();
for (byte bits : data)
changeByteToSegment(bitBuffer, bits);
return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer);
}
public QrSegment excuteForBytedata(byte[] data) {
Objects.requireNonNull(data);
BitBuffer bitBuffer = new BitBuffer();
for (byte bits : data)
changeByteToSegment(bitBuffer, bits);
return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer);
}
public static void changeByteToSegment(BitBuffer bitBuffer, byte bits) {
bitBuffer.appendBits(bits & 0xFF, 8);
}
}

@ -49,28 +49,6 @@ public final class QrSegment {
/*---- Static factory functions (mid level) ----*/
/**
* Returns a segment representing the specified binary data
* encoded in byte mode. All input byte arrays are acceptable.
* <p>Any text string can be converted to UTF-8 bytes ({@code
* s.getBytes(StandardCharsets.UTF_8)}) and encoded as a byte mode segment.</p>
* @param data the binary data (not {@code null})
* @return a segment (not {@code null}) containing the data
* @throws NullPointerException if the array is {@code null}
*/
public static QrSegment makeBytes(byte[] data) {
Objects.requireNonNull(data);
BitBuffer bitBuffer = new BitBuffer();
for (byte one_byte : data)
changeByteToSegment(bitBuffer, one_byte);
return new QrSegment(QrSegment.Mode.BYTE, data.length, bitBuffer);
}
public static void changeByteToSegment(BitBuffer bitBuffer, byte one_byte) {
bitBuffer.appendBits(one_byte & 0xFF, 8);
}
/**
* Returns a segment representing the specified string of decimal digits encoded in numeric mode.
* @param digits the text (not {@code null}), with only digits from 0 to 9 allowed

Loading…
Cancel
Save