Skip to content

Commit 4e5ba00

Browse files
committed
Rename new class name with camel case
Javadoc
1 parent 9603db8 commit 4e5ba00

File tree

2 files changed

+51
-43
lines changed

2 files changed

+51
-43
lines changed

src/main/java/org/apache/commons/codec/digest/CRC16.java renamed to src/main/java/org/apache/commons/codec/digest/Crc16.java

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
* </p>
3232
*
3333
* <pre>
34-
*
3534
* Checksum crc16 = CRC16.builder().setTable(CRC16.getModbusTable()).setInit(0x0000).get();
3635
* </pre>
3736
*
@@ -41,12 +40,12 @@
4140
* @see <a href="https://crccalc.com/?crc=123456789&method=&datatype=ascii&outtype=hex">crccalc</a>
4241
* @since 1.20.0
4342
*/
44-
public class CRC16 implements Checksum {
43+
public final class Crc16 implements Checksum {
4544

4645
/**
47-
* Builds CRC16 instances.
46+
* Builds {@link Crc16} instances.
4847
*/
49-
public static class Builder implements Supplier<CRC16> {
48+
public static final class Builder implements Supplier<Crc16> {
5049

5150
private int init;
5251
private int[] table;
@@ -60,11 +59,11 @@ public Builder() {
6059
}
6160

6261
/**
63-
* Creates a new {@link CRC16} instance.
62+
* Creates a new {@link Crc16} instance.
6463
*/
6564
@Override
66-
public CRC16 get() {
67-
return new CRC16(this);
65+
public Crc16 get() {
66+
return new Crc16(this);
6867
}
6968

7069
/**
@@ -89,7 +88,7 @@ public Builder setTable(final int[] table) {
8988
}
9089

9190
/**
92-
* Sets the XorOut value to XOR to the current checksum returned by {@link CRC16#getValue()}.
91+
* Sets the XorOut value to XOR to the current checksum returned by {@link Crc16#getValue()}.
9392
*
9493
* @param xorOut the XorOut value.
9594
* @return {@code this} instance.
@@ -270,6 +269,7 @@ private Builder table(final int[] table) {
270269

271270
/**
272271
* Creates a new CRC16-CCITT Checksum.
272+
*
273273
* <ul>
274274
* <li>The init value is {@code 0x0000}.</li>
275275
* <li>The XorOut value is {@code 0x0000}.</li>
@@ -287,12 +287,13 @@ private Builder table(final int[] table) {
287287
*
288288
* @return a new CRC16-CCITT Checksum.
289289
*/
290-
public static CRC16 arc() {
290+
public static Crc16 arc() {
291291
return builder().setInit(ARC_INIT).table(ARC).get();
292292
}
293293

294294
/**
295295
* Creates a new builder.
296+
*
296297
* <p>
297298
* Since there are so many CRC-16 variants, we do not pick a default.
298299
* </p>
@@ -324,20 +325,21 @@ public static Builder builder() {
324325
*
325326
* @return a new CRC16-CCITT Checksum.
326327
*/
327-
public static CRC16 ccitt() {
328+
public static Crc16 ccitt() {
328329
return builder().setInit(CCITT_INIT).table(CCITT).get();
329330
}
330331

331332
/**
332333
* Creates a new CRC16-DNP Checksum.
334+
*
333335
* <ul>
334336
* <li>The init value is {@code 0x0000}.</li>
335337
* <li>The XorOut value is {@code 0xFFFF}.</li>
336338
* </ul>
337339
*
338340
* @return a new CRC16-DNP Checksum.
339341
*/
340-
public static CRC16 dnp() {
342+
public static Crc16 dnp() {
341343
return builder().setInit(DNP_INIT).setXorOut(DNP_XOROUT).table(DNP).get();
342344
}
343345

@@ -415,6 +417,7 @@ public static int[] getNrsc5Table() {
415417

416418
/**
417419
* Creates a new CRC16-IBM-SDLC Checksum.
420+
*
418421
* <ul>
419422
* <li>The init value is {@code 0xFFFF}.</li>
420423
* <li>The XorOut value is {@code 0xFFFF}.</li>
@@ -433,12 +436,13 @@ public static int[] getNrsc5Table() {
433436
*
434437
* @return a new CRC16-IBM-SDLC Checksum.
435438
*/
436-
public static CRC16 ibmSdlc() {
439+
public static Crc16 ibmSdlc() {
437440
return builder().setInit(IBM_SDLC_INIT).setXorOut(IBM_SDLC_XOROUT).table(IBM_SDLC).get();
438441
}
439442

440443
/**
441444
* Creates a new instance for CRC16-MAXIM Checksum.
445+
*
442446
* <p>
443447
* CRC-16 checksum implementation based on polynomial {@code x<sup>16</spu> + x^15 + x^2 + 1 (0x8005)}.
444448
* </p>
@@ -455,25 +459,27 @@ public static CRC16 ibmSdlc() {
455459
*
456460
* @return a new CRC16-MAXIM Checksum.
457461
*/
458-
public static CRC16 maxim() {
462+
public static Crc16 maxim() {
459463
return builder().setInit(MAXIM_INIT).setXorOut(MAXIM_XOROUT).table(MAXIM).get();
460464
}
461465

462466
/**
463467
* Creates a new instance for CRC16-MCRF4XX Checksum.
468+
*
464469
* <ul>
465470
* <li>The init value is {@code 0xFFFF}.</li>
466471
* <li>The XorOut value is {@code 0x0000}.</li>
467472
* </ul>
468473
*
469474
* @return a new CRC16-MCRF4XX Checksum.
470475
*/
471-
public static CRC16 mcrf4xx() {
476+
public static Crc16 mcrf4xx() {
472477
return builder().setInit(MCRF4XX_INIT).table(MCRF4XX).get();
473478
}
474479

475480
/**
476481
* Creates a new instance for CRC16-MODBUS Checksum.
482+
*
477483
* <p>
478484
* CRC-16 checksum implementation based on polynomial {@code x<sup>16</spu> + x^15 + x^2 + 1 (0x8005)}.
479485
* </p>
@@ -491,33 +497,35 @@ public static CRC16 mcrf4xx() {
491497
*
492498
* @return a new CRC16-MODBUS Checksum.
493499
*/
494-
public static CRC16 modbus() {
500+
public static Crc16 modbus() {
495501
return builder().setInit(MODBUS_INIT).table(MODBUS).get();
496502
}
497503

498504
/**
499505
* Creates a new instance for CRC16-NRSC-5 Checksum.
506+
*
500507
* <ul>
501508
* <li>The init value is {@code 0xFFFF}.</li>
502509
* <li>The XorOut value is {@code 0x0000}.</li>
503510
* </ul>
504511
*
505512
* @return a new CRC16-NRSC-5 Checksum.
506513
*/
507-
public static CRC16 nrsc5() {
514+
public static Crc16 nrsc5() {
508515
return builder().setInit(NRSC5_INIT).table(NRSC5).get();
509516
}
510517

511518
/**
512519
* Creates a new instance for CRC16-USB Checksum.
520+
*
513521
* <ul>
514522
* <li>The init value is {@code 0xFFFF}.</li>
515523
* <li>The XorOut value is {@code 0xFFFF}.</li>
516524
* </ul>
517525
*
518526
* @return a new CRC16-USB Checksum.
519527
*/
520-
public static CRC16 usb() {
528+
public static Crc16 usb() {
521529
return builder().setInit(USB_INIT).setXorOut(USB_XOROUT).table(USB).get();
522530
}
523531

@@ -532,7 +540,7 @@ public static CRC16 usb() {
532540
/**
533541
* Constructs a new instance.
534542
*/
535-
private CRC16(final Builder builder) {
543+
private Crc16(final Builder builder) {
536544
this.init = builder.init;
537545
this.xorOut = builder.xorOut;
538546
this.crc = builder.init;
@@ -551,7 +559,7 @@ public void reset() {
551559

552560
@Override
553561
public String toString() {
554-
return String.format("CRC16 [init=0x%04X, crc=0x%04X, xorOut=0x%04X, crc^xorOut=0x%04X]", init, crc, xorOut, getValue());
562+
return String.format("%s [init=0x%04X, crc=0x%04X, xorOut=0x%04X, crc^xorOut=0x%04X]", getClass().getSimpleName(), init, crc, xorOut, getValue());
555563
}
556564

557565
@Override

src/test/java/org/apache/commons/codec/digest/CRC16Test.java renamed to src/test/java/org/apache/commons/codec/digest/Crc16Test.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
import org.junit.jupiter.params.provider.MethodSource;
3535

3636
/**
37-
* Tests {@link CRC16}.
37+
* Tests {@link Crc16}.
3838
*/
39-
class CRC16Test {
39+
class Crc16Test {
4040

4141
private static final String BIG_TEXT = Uncheck.get(() -> PathUtils.readString(Paths.get("LICENSE.txt"), StandardCharsets.US_ASCII));
4242
private static final byte[] TEST_BYTES = "123456789".getBytes(StandardCharsets.US_ASCII);
@@ -100,13 +100,13 @@ static Object[][] testDnpDefault() {
100100
static Supplier<int[]>[] testGetTables() {
101101
// @formatter:off
102102
return new Supplier[] {
103-
CRC16::getArcTable,
104-
CRC16::getCcittTable,
105-
CRC16::getDnpTable,
106-
CRC16::getMcrf4xxTable,
107-
CRC16::getMaximTable,
108-
CRC16::getModbusTable,
109-
CRC16::getNrsc5Table
103+
Crc16::getArcTable,
104+
Crc16::getCcittTable,
105+
Crc16::getDnpTable,
106+
Crc16::getMcrf4xxTable,
107+
Crc16::getMaximTable,
108+
Crc16::getModbusTable,
109+
Crc16::getNrsc5Table
110110
};
111111
// @formatter:on
112112
}
@@ -230,19 +230,19 @@ void stdUpdate(final Checksum crc16) {
230230
@ParameterizedTest
231231
@MethodSource
232232
void testArcDefault(final String source, final long expected) {
233-
testUpdateReset(source, expected, CRC16.arc());
233+
testUpdateReset(source, expected, Crc16.arc());
234234
}
235235

236236
@ParameterizedTest
237237
@MethodSource
238238
void testCcittDefault(final String source, final long expected) {
239-
testUpdateReset(source, expected, CRC16.ccitt());
239+
testUpdateReset(source, expected, Crc16.ccitt());
240240
}
241241

242242
@ParameterizedTest
243243
@MethodSource
244244
void testDnpDefault(final String source, final long expected) {
245-
testUpdateReset(source, expected, CRC16.dnp());
245+
testUpdateReset(source, expected, Crc16.dnp());
246246
}
247247

248248
@ParameterizedTest
@@ -257,12 +257,12 @@ void testGetTables(final Supplier<int[]> supplier) {
257257
@ParameterizedTest
258258
@MethodSource
259259
void testIbmSdlcDefault(final String source, final long expected) {
260-
testUpdateReset(source, expected, CRC16.ibmSdlc());
260+
testUpdateReset(source, expected, Crc16.ibmSdlc());
261261
}
262262

263263
@Test
264264
void testInit() {
265-
final Checksum crc16 = CRC16.builder().setTable(CRC16.getModbusTable()).setInit(0xFFFF).get();
265+
final Checksum crc16 = Crc16.builder().setTable(Crc16.getModbusTable()).setInit(0xFFFF).get();
266266
stdUpdate(crc16);
267267
assertEquals(0x4B37, crc16.getValue());
268268
stdUpdate(crc16);
@@ -275,18 +275,18 @@ void testInit() {
275275
@ParameterizedTest
276276
@MethodSource
277277
void testMaximDefault(final String source, final long expected) {
278-
testUpdateReset(source, expected, CRC16.maxim());
278+
testUpdateReset(source, expected, Crc16.maxim());
279279
}
280280

281281
@ParameterizedTest
282282
@MethodSource
283283
void testMcrf4xxDefault(final String source, final long expected) {
284-
testUpdateReset(source, expected, CRC16.mcrf4xx());
284+
testUpdateReset(source, expected, Crc16.mcrf4xx());
285285
}
286286

287287
@Test
288288
void testModbusCustom() {
289-
final Checksum crc16 = CRC16.builder().setTable(CRC16.getModbusTable()).setInit(0xFFFF).get();
289+
final Checksum crc16 = Crc16.builder().setTable(Crc16.getModbusTable()).setInit(0xFFFF).get();
290290
stdUpdate(crc16);
291291
assertEquals(0x4B37, crc16.getValue());
292292
stdUpdate(crc16);
@@ -299,18 +299,18 @@ void testModbusCustom() {
299299
@ParameterizedTest
300300
@MethodSource
301301
void testModbusDefault(final String source, final long expected) {
302-
testUpdateReset(source, expected, CRC16.modbus());
302+
testUpdateReset(source, expected, Crc16.modbus());
303303
}
304304

305305
@ParameterizedTest
306306
@MethodSource
307307
void testNrsc5Default(final String source, final long expected) {
308-
testUpdateReset(source, expected, CRC16.nrsc5());
308+
testUpdateReset(source, expected, Crc16.nrsc5());
309309
}
310310

311311
@Test
312312
void testReset() {
313-
final Checksum crc16 = CRC16.modbus();
313+
final Checksum crc16 = Crc16.modbus();
314314
stdUpdate(crc16);
315315
assertEquals(0x4B37, crc16.getValue());
316316
stdUpdate(crc16);
@@ -322,7 +322,7 @@ void testReset() {
322322

323323
@Test
324324
void testResetCustomModbus() {
325-
final Checksum crc16 = CRC16.builder().setTable(CRC16.getModbusTable()).setInit(0x0000).get();
325+
final Checksum crc16 = Crc16.builder().setTable(Crc16.getModbusTable()).setInit(0x0000).get();
326326
stdUpdate(crc16);
327327
assertEquals(0xBB3D, crc16.getValue());
328328
stdUpdate(crc16);
@@ -334,14 +334,14 @@ void testResetCustomModbus() {
334334

335335
@Test
336336
void testUpdateArray() {
337-
final Checksum crc16 = CRC16.builder().setTable(CRC16.getModbusTable()).setInit(0x0000).get();
337+
final Checksum crc16 = Crc16.builder().setTable(Crc16.getModbusTable()).setInit(0x0000).get();
338338
stdUpdate(crc16);
339339
assertEquals(0xBB3D, crc16.getValue());
340340
}
341341

342342
@Test
343343
void testUpdateInt() {
344-
final Checksum crc16 = CRC16.builder().setTable(CRC16.getModbusTable()).setInit(0x0000).get();
344+
final Checksum crc16 = Crc16.builder().setTable(Crc16.getModbusTable()).setInit(0x0000).get();
345345
final byte[] bytes = TEST_BYTES;
346346
for (final byte element : bytes) {
347347
crc16.update(element);
@@ -363,7 +363,7 @@ void testUpdateReset(final String source, final long expected, final Checksum cr
363363
@ParameterizedTest
364364
@MethodSource
365365
void testUsbDefault(final String source, final long expected) {
366-
testUpdateReset(source, expected, CRC16.usb());
366+
testUpdateReset(source, expected, Crc16.usb());
367367
}
368368

369369
}

0 commit comments

Comments
 (0)