Skip to content

Commit

Permalink
PackedDecimal no longer derived from AbstractFachwert
Browse files Browse the repository at this point in the history
  • Loading branch information
oboehm committed Mar 29, 2018
1 parent f38f7ab commit 9420ae8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/java/de/jfachwert/math/PackedDecimal.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package de.jfachwert.math;

import de.jfachwert.AbstractFachwert;
import de.jfachwert.Fachwert;
import de.jfachwert.SimpleValidator;
import de.jfachwert.pruefung.NullValidator;

Expand Down Expand Up @@ -45,9 +45,10 @@
* @author oboehm
* @since 0.6 (29.03.2018)
*/
public class PackedDecimal extends AbstractFachwert<byte[]> {
public class PackedDecimal implements Fachwert {

private static final SimpleValidator<String> VALIDATOR = new NullValidator();
private final byte[] code;

/**
* Instanziiert ein PackedDecimal.
Expand All @@ -66,7 +67,7 @@ public PackedDecimal(String zahl) {
* @param validator Validator, der die Zahl prueft
*/
public PackedDecimal(String zahl, SimpleValidator<String> validator) {
super(asNibbles(validator.validate(zahl)));
this.code = asNibbles(validator.validate(zahl));
}

private static byte[] asNibbles(String zahl) {
Expand All @@ -83,7 +84,7 @@ private static byte[] asNibbles(String zahl) {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
for (byte b : this.getCode()) {
for (byte b : this.code) {
if ((b & 0x0F) == 0xF) {
buf.append((b & 0xF0) / 16);
} else {
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/de/jfachwert/math/PackedDecimalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,13 @@ public void testToString() {
assertEquals("007", agent.toString());
}

/**
* Zahlen mit null Inhalt sollen erlaubt sein.
*/
@Test
public void testEmptyCtor() {
PackedDecimal nix = new PackedDecimal("");
assertEquals("", nix.toString());
}

}

0 comments on commit 9420ae8

Please sign in to comment.