3131 * </p>
3232 *
3333 * <pre>
34- *
3534 * Checksum crc16 = CRC16.builder().setTable(CRC16.getModbusTable()).setInit(0x0000).get();
3635 * </pre>
3736 *
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
0 commit comments